Cross Validated
2026-11-05 18:19 UTC
By J126
AI-113-20261105-social-media-64366ad6
Garch Giving Flat Line Forecast
I am trying to forecast volatility for log returns of a stock over a period of 365 days. I am using the arch library for python. But, I keep getting a flat line prediction. I ran a summary, and it says that a Garch(1,1) model is appropriate. My code is import yfinance as yf import pandas as pd import numpy as np from arch import arch_model import matplotlib.pyplot as plt ticker = 'GOOG' start_date = '2020-01-01' end_date = '2024-12-31' df = yf.download(ticker, start = start_date, end = end_date) df['Log_Returns'] = 100*np.log(df['Close']).diff() df.dropna(inplace=True) returns = df['Log_Returns'] model = arch.model(returns, p = 1, q = 1) model_fit = model.fit() model_fit.summary() rolling_forecast = [] test_size = 365 for k in range(test_size): trainer = returns[:-(test_size - k)] gm = arch_model(trainer, p = 1, q = 1) gm_fit = model.fit(disp = 'off') forecast = gm_fit.forecast(horizon = 1) rolling_forecast.append(np.sqrt(forecast.variance.iloc[-1].values[0])) rolling_forecasts = pd.Series(rolling_forecast, index = returns.index[-365:]) plt.figure(figsize = (12,6)) true, = plt.plot(returns[-365:]) forecasts, = plt.plot(rolling_forecasts) plt.title('Volatility Predictions') plt.legend(['Returns', 'Predicted Volatility']) plt.show() The returns graph shows up correctly, but the volatility is a flat line. EDIT: Per request here is the model_fit.summary() and a visualization of the returns data: EDIT 2: I updated the above to include getting the data from yfinance. In the (very…
I am trying to forecast volatility for log returns of a stock over a period of 365 days. I am using the arch library for python. But, I keep getting a flat line prediction. I ran a summary, and it says that a Garch(1,1) model is appropriate. My code is import yfinance as yf import pandas as pd import numpy as np from arch import arch_model import matplotlib.pyplot as plt ticker = 'GOOG' start_date = '2020-01-01' end_date = '2024-12-31' df = yf.download(ticker, start = start_date, end = end_date) df['Log_Returns'] = 100*np.log(df['Close']).diff() df.dropna(inplace=True) returns = df['Log_Returns'] model = arch.model(returns, p = 1, q = 1) model_fit = model.fit() model_fit.summary() rolling_forecast = [] test_size = 365 for k in range(test_size): trainer = returns[:-(test_size - k)] gm = arch_model(trainer, p = 1, q = 1) gm_fit = model.fit(disp = 'off') forecast = gm_fit.forecast(horizon = 1) rolling_forecast.append(np.sqrt(forecast.variance.iloc[-1].values[0])) rolling_forecasts = pd.Series(rolling_forecast, index = returns.index[-365:]) plt.figure(figsize = (12,6)) true, = plt.plot(returns[-365:]) forecasts, = plt.plot(rolling_forecasts) plt.title('Volatility Predictions') plt.legend(['Returns', 'Predicted Volatility']) plt.show() The returns graph shows up correctly, but the volatility is a flat line. EDIT: Per request here is the model_fit.summary() and a visualization of the returns data: EDIT 2: I updated the above to include getting the data from yfinance. In the (very…
Full article content could not be extracted automatically. Read the original below.
Source:
Cross Validated
· stats.stackexchange.com