fix: align pooled symbol features at training
This commit is contained in:
@@ -12,6 +12,7 @@ from tools.train_torch_recurrent_forecaster import (
|
|||||||
RecurrentReturnModel,
|
RecurrentReturnModel,
|
||||||
_barrier_outcome,
|
_barrier_outcome,
|
||||||
_export_head_state,
|
_export_head_state,
|
||||||
|
_prepare_data,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,3 +85,38 @@ def test_multitask_head_export_matches_runtime_inference() -> None:
|
|||||||
actual = _torch_head_outputs(context[0].tolist(), entry, hidden_size=4)
|
actual = _torch_head_outputs(context[0].tolist(), entry, hidden_size=4)
|
||||||
|
|
||||||
assert actual == pytest.approx(expected, abs=2e-6)
|
assert actual == pytest.approx(expected, abs=2e-6)
|
||||||
|
|
||||||
|
|
||||||
|
def test_pooled_training_populates_symbol_identity_feature() -> None:
|
||||||
|
candles = [
|
||||||
|
_candle(
|
||||||
|
index,
|
||||||
|
open_=100.0 + index * 0.01,
|
||||||
|
high=100.2 + index * 0.01,
|
||||||
|
low=99.8 + index * 0.01,
|
||||||
|
close=100.0 + index * 0.01,
|
||||||
|
)
|
||||||
|
for index in range(180)
|
||||||
|
]
|
||||||
|
|
||||||
|
prepared = _prepare_data(
|
||||||
|
symbol="BTCUSDT",
|
||||||
|
candles=candles,
|
||||||
|
feature_names=["return_1", "symbol_is_BTCUSDT", "symbol_is_ETHUSDT"],
|
||||||
|
lookback=8,
|
||||||
|
target_horizons=[3],
|
||||||
|
decision_horizon=3,
|
||||||
|
round_trip_cost=0.002,
|
||||||
|
stop_loss_percent=0.04,
|
||||||
|
take_profit_percent=0.035,
|
||||||
|
market_candles={"BTCUSDT": candles},
|
||||||
|
trend_candles=candles,
|
||||||
|
validation_window=24,
|
||||||
|
holdout_window=32,
|
||||||
|
clip=8.0,
|
||||||
|
device=torch.device("cpu"),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert prepared is not None
|
||||||
|
assert torch.all(prepared.train_x[:, :, 1] == 1.0)
|
||||||
|
assert torch.all(prepared.train_x[:, :, 2] == 0.0)
|
||||||
|
|||||||
@@ -361,6 +361,7 @@ def _train_pooled_symbols(
|
|||||||
prepared_by_symbol: dict[str, PreparedData] = {}
|
prepared_by_symbol: dict[str, PreparedData] = {}
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
prepared = _prepare_data(
|
prepared = _prepare_data(
|
||||||
|
symbol=symbol,
|
||||||
candles=market_candles[symbol],
|
candles=market_candles[symbol],
|
||||||
feature_names=feature_names,
|
feature_names=feature_names,
|
||||||
lookback=lookback,
|
lookback=lookback,
|
||||||
@@ -654,6 +655,7 @@ def _train_symbol(
|
|||||||
for lookback in lookbacks:
|
for lookback in lookbacks:
|
||||||
_progress(f"{symbol}: preparing lookback={lookback}")
|
_progress(f"{symbol}: preparing lookback={lookback}")
|
||||||
prepared = _prepare_data(
|
prepared = _prepare_data(
|
||||||
|
symbol=symbol,
|
||||||
candles=candles,
|
candles=candles,
|
||||||
feature_names=feature_names,
|
feature_names=feature_names,
|
||||||
lookback=lookback,
|
lookback=lookback,
|
||||||
@@ -777,6 +779,7 @@ def _train_symbol(
|
|||||||
|
|
||||||
def _prepare_data(
|
def _prepare_data(
|
||||||
*,
|
*,
|
||||||
|
symbol: str,
|
||||||
candles: list[Candle],
|
candles: list[Candle],
|
||||||
feature_names: list[str],
|
feature_names: list[str],
|
||||||
lookback: int,
|
lookback: int,
|
||||||
@@ -796,6 +799,7 @@ def _prepare_data(
|
|||||||
feature_rows = _feature_matrix(
|
feature_rows = _feature_matrix(
|
||||||
candles,
|
candles,
|
||||||
feature_names,
|
feature_names,
|
||||||
|
symbol=symbol,
|
||||||
market_candles=market_candles,
|
market_candles=market_candles,
|
||||||
trend_candles=trend_candles,
|
trend_candles=trend_candles,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user