diff --git a/crates/fidc-core/src/platform_expr_strategy.rs b/crates/fidc-core/src/platform_expr_strategy.rs index 1c49e1e..a896fff 100644 --- a/crates/fidc-core/src/platform_expr_strategy.rs +++ b/crates/fidc-core/src/platform_expr_strategy.rs @@ -10166,7 +10166,8 @@ impl PlatformExprStrategy { return Ok((selected, diagnostics, risk_decisions)); } - let mut candidates = Vec::new(); + let mut candidates = Vec::with_capacity(universe_symbol_ids.len()); + let mut candidate_states = Vec::with_capacity(universe_symbol_ids.len()); let mut missing_rank_count = 0usize; let mut missing_rank_examples = Vec::new(); for symbol_id in universe_symbol_ids { @@ -10240,12 +10241,14 @@ impl PlatformExprStrategy { } continue; } - candidates.push((candidate, stock, rank_value)); + let state_index = candidate_states.len(); + candidate_states.push(stock); + candidates.push((candidate, rank_value, state_index)); } if !self.rank_reuses_market_cap_order() { candidates.sort_by(|lhs, rhs| { - let lhs_value = lhs.2; - let rhs_value = rhs.2; + let lhs_value = lhs.1; + let rhs_value = rhs.1; let ordering = if self.config.rank_desc { rhs_value .partial_cmp(&lhs_value) @@ -10264,13 +10267,14 @@ impl PlatformExprStrategy { } let mut selected = Vec::new(); - for (candidate, stock, _) in candidates { + for (candidate, _, state_index) in candidates { + let stock = &candidate_states[state_index]; if !self.selection_candidate_passes_filters( ctx, date, day, &candidate.symbol, - &stock, + stock, &mut diagnostics, )? { continue; @@ -10884,7 +10888,6 @@ impl PlatformExprStrategy { selection_limit: usize, ) -> Result<(Vec, Vec, usize, Vec), BacktestError> { let mut diagnostics = Vec::new(); - let mut candidates = Vec::new(); let mut missing_rank_count = 0usize; let mut missing_rank_examples = Vec::new(); let quote_usage = self.stock_filter_quote_usage(); @@ -10904,6 +10907,8 @@ impl PlatformExprStrategy { selection_risk_deferral, false, ); + let mut candidates = Vec::with_capacity(universe_symbol_ids.len()); + let mut candidate_states = Vec::with_capacity(universe_symbol_ids.len()); let execution_day = ctx.data.daily_snapshot_view(date); let universe_factor_day = ctx.data.daily_snapshot_view(universe_factor_date); let factor_day = ctx.data.daily_snapshot_view(stock_factor_date); @@ -10959,7 +10964,9 @@ impl PlatformExprStrategy { } continue; } - candidates.push((candidate.symbol.clone(), rank_value, stock)); + let state_index = candidate_states.len(); + candidate_states.push(stock); + candidates.push((candidate.symbol.clone(), rank_value, state_index)); } candidates.sort_by(|lhs, rhs| { let ordering = if self.config.rank_desc { @@ -10981,7 +10988,8 @@ impl PlatformExprStrategy { let mut quote_candidate_symbols = Vec::new(); let mut selected_symbols = Vec::new(); let mut processed_scope = 0usize; - for (symbol, _, stock) in &candidates { + for (symbol, _, state_index) in &candidates { + let stock = &candidate_states[*state_index]; processed_scope += 1; if !self.stock_passes_quote_plan_filter(ctx, day, stock, quote_usage)? { if diagnostics.len() < 12 {