修正预计算rolling缺失回退
This commit is contained in:
@@ -2834,13 +2834,14 @@ impl PlatformExprStrategy {
|
|||||||
lookback: usize,
|
lookback: usize,
|
||||||
) -> Option<f64> {
|
) -> Option<f64> {
|
||||||
let precomputed = precomputed_stock_rolling_mean(extra_factors, field, lookback);
|
let precomputed = precomputed_stock_rolling_mean(extra_factors, field, lookback);
|
||||||
|
let computed = || {
|
||||||
|
ctx.data
|
||||||
|
.market_decision_numeric_moving_average(date, symbol, field, lookback)
|
||||||
|
};
|
||||||
if self.config.prefer_precomputed_rolling_factors {
|
if self.config.prefer_precomputed_rolling_factors {
|
||||||
precomputed
|
precomputed.or_else(computed)
|
||||||
} else {
|
} else {
|
||||||
let computed = ctx
|
computed().or(precomputed)
|
||||||
.data
|
|
||||||
.market_decision_numeric_moving_average(date, symbol, field, lookback);
|
|
||||||
computed.or(precomputed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25887,7 +25888,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn platform_stock_state_keeps_missing_precomputed_rolling_as_missing() {
|
fn platform_stock_state_falls_back_when_precomputed_rolling_is_missing() {
|
||||||
let current = d(2025, 5, 30);
|
let current = d(2025, 5, 30);
|
||||||
let start = current - chrono::Duration::days(100);
|
let start = current - chrono::Duration::days(100);
|
||||||
let symbol = "300022.SZ";
|
let symbol = "300022.SZ";
|
||||||
@@ -25994,10 +25995,10 @@ mod tests {
|
|||||||
let stock = strategy
|
let stock = strategy
|
||||||
.stock_state_with_factor_date(&ctx, current, current, symbol)
|
.stock_state_with_factor_date(&ctx, current, current, symbol)
|
||||||
.expect("stock state");
|
.expect("stock state");
|
||||||
assert!(stock.stock_volume_ma100.is_nan());
|
assert_eq!(stock.stock_volume_ma100, 1_000.0);
|
||||||
let day = strategy.day_state(&ctx, current).expect("day state");
|
let day = strategy.day_state(&ctx, current).expect("day state");
|
||||||
assert!(
|
assert!(
|
||||||
!strategy
|
strategy
|
||||||
.stock_passes_expr(&ctx, &day, &stock)
|
.stock_passes_expr(&ctx, &day, &stock)
|
||||||
.expect("stock expr")
|
.expect("stock expr")
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user