perf: isolate generic selection ranking
This commit is contained in:
@@ -10117,15 +10117,14 @@ impl PlatformExprStrategy {
|
||||
universe_factor_date,
|
||||
5,
|
||||
);
|
||||
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);
|
||||
|
||||
// The universe is already stably ordered by market cap. When the
|
||||
// strategy asks for that exact ascending order and does not need a
|
||||
// complete ranking for replacement limiting, select directly from the
|
||||
// ordered stream instead of materializing a second candidate vector.
|
||||
if self.rank_reuses_market_cap_order() && self.config.daily_replacement_limit == 0 {
|
||||
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);
|
||||
let mut selected = Vec::with_capacity(limit.min(universe_symbol_ids.len()));
|
||||
for symbol_id in universe_symbol_ids {
|
||||
let factor = universe_factor_day
|
||||
@@ -10166,6 +10165,39 @@ impl PlatformExprStrategy {
|
||||
return Ok((selected, diagnostics, risk_decisions));
|
||||
}
|
||||
|
||||
let selected = self.select_ranked_symbols(
|
||||
ctx,
|
||||
date,
|
||||
universe_factor_date,
|
||||
stock_factor_date,
|
||||
day,
|
||||
band_low,
|
||||
band_high,
|
||||
limit,
|
||||
universe_symbol_ids,
|
||||
&mut diagnostics,
|
||||
)?;
|
||||
Ok((selected, diagnostics, risk_decisions))
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn select_ranked_symbols(
|
||||
&self,
|
||||
ctx: &StrategyContext<'_>,
|
||||
date: NaiveDate,
|
||||
universe_factor_date: NaiveDate,
|
||||
stock_factor_date: NaiveDate,
|
||||
day: &DayExpressionState,
|
||||
band_low: f64,
|
||||
band_high: f64,
|
||||
limit: usize,
|
||||
universe_symbol_ids: Vec<u32>,
|
||||
diagnostics: &mut Vec<String>,
|
||||
) -> Result<Vec<String>, BacktestError> {
|
||||
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);
|
||||
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;
|
||||
@@ -10275,7 +10307,7 @@ impl PlatformExprStrategy {
|
||||
day,
|
||||
&candidate.symbol,
|
||||
stock,
|
||||
&mut diagnostics,
|
||||
diagnostics,
|
||||
)? {
|
||||
continue;
|
||||
}
|
||||
@@ -10292,7 +10324,7 @@ impl PlatformExprStrategy {
|
||||
));
|
||||
}
|
||||
|
||||
Ok((selected, diagnostics, risk_decisions))
|
||||
Ok(selected)
|
||||
}
|
||||
|
||||
fn stock_filter_quote_usage(&self) -> StockFilterQuoteUsage {
|
||||
|
||||
Reference in New Issue
Block a user