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
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
Comment