I need you help with GARCH model in python I got the error
below.
Dataset Apple Stock Returns
split data into 80% train and test 20%:
forecasting on test data using garch model (1,1)
I get error in the above code.
In [101]: returns Out[101]: Date 2018-01-03 2018-01-04 2018-01-05 2018-01-08 2018-01-09 -0.017415 0.464497 1.138532 -0.371425 -0.011474 2021-09-23 0.671920 2021-09-24 0.061293 2021-09-27 -1.054998 2021-09-28 -2.380128 2021-09-29 0.648297 Name: Close, Length: 942, dtype: float64
In [102]: train Out[102]: Date 2018-01-03 2018-01-04 2018-01-05 2018-01-08 2018-01-09 -0.017415 0.464497 1.138532 -0.371425 -0.011474 2020-12-22 2.846455 2020-12-23 -0.697602 2020-12-24 0.771224 2020-12-28 3.576571 2020-12-29 -1.331485 Name: Close, Length: 753, dtype: float64 In [103]: test Out[103]: Date 2020-12-30 2020-12-31 2021-01-04 2021-01-05 2021-01-06 -0.852668 -0.770265 -2.471926 1.236373 -3.366152 2021-09-23 0.671920 2021-09-24 0.061293 2021-09-27 -1.054998 2021-09-28 -2.380128 2021-09-29 0.648297 Name: Close, Length: 189, dtype: float64
= rolling predictions = [] for i in range(test): train = returns[:-(test-i)] model = arch_model(train, p=2, q=2) model_fit = model.fit(disp='off') pred = model_fit. forecast(horizon=1) rolling predictions.append(np.sqrt(pred.variance.values[-1,:][0])) TypeError Traceback (most recent call last) <ipython-input-110-17b5849be2c8> in <module> 1 rolling_predictions = [] --> 2 for i in range(test): 3 train = returns[:-(test-i)] 4 model = arch_model(train, p=2, q=2) 5 model_fit = model.fit(disp='off') TypeError: 'Series' object cannot be interpreted as an integer
I need you help with GARCH model in python I got the error below. Dataset Apple Stock Returns split data into 80% train
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am