Announcement

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

  • Annualised returns using daily data

    Hi,
    I'm trying to generate annualised returns from daily stock prices by doing like this:

    gen adjustedprice = prccd * trfd
    egen priceplusdiv = rowtotal( adjustedprice div)
    gen dailystockret= (priceplusdiv[_n]/ prccd[_n-1]) -1

    generate year=substr( datadate,6,9)

    * flag the minimum return
    bys lpermno year: egen minret= min(dailystockret)

    * count the number of periods
    bys lpermno year: gen obs= [_n]
    bys lpermno year: egen n_periods= max(obs)

    * flag the max return
    bys lpermno year: egen maxret=max(dailystockret)

    *count missing periods
    bys lpermno year: gen n_miss_one= 1 if dailystockret ==.
    bys lpermno year: egen n_miss= total(n_miss_one)

    * Calculate the annualised returns
    bys lpermno year: egen sumInret= sum(ln(1+dailystockret))
    bys lpermno year: gen annualpercent=(exp(sumInret)-1)/100 if _n==_N
    bys lpermno year: gen last=1 if _n==_N
    list lpermno mydate annualpercent minret maxret n_periods n_miss if last==1

    But, I notice huge values for annualpercent data which normally represent the annualised returns. I can't see the problem with my do. file!
    Thanks for your help.

    Ps the attached file show an exemple of a huge value for one stock
    Attached Files

  • #2
    I think it would help your case if you post how it is you calculate what you call "annualized return"; the mathematical formula, I mean (use appropriate formatting to post that). A small example dataset, with only the variables actually needed to compute the new one, would also be helpful. The file you posted seems unnecessarily large and the code too cryptic for most people to want to take a detailed look. Double check your code with some benchmark data. It just might be that the "huge" value is correct.

    Take time to properly explain your problem. Copying and pasting a huge chunk of code/file in the forum is not the best approach.
    Last edited by Roberto Ferrer; 11 Sep 2014, 22:02.
    You should:

    1. Read the FAQ carefully.

    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment

    Working...
    X