January 2020
Beginner to intermediate
432 pages
11h 24m
English
Execute the following steps to calculate and annualize the monthly realized volatility.
import pandas as pd
def realized_volatility(x): return np.sqrt(np.sum(x**2))
df_rv = df.groupby(pd.Grouper(freq='M')).apply(realized_volatility)df_rv.rename(columns={'log_rtn': 'rv'}, inplace=True)
df_rv.rv = df_rv.rv * np.sqrt(12)
fig, ax = plt.subplots(2, 1, sharex=True)ax[0].plot(df)ax[1].plot(df_rv)
Executing the preceding code results in the following plots:

Read now
Unlock full access