Improve Trader V4 training pipeline

Align entry labels with max future edge, tune direction labeling, and harden regression evaluation.

Add training diagnostics, price-plan search, feature screening, and nonlinear benchmark scripts.
This commit is contained in:
Codex
2026-06-27 19:57:29 +08:00
parent e58e4a5572
commit 9acb3460a1
27 changed files with 2059 additions and 341 deletions
+17 -2
View File
@@ -4,8 +4,8 @@ from dataclasses import dataclass
from typing import Any
FEATURE_VERSION = "feature-v4-p0"
LABEL_VERSION = "label-v4-p0"
FEATURE_VERSION = "feature-v4-p2-book-cross"
LABEL_VERSION = "label-v4-p1-max-edge"
SPLIT_VERSION = "split-v4-p0"
MODEL_BUNDLE_VERSION = "trader-v4-btc-p0"
CALIBRATION_BUNDLE_VERSION = "cal-v4-btc-p0"
@@ -96,6 +96,21 @@ FEATURES: tuple[FeatureDef, ...] = (
FeatureDef(37, "minute_of_day_sin", "日内时间正弦", "Time of day cyclic feature.", ("event_time",), "sin(2*pi*minute_of_day/1440)", "event_time", "ratio", "float32", "never null", True, "event timestamp only", ("Direction", "Entry", "Risk")),
FeatureDef(38, "minute_of_day_cos", "日内时间余弦", "Time of day cyclic feature.", ("event_time",), "cos(2*pi*minute_of_day/1440)", "event_time", "ratio", "float32", "never null", True, "event timestamp only", ("Direction", "Entry", "Risk")),
FeatureDef(39, "minutes_to_next_funding", "距离下次资金费分钟", "Minutes to next funding settlement.", ("funding", "replay_1m"), "clip((next_funding_time - event_time) / 60000, 0, 480)", "as-of", "minute", "float32", "as-of > 12h -> fail", True, "backward as-of only", ("Entry", "Continue", "Risk")),
FeatureDef(40, "book_top_imbalance", "盘口一档强弱", "Top bid/ask size imbalance.", ("book",), "(bid_0_size - ask_0_size) / max(bid_0_size + ask_0_size, eps)", "last book snapshot in 1m", "ratio", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Direction", "Entry", "Risk")),
FeatureDef(41, "book_microprice_basis_bps", "微价格偏离", "Microprice distance from mid price.", ("book",), "((bid_0_price * ask_0_size + ask_0_price * bid_0_size) / max(bid_0_size + ask_0_size, eps) / mid - 1) * 10000", "last book snapshot in 1m", "bps", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Direction", "Entry", "Risk")),
FeatureDef(42, "book_bid_depth_l5_quote", "前5档买盘深度", "Bid notional in levels 0..4.", ("book",), "sum(bid_i_price * bid_i_size, i=0..4)", "last book snapshot in 1m", "quote", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Entry", "Risk")),
FeatureDef(43, "book_ask_depth_l5_quote", "前5档卖盘深度", "Ask notional in levels 0..4.", ("book",), "sum(ask_i_price * ask_i_size, i=0..4)", "last book snapshot in 1m", "quote", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Entry", "Risk")),
FeatureDef(44, "book_depth_imbalance_l5", "前5档盘口深度差", "Bid/ask notional imbalance in levels 0..4.", ("book",), "(bid_depth_l5 - ask_depth_l5) / max(bid_depth_l5 + ask_depth_l5, eps)", "last book snapshot in 1m", "ratio", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Direction", "Entry", "Risk")),
FeatureDef(45, "book_depth_imbalance_l20", "前20档盘口深度差", "Bid/ask notional imbalance in levels 0..19.", ("book",), "(bid_depth_l20 - ask_depth_l20) / max(bid_depth_l20 + ask_depth_l20, eps)", "last book snapshot in 1m", "ratio", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Direction", "Entry", "Risk")),
FeatureDef(46, "book_depth_concentration_l5_l20", "前5档深度集中度", "How much total book notional is concentrated in top five levels.", ("book",), "(bid_depth_l5 + ask_depth_l5) / max(bid_depth_l20 + ask_depth_l20, eps)", "last book snapshot in 1m", "ratio", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Entry", "Risk")),
FeatureDef(47, "book_pressure_spread_ratio", "盘口压力相对价差", "Microprice pressure normalized by current spread.", ("book", "level_1"), "book_microprice_basis_bps / max(abs(spread_bps), 0.01)", "1m", "ratio", "float32", "missing dependency -> WARMUP", True, "uses <= t book and spread only", ("Direction", "Entry", "Risk")),
FeatureDef(48, "book_pressure_taker_1m", "盘口压力和1分钟主动成交共振", "Microprice pressure confirmed by current taker imbalance.", ("book", "trades"), "book_microprice_basis_bps * taker_imbalance_1m", "1m", "bps", "float32", "missing dependency -> WARMUP", True, "uses <= t book and trades only", ("Direction", "Entry")),
FeatureDef(49, "book_pressure_taker_5m", "盘口压力和5分钟主动成交共振", "Microprice pressure confirmed by short taker imbalance.", ("book", "trades"), "book_microprice_basis_bps * taker_imbalance_5m", "5m", "bps", "float32", "missing dependency -> WARMUP", True, "uses <= t book and trades only", ("Direction", "Entry")),
FeatureDef(50, "book_l20_imbalance_taker_15m", "20档深度和15分钟主动成交共振", "Deep book imbalance confirmed by near taker flow.", ("book", "trades"), "book_depth_imbalance_l20 * taker_imbalance_15m", "15m", "ratio", "float32", "missing dependency -> WARMUP", True, "uses <= t book and trades only", ("Direction", "Entry")),
FeatureDef(51, "book_l20_imbalance_ret_15m", "20档深度和15分钟走势关系", "Deep book pressure interacting with near return.", ("book", "replay_1m"), "book_depth_imbalance_l20 * ret_15m_bps", "15m", "bps", "float32", "missing dependency -> WARMUP", True, "uses <= t book and returns only", ("Direction", "Entry")),
FeatureDef(52, "book_pressure_vol_adjusted", "波动调整后的盘口压力", "Microprice pressure divided by near realized volatility.", ("book", "replay_1m"), "book_microprice_basis_bps / max(realized_vol_15m_bps, 1)", "15m", "ratio", "float32", "missing dependency -> WARMUP", True, "uses <= t book and volatility only", ("Direction", "Entry", "Risk")),
FeatureDef(53, "book_depth_pressure_gap", "近档和深档压力差", "Top five depth imbalance minus top twenty depth imbalance.", ("book",), "book_depth_imbalance_l5 - book_depth_imbalance_l20", "last book snapshot in 1m", "ratio", "float32", "missing book -> WARMUP", True, "uses last book snapshot within current closed minute only", ("Entry", "Risk")),
FeatureDef(54, "book_pressure_reversal_15m", "盘口压力和15分钟反转关系", "Positive when book pressure leans against the recent move.", ("book", "replay_1m"), "-book_microprice_basis_bps * ret_15m_bps", "15m", "bps^2", "float32", "missing dependency -> WARMUP", True, "uses <= t book and returns only", ("Direction", "Entry")),
)