1
$\begingroup$

I am trying to calculate the annualized Volatility of given returns for a stock with Garch(1,1) on python using a code I found online. The value I should be getting is around 27, but the value I am getting is between 17 to 19. I would be really grateful if someone can point out my mistake.

This is the code I am using:

start = datetime.datetime(2017, 9, 8)
end = datetime.datetime(2020, 9, 7)

df = web.DataReader("HDFCBANK.NS", 'yahoo', start, end)
df.tail()

data=pd.DataFrame()
data = df['Close']
returns = data.pct_change().dropna()

model_irfm = arch_model(returns, vol='Garch', p=1, o=0, q=1, dist='Normal', rescale=True )
res_irfm = model_irfm.fit()
scale = res_irfm.scale
print(res_irfm.summary())

# Forecast
forecasts_irfm = res_irfm.forecast(horizon=5)

# Getting Annualized Standard Deviation
# Garch Vol
vol_irfm_for = (forecasts_irfm.variance.iloc[-1] / np.power(scale, 2))**0.5 * np.sqrt(252) * 100
print('vol_irfm_for',vol_irfm_for)

# Observed Vol
vol_irfm = returns.std() * np.sqrt(252) * 100
print('vol_irfm',vol_irfm)

The result

vol_irfm_for h.1    17.866891
h.2    18.212123
h.3    18.539075
h.4    18.849109
h.5    19.143440
Name: 2020-09-07 00:00:00, dtype: float64
vol_irfm 27.00143321696037
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.