修正满仓待清仓补仓槽位
This commit is contained in:
@@ -8362,7 +8362,7 @@ impl Strategy for PlatformExprStrategy {
|
|||||||
let mut pending_full_close_symbols = BTreeSet::<String>::new();
|
let mut pending_full_close_symbols = BTreeSet::<String>::new();
|
||||||
let mut slot_blocking_symbols = BTreeSet::<String>::new();
|
let mut slot_blocking_symbols = BTreeSet::<String>::new();
|
||||||
let should_block_released_slots_after_top_up = delayed_open_exit_submitted;
|
let should_block_released_slots_after_top_up = delayed_open_exit_submitted;
|
||||||
let should_block_partial_stop_residual_slot =
|
let should_block_partial_exit_residual_slot =
|
||||||
should_block_released_slots_after_top_up || trading_ratio < 1.0;
|
should_block_released_slots_after_top_up || trading_ratio < 1.0;
|
||||||
let interleaved_pending_full_close_symbols = BTreeSet::<String>::new();
|
let interleaved_pending_full_close_symbols = BTreeSet::<String>::new();
|
||||||
let risk_level_forced_exit_time = self.risk_level_forced_exit_time();
|
let risk_level_forced_exit_time = self.risk_level_forced_exit_time();
|
||||||
@@ -8741,7 +8741,9 @@ impl Strategy for PlatformExprStrategy {
|
|||||||
self.pending_full_close_symbols.remove(&position.symbol);
|
self.pending_full_close_symbols.remove(&position.symbol);
|
||||||
} else {
|
} else {
|
||||||
exit_symbols.insert(position.symbol.clone());
|
exit_symbols.insert(position.symbol.clone());
|
||||||
|
if should_block_partial_exit_residual_slot {
|
||||||
slot_blocking_symbols.insert(position.symbol.clone());
|
slot_blocking_symbols.insert(position.symbol.clone());
|
||||||
|
}
|
||||||
order_intents.push(OrderIntent::TargetValue {
|
order_intents.push(OrderIntent::TargetValue {
|
||||||
symbol: position.symbol.clone(),
|
symbol: position.symbol.clone(),
|
||||||
target_value: 0.0,
|
target_value: 0.0,
|
||||||
@@ -8768,7 +8770,9 @@ impl Strategy for PlatformExprStrategy {
|
|||||||
self.pending_full_close_symbols.remove(&position.symbol);
|
self.pending_full_close_symbols.remove(&position.symbol);
|
||||||
} else {
|
} else {
|
||||||
pending_full_close_symbols.insert(position.symbol.clone());
|
pending_full_close_symbols.insert(position.symbol.clone());
|
||||||
|
if should_block_partial_exit_residual_slot {
|
||||||
slot_blocking_symbols.insert(position.symbol.clone());
|
slot_blocking_symbols.insert(position.symbol.clone());
|
||||||
|
}
|
||||||
self.pending_full_close_symbols
|
self.pending_full_close_symbols
|
||||||
.insert(position.symbol.clone());
|
.insert(position.symbol.clone());
|
||||||
}
|
}
|
||||||
@@ -8811,7 +8815,7 @@ impl Strategy for PlatformExprStrategy {
|
|||||||
self.pending_full_close_symbols.remove(&position.symbol);
|
self.pending_full_close_symbols.remove(&position.symbol);
|
||||||
} else {
|
} else {
|
||||||
pending_full_close_symbols.insert(position.symbol.clone());
|
pending_full_close_symbols.insert(position.symbol.clone());
|
||||||
if should_block_partial_stop_residual_slot {
|
if should_block_partial_exit_residual_slot {
|
||||||
slot_blocking_symbols.insert(position.symbol.clone());
|
slot_blocking_symbols.insert(position.symbol.clone());
|
||||||
}
|
}
|
||||||
self.pending_full_close_symbols
|
self.pending_full_close_symbols
|
||||||
@@ -8881,7 +8885,9 @@ impl Strategy for PlatformExprStrategy {
|
|||||||
self.pending_full_close_symbols.remove(&position.symbol);
|
self.pending_full_close_symbols.remove(&position.symbol);
|
||||||
} else {
|
} else {
|
||||||
pending_full_close_symbols.insert(position.symbol.clone());
|
pending_full_close_symbols.insert(position.symbol.clone());
|
||||||
|
if should_block_partial_exit_residual_slot {
|
||||||
slot_blocking_symbols.insert(position.symbol.clone());
|
slot_blocking_symbols.insert(position.symbol.clone());
|
||||||
|
}
|
||||||
self.pending_full_close_symbols
|
self.pending_full_close_symbols
|
||||||
.insert(position.symbol.clone());
|
.insert(position.symbol.clone());
|
||||||
}
|
}
|
||||||
@@ -22021,8 +22027,7 @@ mod tests {
|
|||||||
assert_eq!(top_up_symbols, vec!["000001.SZ"]);
|
assert_eq!(top_up_symbols, vec!["000001.SZ"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
fn carried_full_close_top_up_symbols_for_exposure(exposure_expr: &str) -> Vec<String> {
|
||||||
fn platform_aiquant_carried_full_close_does_not_release_new_top_up_slot() {
|
|
||||||
let prev_date = d(2025, 4, 29);
|
let prev_date = d(2025, 4, 29);
|
||||||
let date = d(2025, 4, 30);
|
let date = d(2025, 4, 30);
|
||||||
let buy_first = "000001.SZ";
|
let buy_first = "000001.SZ";
|
||||||
@@ -22166,7 +22171,7 @@ mod tests {
|
|||||||
cfg.market_cap_upper_expr = "1000".to_string();
|
cfg.market_cap_upper_expr = "1000".to_string();
|
||||||
cfg.selection_limit_expr = "4".to_string();
|
cfg.selection_limit_expr = "4".to_string();
|
||||||
cfg.stock_filter_expr = "close > 0".to_string();
|
cfg.stock_filter_expr = "close > 0".to_string();
|
||||||
cfg.exposure_expr = "1.0".to_string();
|
cfg.exposure_expr = exposure_expr.to_string();
|
||||||
cfg.take_profit_expr = "1.1".to_string();
|
cfg.take_profit_expr = "1.1".to_string();
|
||||||
cfg.daily_top_up_enabled = true;
|
cfg.daily_top_up_enabled = true;
|
||||||
cfg.release_slot_on_exit_signal = true;
|
cfg.release_slot_on_exit_signal = true;
|
||||||
@@ -22184,7 +22189,7 @@ mod tests {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter_map(|intent| match intent {
|
.filter_map(|intent| match intent {
|
||||||
OrderIntent::Value { symbol, reason, .. } if reason == "daily_top_up_buy" => {
|
OrderIntent::Value { symbol, reason, .. } if reason == "daily_top_up_buy" => {
|
||||||
Some(symbol.as_str())
|
Some(symbol.clone())
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
@@ -22204,19 +22209,24 @@ mod tests {
|
|||||||
"{:?}",
|
"{:?}",
|
||||||
decision.order_intents
|
decision.order_intents
|
||||||
);
|
);
|
||||||
|
top_up_symbols
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn platform_full_exposure_carried_full_close_releases_second_top_up_slot() {
|
||||||
|
let top_up_symbols = carried_full_close_top_up_symbols_for_exposure("1.0");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
top_up_symbols,
|
top_up_symbols,
|
||||||
vec![buy_first],
|
vec!["000001.SZ".to_string(), "000002.SZ".to_string()]
|
||||||
"{:?}",
|
|
||||||
decision.order_intents
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
!top_up_symbols.contains(&buy_second),
|
|
||||||
"{:?}",
|
|
||||||
decision.order_intents
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn platform_weak_exposure_carried_full_close_keeps_residual_slot() {
|
||||||
|
let top_up_symbols = carried_full_close_top_up_symbols_for_exposure("0.5");
|
||||||
|
assert!(top_up_symbols.is_empty(), "{top_up_symbols:?}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn platform_max_holding_days_exit_preempts_take_profit_exit() {
|
fn platform_max_holding_days_exit_preempts_take_profit_exit() {
|
||||||
let date = d(2025, 2, 26);
|
let date = d(2025, 2, 26);
|
||||||
|
|||||||
Reference in New Issue
Block a user