I'm trying to implement the AQR ivestment strategy "Time Series Momentum": https://www.aqr.com/library/journal-articles/time-series-momentum.
I'm running into some confusion/trouble in part of the process. At first glance Pandas appears to have the functionality to calculate a key metric, "exponentially weighted lagged squared returns", as a measure of how volatile a financial instrument is. The formula is thus (with some background):
I understand Pandas has some functionality to apply formula (1) above, to a time series. For example the daily returns for a future contract could be:
[In]: returns
[Out]:
Date
1984-01-03 -0.007299
1984-01-04 0.003614
1984-01-05 -0.007318
1984-01-06 -0.004134
1984-01-09 0.009487
1984-01-10 -0.000896
...
I then use pandas.DataFrame.ewm
in conjunction with pd.std()
to try and implement the required formula in a quick one liner, setting com=60
in order to match the paper, this yields:
[In]: np.sqrt(261) * returns.ewm(com=60).std()
[Out]:
Date
1984-01-03 NaN
1984-01-04 0.124664
1984-01-05 0.101879
1984-01-06 0.082925
1984-01-09 0.120588
1984-01-10 0.107411
...
Though this seems OK... though the formula in the paper uses the difference between the value of the previous or lagged return and the exponentially weighted average return at the current timestep in its calculation:
Would I be right in saying that the Pandas method I carried out above won't use the lagged return, but instead will use the return at the current timestep? As such, I will need to program up my own way of calculating this in Pandas? Perhaps by using some sort of shift?
Thanks in advance! I'm still getting to grips with the nuances of Pandas and your help is much appreciated.