49
49
EGARCH (),
50
50
]
51
51
52
+ ANALYTICAL_VOLATILITIES = [
53
+ ConstantVariance (),
54
+ GARCH (),
55
+ FIGARCH (),
56
+ EWMAVariance (lam = 0.94 ),
57
+ MIDASHyperbolic (),
58
+ HARCH (lags = [1 , 5 , 22 ]),
59
+ RiskMetrics2006 (),
60
+ ]
61
+
62
+
52
63
MODEL_SPECS = list (product (MEAN_MODELS , VOLATILITIES ))
64
+ ANALYTICAL_MODEL_SPECS = list (product (MEAN_MODELS , ANALYTICAL_VOLATILITIES ))
53
65
54
66
IDS = [
55
67
f"{ str (mean ).split ('(' )[0 ]} -{ str (vol ).split ('(' )[0 ]} " for mean , vol in MODEL_SPECS
56
68
]
69
+ ANALYTICAL_IDS = [
70
+ f"{ str (mean ).split ('(' )[0 ]} -{ str (vol ).split ('(' )[0 ]} "
71
+ for mean , vol in ANALYTICAL_MODEL_SPECS
72
+ ]
57
73
58
74
59
75
@pytest .fixture (params = MODEL_SPECS , ids = IDS )
@@ -63,6 +79,13 @@ def model_spec(request):
63
79
return mean
64
80
65
81
82
+ @pytest .fixture (params = ANALYTICAL_MODEL_SPECS , ids = ANALYTICAL_IDS )
83
+ def analytical_model_spec (request ):
84
+ mean , vol = request .param
85
+ mean .volatility = vol
86
+ return mean
87
+
88
+
66
89
class TestForecasting :
67
90
@classmethod
68
91
def setup_class (cls ):
@@ -1053,3 +1076,31 @@ def test_rescale_ar():
1053
1076
fcasts = res .forecast (horizon = 100 ).variance
1054
1077
fcasts_no_rs = res_no_rs .forecast (horizon = 100 ).variance
1055
1078
assert_allclose (fcasts .iloc [0 , - 10 :], fcasts_no_rs .iloc [0 , - 10 :], rtol = 1e-5 )
1079
+
1080
+
1081
+ def test_figarch_multistep ():
1082
+ # GH 670
1083
+ mod = ConstantMean (SP500 , volatility = FIGARCH ())
1084
+ res = mod .fit (disp = "off" )
1085
+ fcasts = res .forecast (horizon = 10 )
1086
+ rv = fcasts .residual_variance
1087
+ assert np .all (np .isfinite (rv ))
1088
+ assert rv .shape == (1 , 10 )
1089
+ fcasts_ri = res .forecast (horizon = 10 , reindex = True )
1090
+ rv_ri = fcasts_ri .residual_variance
1091
+ assert_frame_equal (rv , rv_ri .iloc [- 1 :])
1092
+ assert rv_ri .shape == (SP500 .shape [0 ], 10 )
1093
+
1094
+
1095
+ def test_multistep (analytical_model_spec ):
1096
+ # GH 670
1097
+ # Ensure all work as expected
1098
+ res = analytical_model_spec .fit (disp = "off" )
1099
+ fcasts = res .forecast (horizon = 10 )
1100
+ rv = fcasts .residual_variance
1101
+ assert np .all (np .isfinite (rv ))
1102
+ assert rv .shape == (1 , 10 )
1103
+ fcasts_ri = res .forecast (horizon = 10 , reindex = True )
1104
+ rv_ri = fcasts_ri .residual_variance
1105
+ assert_frame_equal (rv , rv_ri .iloc [- 1 :])
1106
+ assert rv_ri .shape == (SP500 .shape [0 ], 10 )
0 commit comments