Skip to content

Commit 065f330

Browse files
committed
Add test file for forecast_ar.py.
1 parent f726932 commit 065f330

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/analysis/test_forecast_ar.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import numpy as np
2+
import pandas as pd
3+
import pytest
4+
5+
from lennart_epp.analysis.forecast_ar import forecast_ar_multi_step
6+
7+
8+
@pytest.fixture
9+
def test_dataframe():
10+
rng = np.random.default_rng(83)
11+
dates = pd.date_range(start="2023-01-01", periods=400, freq="D")
12+
data = np.linspace(100, 200, num=400) + rng.normal(scale=5, size=400)
13+
return pd.DataFrame({"close_price": data}, index=dates)
14+
15+
16+
@pytest.fixture
17+
def test_integrated_coefficients():
18+
coeffs = np.array([0.5, 0.3, -0.2])
19+
return pd.DataFrame({"coefficient": coeffs})
20+
21+
22+
def test_forecast_ar_multi_step(test_dataframe, test_integrated_coefficients):
23+
forecast_steps = 10
24+
forecasts = forecast_ar_multi_step(
25+
test_dataframe, test_integrated_coefficients, forecast_steps
26+
)
27+
28+
assert isinstance(forecasts, pd.Series)
29+
assert len(forecasts) == forecast_steps
30+
assert not forecasts.isna().any()
31+
32+
expected_index_start = test_dataframe.index[-344]
33+
expected_index = pd.date_range(
34+
start=expected_index_start, periods=forecast_steps, freq="D"
35+
)
36+
37+
assert forecasts.index.equals(expected_index), "Index does not match"

0 commit comments

Comments
 (0)