I am trying to do a standard realized volatility calculation in python using daily log returns, like so:
window = 21
trd_days = 252
ann_factor = window/trd_days
rlz_var = underlying_df['log_ret'].rolling(window).var() * ann_factor
rlz_vol = np.sqrt(rlz_var)
I am essentially getting a realized vol value for each day in my dataset, hence the rolling window over roughly the past month (21 days), and then multiplying the var of this by the annualization factor.
Output with some SPY data:
Is this a sensible and industry way of going about calculating realized vol? If not, what would be a more appropriate calculation be?