ARIMA_SAX_Hybrid_Forecaster/tests/test_target.py

29 lines
No EOL
893 B
Python

# -*- coding: utf-8 -*-
"""Unit tests: common target (Forward Return / ATR) and ATR no-lookahead."""
import numpy as np
import pytest
from src.forecasting.target import forward_return, data_atr
def test_forward_return_uses_atr_denominator():
close = [1.0, 2.0, 3.0, 4.0, 5.0]
atr = [1.0, 1.0, 1.0, 1.0, 1.0]
assert forward_return(close, atr, 0, 2) == pytest.approx(3.0 - 1.0)
def test_forward_return_reachable():
close = list(np.linspace(100.0, 101.5, 15))
atr = data_atr(close, 5)
y = forward_return(close, atr, 5, 4)
assert np.isfinite(y)
def test_atr_no_lookahead():
close = np.asarray(np.linspace(100, 110, 50), dtype=float)
atr = data_atr(close, 10)
# mutating future bars must not change ATR at earlier indices
close2 = close.copy()
close2[20:] += 5000.0
atr2 = data_atr(close2, 10)
assert np.allclose(atr[9:19], atr2[9:19])