Skip to content

Commit 436eea1

Browse files
committed
test(garch): exercise lookahead through public expression
1 parent 1702321 commit 436eea1

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎tests/features/volatility/test_volatility_comprehensive.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,18 @@ def test_alpha_beta_constraint(self):
500500

501501
def test_forecast_ignores_future_returns(self):
502502
"""A later shock must not change forecasts made before it is observed."""
503-
from ml4t.engineer.features.volatility.garch_forecast import garch_volatility_forecast_nb
503+
from ml4t.engineer.features.volatility.garch_forecast import garch_forecast
504504

505505
calm = np.zeros(30)
506506
shocked = calm.copy()
507-
shocked[20] = 4.0
508-
calm_forecast = garch_volatility_forecast_nb(calm, 1e-6, 0.1, 0.85, 1)
509-
shocked_forecast = garch_volatility_forecast_nb(shocked, 1e-6, 0.1, 0.85, 1)
510-
511-
np.testing.assert_allclose(shocked_forecast[:20], calm_forecast[:20])
512-
assert shocked_forecast[20] > shocked_forecast[19]
507+
shocked[10] = 4.0
508+
calm_forecast = pl.DataFrame({"returns": calm}).select(garch_forecast("returns"))["returns"]
509+
shocked_forecast = pl.DataFrame({"returns": shocked}).select(garch_forecast("returns"))[
510+
"returns"
511+
]
512+
513+
np.testing.assert_allclose(shocked_forecast[:10], calm_forecast[:10])
514+
assert shocked_forecast[10] > shocked_forecast[9]
513515

514516
def test_responds_to_shocks(self, ohlcv_df):
515517
"""Conditional vol should increase after large returns."""

0 commit comments

Comments
 (0)