Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: AW: How to calculate the bid-ask spread in this case?


From   help me <carrot2rabbit@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: AW: How to calculate the bid-ask spread in this case?
Date   Thu, 30 Jul 2009 23:51:20 -0400

Dear Martin,

Thank you very much! Yes, I should check the both ways. I think I now
understand how to solve my problem.

-JHS

On Thu, Jul 30, 2009 at 11:14 PM, Martin Weiss<martin.weiss1@gmx.de> wrote:
> <>
>
> Ok, that makes the solution slightly more involved:
>
>
> ******
> clear*
>
> input BondID:mylabel    str10(Date Time) Bid_Price Ask_Price , auto
> AAA     20090729 090540  100.00 .
> AAA     20090729 092307  100.05 .
> AAA     20090729 093051           .  101.10
> AAA     20090729 093523           .  101.20
> AAA     20090729 093617  101.05 .
> AAA     20090729 094521           .  101.20
> AAA     20090729 094654  100.30 .
> AAA     20090729 094929           .  100.70
> AAA     20090729 100002           .  100.50
> end
>
> egen newdate=concat(Date Time)
> gen double timeoftrade=clock(newdate, "YMDhms")
> format timeoftrade %tc
>
> //get time difference
> bys BondID (timeoftrade): /*
>  */ gen timediff=timeoftrade[_n]-timeoftrade[_n-1]
>
> //get the spread
> //have to check both ways
> bys BondID (timeoftrade): /*
>  */ gen spread=min(Ask_Price[_n]-Bid_Price[_n-1], /*
>  */ Ask_Price[_n-1]-Bid_Price[_n])
>
> //get the minimum time diff
> bys BondID (timeoftrade): /*
>  */ egen mintime=min(timediff)
>
> //get rid of auxiliaries
> drop Date Time newdate
>
> //get desiredspread
> bys BondID (timeoftrade): /*
>  */ egen desiredspread= /*
>  */ max((timediff==mintime)* /*
>  */ spread)
>
> list, noobs
> ******
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von help me
> Gesendet: Donnerstag, 30. Juli 2009 19:33
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: AW: How to calculate the bid-ask spread in this case?
>
> Dear Martin,
>
> Thank you very much for your answer. Your suggestion is very helpful.
> Now I can have a measure of the bid-ask spread!
>
> However, I am afraid I did not correctly explain my problem. The
> actual data is more complicated although it has the same structure as
> the hypothetical one that I provided.
>
> Bond ID Date     Time(HHMMSS) Bid_Price Ask_Price
> AAA     20090729 090540       100.00
> AAA     20090729 092307       100.05
> AAA     20090729 093051                 101.10
> AAA     20090729 093523                 101.20
> AAA     20090729 093617       101.05
> AAA     20090729 094521                 101.20
> AAA     20090729 094654       100.30
> AAA     20090729 094929                 100.70
> AAA     20090729 100002                 100.50
> .
> .
> .
> In this case I want to calculate the difference between the ask price
> at 09:35:23 (101.20) and the bid price at 09:36:17(101.05) because
> these bid and ask transactions take place at the closest time among
> other pairs.
>
> Do you have any idea how to do that?
>
> Thank you.
>
> JHS

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index