Hello,
I´ve got a quite specific problem. In order to calculate the beta of the Capital Asset Pricing Model (CAPM), I need to calculate the volatility of stock returns as well as their correlation with the S&P 500.
Thereby I follow the approach of a specific paper ("Betting against Beta"). The volatility is calculated for the last 250 trading days and the correlation for the last 1250 days. Until this point, there is no problem.
But: The authors start calculating the volatility/correlation as 120/750 days of non-missing data are reached.
That means: Starting with the 120th,121th,122th,.../750th,751th,752th,... day of non-missing data, I need the volatility/correlation for the last 120,121,122,.../750,751,752,...days. The used days should rise until the "normal" 250/1250 days are reached.
Doing it manually is almost impossible, because I use >1000 stocks, which have different dates of IPO´s/delistings. I literally have no idea how to implement the approach. Maybe a nested if- and count-if function within the volatility/correlation-function?
I appreciate every kind of help!
(Please excuse, that the syntax of my question might be wrong at some point. I'm not a native english speaker)
Best Regards
Bookmarks