perf: freeze rank expression presence
This commit is contained in:
@@ -1121,6 +1121,7 @@ pub struct PlatformExprStrategy {
|
||||
prelude_declared_identifiers: BTreeSet<String>,
|
||||
stock_filter_quote_usage: StockFilterQuoteUsage,
|
||||
stock_filter_expr_present: bool,
|
||||
rank_expr_present: bool,
|
||||
selection_quote_usage: StockFilterQuoteUsage,
|
||||
stock_rolling_requirements: StockRollingRequirements,
|
||||
stock_current_rolling_mean_required: bool,
|
||||
@@ -1397,6 +1398,7 @@ impl PlatformExprStrategy {
|
||||
let prelude_declared_identifiers = Self::declared_prelude_identifiers(&config.prelude);
|
||||
let normalized_stock_filter_expr = Self::normalize_expr(&config.stock_filter_expr);
|
||||
let stock_filter_expr_present = !normalized_stock_filter_expr.is_empty();
|
||||
let rank_expr_present = !config.rank_expr.trim().is_empty();
|
||||
let stock_filter_quote_usage =
|
||||
Self::stock_filter_quote_usage_for_expr(&normalized_stock_filter_expr);
|
||||
let selection_quote_usage =
|
||||
@@ -1446,6 +1448,7 @@ impl PlatformExprStrategy {
|
||||
prelude_declared_identifiers,
|
||||
stock_filter_quote_usage,
|
||||
stock_filter_expr_present,
|
||||
rank_expr_present,
|
||||
selection_quote_usage,
|
||||
stock_rolling_requirements,
|
||||
stock_current_rolling_mean_required,
|
||||
@@ -9883,7 +9886,7 @@ impl PlatformExprStrategy {
|
||||
free_float_cap_bn: f64,
|
||||
stock: &StockExpressionState,
|
||||
) -> Result<f64, BacktestError> {
|
||||
if !self.config.rank_expr.trim().is_empty() {
|
||||
if self.rank_expr_present {
|
||||
return match self.eval_float(ctx, &self.config.rank_expr, day, Some(stock), None) {
|
||||
Ok(value) => Ok(value),
|
||||
Err(error) if Self::is_missing_rolling_mean_error(&error) => Ok(f64::NAN),
|
||||
@@ -9909,7 +9912,7 @@ impl PlatformExprStrategy {
|
||||
}
|
||||
|
||||
fn rank_reuses_market_cap_order(&self) -> bool {
|
||||
self.config.rank_expr.trim().is_empty()
|
||||
!self.rank_expr_present
|
||||
&& !self.config.rank_desc
|
||||
&& matches!(self.config.rank_by.trim(), "market_cap" | "market_cap_bn")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user