I have been reading AFML ( Marcos López de Prado ) and I am having trouble understanding snippet 3.1 which provides the following code:
def getDailyVol(close,span0=100): # daily vol, reindexed to close df0=close.index.searchsorted(close.index-pd.Timedelta(days=1)) df0=df0[df0>0] df0=pd.Series(close.index[df0-1], index=close.index[close.shape-df0.shape:]) df0=close.loc[df0.index]/close.loc[df0.values].values-1 # daily returns df0=df0.ewm(span=span0).std() return df0
Could anyone explain what is wrong with computing daily volatility as:
span0 = 100 close.pct_change().ewm(span = span0).std()
The results in the two methods of computation differ as the previous date used in
getDailyVol is different from the day before.
Could anyone please explain?