chore: 更新 fidc-backtest-engine - 2026-05-08

This commit is contained in:
boris
2026-05-08 19:57:49 -07:00
parent 65742d4d5e
commit d9de9715ef

View File

@@ -4612,18 +4612,13 @@ impl Strategy for PlatformExprStrategy {
0
};
let stock_list = if self.config.rotation_enabled {
let selection_scan_limit = if self.config.daily_top_up_enabled {
selection_limit.saturating_add(80).max(120)
} else {
selection_limit
};
let (stock_list, notes) = self.select_symbols(
ctx,
decision_date,
&day,
band_low,
band_high,
selection_scan_limit,
selection_limit,
)?;
selection_notes = notes;
stock_list
@@ -6121,6 +6116,139 @@ mod tests {
assert_eq!(decision.order_intents.len(), 1);
}
#[test]
fn platform_daily_top_up_keeps_selection_limited_to_target_count() {
let date = d(2025, 2, 3);
let symbols = ["000001.SZ", "000002.SZ", "000003.SZ"];
let data = DataSet::from_components(
symbols
.iter()
.map(|symbol| Instrument {
symbol: (*symbol).to_string(),
name: (*symbol).to_string(),
board: "SZ".to_string(),
round_lot: 100,
listed_at: Some(d(2020, 1, 1)),
delisted_at: None,
status: "active".to_string(),
})
.collect(),
symbols
.iter()
.map(|symbol| DailyMarketSnapshot {
date,
symbol: (*symbol).to_string(),
timestamp: Some("2025-02-03 09:33:00".to_string()),
day_open: 10.0,
open: 10.0,
high: 10.5,
low: 9.8,
close: 10.0,
last_price: 10.0,
bid1: 9.99,
ask1: 10.01,
prev_close: 9.9,
volume: 1_000_000,
tick_volume: 10_000,
bid1_volume: 2_000,
ask1_volume: 2_000,
trading_phase: Some("continuous".to_string()),
paused: false,
upper_limit: 11.0,
lower_limit: 9.0,
price_tick: 0.01,
})
.collect(),
symbols
.iter()
.enumerate()
.map(|(index, symbol)| DailyFactorSnapshot {
date,
symbol: (*symbol).to_string(),
market_cap_bn: 10.0 + index as f64,
free_float_cap_bn: 10.0 + index as f64,
pe_ttm: 8.0,
turnover_ratio: Some(1.0),
effective_turnover_ratio: Some(1.0),
extra_factors: BTreeMap::new(),
})
.collect(),
symbols
.iter()
.map(|symbol| CandidateEligibility {
date,
symbol: (*symbol).to_string(),
is_st: false,
is_new_listing: false,
is_paused: false,
allow_buy: true,
allow_sell: true,
is_kcb: false,
is_one_yuan: false,
})
.collect(),
vec![BenchmarkSnapshot {
date,
benchmark: "000852.SH".to_string(),
open: 1000.0,
close: 1002.0,
prev_close: 998.0,
volume: 1_000_000,
}],
)
.expect("dataset");
let portfolio = PortfolioState::new(30_000.0);
let subscriptions = BTreeSet::new();
let ctx = StrategyContext {
execution_date: date,
decision_date: date,
decision_index: 1,
data: &data,
portfolio: &portfolio,
futures_account: None,
open_orders: &[],
dynamic_universe: None,
subscriptions: &subscriptions,
process_events: &[],
active_process_event: None,
active_datetime: None,
order_events: &[],
fills: &[],
};
let mut cfg = PlatformExprStrategyConfig::microcap_rotation();
cfg.signal_symbol = "000001.SZ".to_string();
cfg.refresh_rate = 99;
cfg.max_positions = 2;
cfg.benchmark_short_ma_days = 1;
cfg.benchmark_long_ma_days = 1;
cfg.market_cap_lower_expr = "0".to_string();
cfg.market_cap_upper_expr = "100".to_string();
cfg.selection_limit_expr = "2".to_string();
cfg.stock_filter_expr = "close > 0".to_string();
cfg.daily_top_up_enabled = true;
cfg.retry_empty_rebalance = true;
let mut strategy = PlatformExprStrategy::new(cfg);
let decision = strategy.on_day(&ctx).expect("platform decision");
assert!(
decision
.diagnostics
.iter()
.any(|item| item.contains("selected=2")),
"{:?}",
decision.diagnostics
);
assert!(
!decision
.diagnostics
.iter()
.any(|item| item.contains("selected=3")),
"{:?}",
decision.diagnostics
);
}
#[test]
fn platform_strategy_emits_target_shares_explicit_action() {
let date = d(2025, 2, 3);