验证目标组合区间表达式

This commit is contained in:
boris
2026-06-29 17:45:46 +08:00
parent 9e6eac557f
commit 19b7a0c00c
@@ -20259,13 +20259,16 @@ mod tests {
target_weights_expr: concat!(
"{",
"\"000521.SZ\": if current_date == \"2023-01-03\" { 0.025 } else { 0.0 },",
"\"000333.SZ\": if current_date >= \"2023-01-03\" && current_date < \"2023-02-27\" { 0.05 } else { 0.0 },",
"\"001239.SZ\": if current_date == \"2024-08-13\" { 0.025 } else { 0.0 }",
"}"
)
.to_string(),
order_prices_expr: None,
valuation_prices_expr: None,
when_expr: None,
when_expr: Some(
"current_date >= \"2023-01-03\" && current_date <= \"2023-03-02\"".to_string(),
),
reason: "date_conditioned_target_weights".to_string(),
}];
let mut strategy = PlatformExprStrategy::new(cfg);
@@ -20276,13 +20279,14 @@ mod tests {
match &decision.order_intents[0] {
crate::strategy::OrderIntent::TargetPortfolioSmart { target_weights, .. } => {
assert_eq!(target_weights.get("000521.SZ").copied(), Some(0.025));
assert_eq!(target_weights.get("000333.SZ").copied(), Some(0.05));
assert_eq!(target_weights.get("001239.SZ").copied(), Some(0.0));
assert_eq!(
target_weights
.iter()
.filter(|(_, weight)| weight.abs() > f64::EPSILON)
.count(),
1
2
);
}
other => panic!("unexpected explicit target portfolio intent: {other:?}"),