35 lines
No EOL
1.2 KiB
Python
35 lines
No EOL
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Shared test fixtures."""
|
|
import numpy as np
|
|
|
|
from src.forecasting.interface import Series
|
|
|
|
|
|
def make_series(n=600, seed=0, start_close=100.0, vol=1.0) -> Series:
|
|
rng = np.random.default_rng(seed)
|
|
close = np.cumsum(rng.normal(0.0, vol, n)) + start_close
|
|
return Series(
|
|
symbol="XAUUSD",
|
|
timeframe="H1",
|
|
timestamp=[f"ts-{i:06d}" for i in range(n)],
|
|
open=close.copy(),
|
|
high=close + 0.5,
|
|
low=close - 0.5,
|
|
close=close.tolist(),
|
|
)
|
|
|
|
|
|
def clone_with_future(s: Series, origin: int, mut: float = 10000.0) -> Series:
|
|
"""Return a copy where all bars AFTER `origin` are heavily changed.
|
|
|
|
Used to prove forecasts are independent of future data (no-lookahead).
|
|
"""
|
|
close = np.asarray(s.close, dtype=float).copy()
|
|
close[origin + 1:] += mut
|
|
high = np.asarray(s.high, dtype=float).copy()
|
|
low = np.asarray(s.low, dtype=float).copy()
|
|
high[origin + 1:] += mut
|
|
low[origin + 1:] += mut
|
|
return Series(symbol=s.symbol, timeframe=s.timeframe, timestamp=list(s.timestamp),
|
|
open=list(np.asarray(s.open, dtype=float)),
|
|
high=high, low=low, close=close.tolist()) |