修复next-open执行日风控价格

This commit is contained in:
boris
2026-07-05 13:48:01 +08:00
parent 2f61bd8e57
commit d3c986e1f2
3 changed files with 469 additions and 22 deletions
+65
View File
@@ -5210,6 +5210,30 @@ mod tests {
);
}
#[test]
fn next_bar_open_execution_risk_uses_open_not_close_for_upper_limit_buy() {
let first = d(2025, 1, 2);
let second = d(2025, 1, 3);
let result = run_scheduled_next_open_with_dataset(dataset_with(
market(first, 10.0, 11.5),
market_with_state(second, 11.8, 12.0, false, 12.0, 1.0),
candidate(first),
candidate(second),
));
assert_eq!(result.fills.len(), 1);
assert_eq!(result.fills[0].date, second);
assert_eq!(result.fills[0].price, 11.8);
assert!(
result
.order_events
.iter()
.all(|event| !event.reason.contains("upper limit")),
"{:?}",
result.order_events
);
}
#[test]
fn next_bar_open_execution_risk_rejects_execution_day_st_state() {
let first = d(2025, 1, 2);
@@ -5344,6 +5368,47 @@ mod tests {
assert_round_trip_sell_canceled_with_reason(&result, "open at or below lower limit");
}
#[test]
fn next_bar_open_sell_risk_uses_open_not_close_for_lower_limit_sell() {
let first = d(2025, 1, 2);
let second = d(2025, 1, 3);
let third = d(2025, 1, 6);
let fourth = d(2025, 1, 7);
let result = run_scheduled_round_trip_next_open_with_dataset_and_broker(
dataset_from_market_and_candidates(
vec![
market(first, 10.0, 10.5),
market(second, 11.0, 11.5),
market(third, 12.0, 12.5),
market_with_state(fourth, 9.2, 9.0, false, 20.0, 9.0),
],
vec![
candidate(first),
candidate(second),
candidate(third),
candidate(fourth),
],
),
scheduled_next_open_broker(FidcRiskControlConfig::default()),
);
let sell_fill = result
.fills
.iter()
.find(|fill| fill.side == OrderSide::Sell)
.expect("sell should execute when next-open is above lower limit");
assert_eq!(sell_fill.date, fourth);
assert_eq!(sell_fill.price, 9.2);
assert!(
result
.order_events
.iter()
.all(|event| !event.reason.contains("lower limit")),
"{:?}",
result.order_events
);
}
#[test]
fn next_bar_open_sell_respects_allow_sell_policy_on_execution_day() {
let first = d(2025, 1, 2);