From these daily stock returns I want to calculate the one-year "rolling standard deviation" (according to the paper I'm following).
I have managed to come up with the command using -rangestat- and I'm just wondering if I'm doing it correctly as there is no other way for me to check whether the resulting standard deviations from rangestat are correct.
I have also noticed a couple of things while using -rangestat-:
I use the count option to see how many observations it uses and while sometimes it uses 1 observation (this is fine), in other times it uses 2 observations which I'm not sure why it's doing that since I want to use one day returns (the previous day).
Also the standard deviation is sometimes 0 and other times " . " (missing value), I wonder why this is and how I should interpret the difference between these 2 in the output of the rangestat command?
I will post below an example of the data I'm using, but since there is so many observations I cannot post a completely representative sample here. So I will just go with the returns of 1 company (Apple):
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long date str8 ticker str36 comnam double permco float Returns 8417 "AAPL" "APPLE COMPUTER INC" 7 .03319269 8418 "AAPL" "APPLE COMPUTER INC" 7 -.022553137 8419 "AAPL" "APPLE COMPUTER INC" 7 .007132721 8420 "AAPL" "APPLE COMPUTER INC" 7 .1054022 8421 "AAPL" "APPLE COMPUTER INC" 7 -.00033 8424 "AAPL" "APPLE COMPUTER INC" 7 -.0588665 8425 "AAPL" "APPLE COMPUTER INC" 7 .03793554 8426 "AAPL" "APPLE COMPUTER INC" 7 .03980917 8427 "AAPL" "APPLE COMPUTER INC" 7 .06625561 8428 "AAPL" "APPLE COMPUTER INC" 7 .005786227 8431 "AAPL" "APPLE COMPUTER INC" 7 -.0033834374 8432 "AAPL" "APPLE COMPUTER INC" 7 .02086082 8433 "AAPL" "APPLE COMPUTER INC" 7 .026269455 8434 "AAPL" "APPLE COMPUTER INC" 7 .03968534 8435 "AAPL" "APPLE COMPUTER INC" 7 -.014424606 8438 "AAPL" "APPLE COMPUTER INC" 7 -.04090528 8439 "AAPL" "APPLE COMPUTER INC" 7 -.009235363 end format %d date
note: permco is simply a unique identifier that each company in the dataset has, a unique number per company.
I then use the following command:
rangestat (sd) Returns (count) Returns, interval (date -1 0) by (permco)
Thanks in advance
0 Response to Rolling standard dev
Post a Comment