Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculate number of calendar days based on business calendar

    Hi everyone. It's my first time to post something on Stalist. I'm trying to follow the advice, but probably I still make mistake somewhere.

    I am doing an event study in bonds. Thanks to many previous posts, I am able to create business calendar for my trading days:

    Code:
    input str10(var1 var2) long var3 float(var4 var5 var6)
    "88EO.ASX"   "07/07/2015" 20150707 .005 .005 .005
    "88EO.ASX"   "08/07/2015" 20150708 .004 .004 .004
    "88EO.ASX"   "13/07/2015" 20150713 .005 .004 .005
    "UseDataex!" "02/01/2015" 20150707 .005 .005 .005
    "UseDataex!" "06/01/2015" 20150708 .004 .004 .004
    end
    * convert string date to Stata SIF date
    gen ndate = daily(var2,"DMY")
    format %td ndate
    * convert to business calendar date
    gen tdate = bofd("trade", ndate)
    format tdate %tbtrade
    * declare panel data
    egen long panelvar = group(var1)
    tsset panelvar tdate
    * fill in missing trading days
    tsfill
    list
    My data looks like this:
    Code:
     list
    
         +----------------------------------------------------------------------------------------+
         |       var1         var2       var3   var4   var5   var6       ndate   tdate   panelvar |
         |----------------------------------------------------------------------------------------|
      1. |   88EO.ASX   07/07/2015   20150707   .005   .005   .005   07jul2015       .          1 |
      2. |   88EO.ASX   08/07/2015   20150708   .004   .004   .004   08jul2015       .          1 |
      3. |   88EO.ASX   13/07/2015   20150713   .005   .004   .005   13jul2015       .          1 |
      4. | UseDataex!   02/01/2015   20150707   .005   .005   .005   02jan2015       .          2 |
      5. | UseDataex!   06/01/2015   20150708   .004   .004   .004   06jan2015       .          2 |
         +----------------------------------------------------------------------------------------+
    To calculate return of bond, I need to estimate accrued interest (or the change in accrued interest), which require me to have number of calendar days between 2 trading days. But because the tdate is on business calendar format, it showed the result of 1 when I subtract the 2 trading dates as following:

    Code:
     gen diff=tdate-tdate[_n-1]
    Could you please tell me how can I calculate number of calendar days based on those business days? Or another way to calculate accrued interest for bonds? I have also the information for the offering date, maturity dates and coupon rate.
    Thank you so much in advance!

  • #2
    It looks like tdate is not well defined in your code. It is all empty. I don't think the trade business calendar is a standard one, so you will need to elaborate on what that looks like if you want help.

    Comment


    • #3
      Hello Lien,

      I think your code
      Code:
      gen diff=tdate-tdate[_n-1]
      is giving the correct result, because it is excluding business holidays. So the number of days between Friday and the next Monday is 1 (if Saturdays and Sundays are holidays). If you want the difference in terms of the number of calendar days, one way is to use ndate. But you may have some observations with ndate missing (because tsfill is based on tdate). Function dofb() can be used to replace the missing values of ndate (or generate a new date variable altogether).

      As Dimitriy V. Masterov pointed out, the business calendar trade is not available. I created the business calendar (basically a file called trade.stbcal) with Saturdays and Sundays as holidays. I reproduce your code below, with the changes mentioned above. Hopefully it gives what you are looking for.

      -- Kreshna
      Code:
      clear
      input str10(var1 var2) long var3 float(var4 var5 var6)
      "88EO.ASX"   "07/07/2015" 20150707 .005 .005 .005
      "88EO.ASX"   "08/07/2015" 20150708 .004 .004 .004
      "88EO.ASX"   "13/07/2015" 20150713 .005 .004 .005
      "UseDataex!" "02/01/2015" 20150707 .005 .005 .005
      "UseDataex!" "06/01/2015" 20150708 .004 .004 .004
      end
      * convert string date to Stata SIF date
      gen ndate = daily(var2,"DMY")
      format %td ndate
      * convert to business calendar date
      gen tdate = bofd("trade", ndate)
      format tdate %tbtrade
      * declare panel data
      egen long panelvar = group(var1)
      tsset panelvar tdate
      * fill in missing trading days
      tsfill
      replace ndate = dofb(tdate, "trade") if missing(ndate)
      list
      
      gen diff_biz  = tdate-tdate[_n-1]
      gen diff_cal  = ndate-ndate[_n-1]

      Comment


      • #4
        Many thanks Dimitriy and especially Kreshna. It totally works for me now.

        Comment

        Working...
        X