perf: keep ranked candidate states transient
This commit is contained in:
@@ -3981,32 +3981,6 @@ impl PlatformExprStrategy {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selection_stock_state_with_factor_date_from_views<'a>(
|
|
||||||
&self,
|
|
||||||
ctx: &StrategyContext<'a>,
|
|
||||||
date: NaiveDate,
|
|
||||||
factor_date: NaiveDate,
|
|
||||||
symbol: &str,
|
|
||||||
execution_day: &DailySnapshotView<'a>,
|
|
||||||
factor_day: &DailySnapshotView<'a>,
|
|
||||||
) -> Result<Arc<StockExpressionState>, BacktestError> {
|
|
||||||
let source = ViewStockStateSnapshotSource {
|
|
||||||
execution: execution_day,
|
|
||||||
factor: factor_day,
|
|
||||||
same_date: factor_date == date,
|
|
||||||
};
|
|
||||||
let use_intraday_quote = self.selection_quote_usage != StockFilterQuoteUsage::DailyOnly;
|
|
||||||
self.stock_state_with_factor_date_and_time_from_source(
|
|
||||||
ctx,
|
|
||||||
date,
|
|
||||||
factor_date,
|
|
||||||
symbol,
|
|
||||||
None,
|
|
||||||
use_intraday_quote,
|
|
||||||
&source,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn uncached_selection_stock_state_from_views_by_symbol_id<'a>(
|
fn uncached_selection_stock_state_from_views_by_symbol_id<'a>(
|
||||||
&self,
|
&self,
|
||||||
@@ -9497,6 +9471,7 @@ impl PlatformExprStrategy {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
fn selectable_universe_on_with_options(
|
fn selectable_universe_on_with_options(
|
||||||
&self,
|
&self,
|
||||||
ctx: &StrategyContext<'_>,
|
ctx: &StrategyContext<'_>,
|
||||||
@@ -9514,6 +9489,7 @@ impl PlatformExprStrategy {
|
|||||||
.0
|
.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
fn selection_universe_and_risk_decisions_with_options(
|
fn selection_universe_and_risk_decisions_with_options(
|
||||||
&self,
|
&self,
|
||||||
ctx: &StrategyContext<'_>,
|
ctx: &StrategyContext<'_>,
|
||||||
@@ -10190,28 +10166,23 @@ impl PlatformExprStrategy {
|
|||||||
return Ok((selected, diagnostics, risk_decisions));
|
return Ok((selected, diagnostics, risk_decisions));
|
||||||
}
|
}
|
||||||
|
|
||||||
let universe = universe_symbol_ids
|
|
||||||
.into_iter()
|
|
||||||
.map(|symbol_id| {
|
|
||||||
let factor = universe_factor_day
|
|
||||||
.factor(symbol_id)
|
|
||||||
.expect("market-cap order references missing factor row");
|
|
||||||
EligibleUniverseSnapshot {
|
|
||||||
symbol: factor.symbol.clone(),
|
|
||||||
market_cap_bn: decision_market_cap_bn(factor),
|
|
||||||
free_float_cap_bn: decision_free_float_cap_bn(factor),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let mut candidates = Vec::new();
|
let mut candidates = Vec::new();
|
||||||
let mut missing_rank_count = 0usize;
|
let mut missing_rank_count = 0usize;
|
||||||
let mut missing_rank_examples = Vec::new();
|
let mut missing_rank_examples = Vec::new();
|
||||||
for candidate in universe {
|
for symbol_id in universe_symbol_ids {
|
||||||
let stock = self.selection_stock_state_with_factor_date_from_views(
|
let factor = universe_factor_day
|
||||||
|
.factor(symbol_id)
|
||||||
|
.expect("market-cap order references missing factor row");
|
||||||
|
let candidate = EligibleUniverseSnapshot {
|
||||||
|
symbol: factor.symbol.clone(),
|
||||||
|
market_cap_bn: decision_market_cap_bn(factor),
|
||||||
|
free_float_cap_bn: decision_free_float_cap_bn(factor),
|
||||||
|
};
|
||||||
|
let stock = self.uncached_selection_stock_state_from_views_by_symbol_id(
|
||||||
ctx,
|
ctx,
|
||||||
date,
|
date,
|
||||||
stock_factor_date,
|
stock_factor_date,
|
||||||
|
symbol_id,
|
||||||
&candidate.symbol,
|
&candidate.symbol,
|
||||||
&execution_day,
|
&execution_day,
|
||||||
&factor_day,
|
&factor_day,
|
||||||
@@ -10926,20 +10897,31 @@ impl PlatformExprStrategy {
|
|||||||
} else {
|
} else {
|
||||||
SelectionRiskDeferral::None
|
SelectionRiskDeferral::None
|
||||||
};
|
};
|
||||||
let universe = self.selectable_universe_on_with_options(
|
let (universe_symbol_ids, _) = self.selection_symbol_ids_and_risk_decisions_with_options(
|
||||||
ctx,
|
ctx,
|
||||||
date,
|
date,
|
||||||
universe_factor_date,
|
universe_factor_date,
|
||||||
selection_risk_deferral,
|
selection_risk_deferral,
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
let execution_day = ctx.data.daily_snapshot_view(date);
|
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 factor_day = ctx.data.daily_snapshot_view(stock_factor_date);
|
||||||
let quote_candidate_limit = self.quote_plan_candidate_limit(selection_limit);
|
let quote_candidate_limit = self.quote_plan_candidate_limit(selection_limit);
|
||||||
for candidate in universe {
|
for symbol_id in universe_symbol_ids {
|
||||||
let stock = self.selection_stock_state_with_factor_date_from_views(
|
let factor = universe_factor_day
|
||||||
|
.factor(symbol_id)
|
||||||
|
.expect("market-cap order references missing factor row");
|
||||||
|
let candidate = EligibleUniverseSnapshot {
|
||||||
|
symbol: factor.symbol.clone(),
|
||||||
|
market_cap_bn: decision_market_cap_bn(factor),
|
||||||
|
free_float_cap_bn: decision_free_float_cap_bn(factor),
|
||||||
|
};
|
||||||
|
let stock = self.uncached_selection_stock_state_from_views_by_symbol_id(
|
||||||
ctx,
|
ctx,
|
||||||
date,
|
date,
|
||||||
stock_factor_date,
|
stock_factor_date,
|
||||||
|
symbol_id,
|
||||||
&candidate.symbol,
|
&candidate.symbol,
|
||||||
&execution_day,
|
&execution_day,
|
||||||
&factor_day,
|
&factor_day,
|
||||||
@@ -11001,7 +10983,7 @@ impl PlatformExprStrategy {
|
|||||||
let mut processed_scope = 0usize;
|
let mut processed_scope = 0usize;
|
||||||
for (symbol, _, stock) in &candidates {
|
for (symbol, _, stock) in &candidates {
|
||||||
processed_scope += 1;
|
processed_scope += 1;
|
||||||
if !self.stock_passes_quote_plan_filter(ctx, day, &stock, quote_usage)? {
|
if !self.stock_passes_quote_plan_filter(ctx, day, stock, quote_usage)? {
|
||||||
if diagnostics.len() < 12 {
|
if diagnostics.len() < 12 {
|
||||||
diagnostics.push(format!("{symbol} quote_plan rejected by stock_expr"));
|
diagnostics.push(format!("{symbol} quote_plan rejected by stock_expr"));
|
||||||
}
|
}
|
||||||
@@ -11019,7 +11001,7 @@ impl PlatformExprStrategy {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if quote_usage == StockFilterQuoteUsage::IntradayQuote
|
if quote_usage == StockFilterQuoteUsage::IntradayQuote
|
||||||
&& !self.stock_passes_expr(ctx, day, &stock)?
|
&& !self.stock_passes_expr(ctx, day, stock)?
|
||||||
{
|
{
|
||||||
if diagnostics.len() < 12 {
|
if diagnostics.len() < 12 {
|
||||||
diagnostics.push(format!("{symbol} quote_plan rejected by stock_expr"));
|
diagnostics.push(format!("{symbol} quote_plan rejected by stock_expr"));
|
||||||
|
|||||||
Reference in New Issue
Block a user