修复买入禁入误触发强平

This commit is contained in:
boris
2026-06-20 19:24:31 +08:00
parent eb4e77f8c5
commit 144483be4c
+4 -74
View File
@@ -2198,17 +2198,6 @@ impl PlatformExprStrategy {
} }
} }
fn candidate_requires_forced_exit(
&self,
ctx: &StrategyContext<'_>,
date: NaiveDate,
symbol: &str,
) -> bool {
ctx.data.candidate(date, symbol).is_some_and(|candidate| {
!candidate.allow_buy && candidate.allow_sell && !candidate.is_paused
})
}
fn stock_state_with_factor_date_and_time( fn stock_state_with_factor_date_and_time(
&self, &self,
ctx: &StrategyContext<'_>, ctx: &StrategyContext<'_>,
@@ -6831,10 +6820,6 @@ impl Strategy for PlatformExprStrategy {
)? { )? {
continue; continue;
} }
if self.candidate_requires_forced_exit(ctx, execution_date, &position.symbol) {
pending_full_close_symbols.insert(position.symbol.clone());
continue;
}
let (stop_hit, profit_hit) = let (stop_hit, profit_hit) =
self.stop_take_action_for_position(ctx, execution_date, &day, position)?; self.stop_take_action_for_position(ctx, execution_date, &day, position)?;
if stop_hit { if stop_hit {
@@ -6869,52 +6854,6 @@ impl Strategy for PlatformExprStrategy {
} }
} }
if self.config.aiquant_transaction_cost {
for position in ctx.portfolio.positions().values() {
if position.quantity == 0 || delayed_sold_symbols.contains(&position.symbol) {
continue;
}
if !pending_full_close_symbols.contains(&position.symbol)
|| !self.candidate_requires_forced_exit(ctx, execution_date, &position.symbol)
{
continue;
}
if self.regular_sell_should_wait_due_to_highlimit(
ctx,
execution_date,
&position.symbol,
self.intraday_execution_start_time(),
)? {
continue;
}
let can_sell = self.can_sell_position(ctx, execution_date, &position.symbol);
exit_symbols.insert(position.symbol.clone());
order_intents.push(OrderIntent::TargetValue {
symbol: position.symbol.clone(),
target_value: 0.0,
reason: "risk_forced_exit".to_string(),
});
if can_sell {
if self
.project_target_zero(
ctx,
&mut projected,
execution_date,
&position.symbol,
&mut projected_execution_state,
)
.is_some()
&& Self::projected_position_is_flat(&projected, &position.symbol)
{
same_day_sold_symbols.insert(position.symbol.clone());
slot_working_symbols.remove(&position.symbol);
}
} else {
unresolved_stop_loss_symbols.insert(position.symbol.clone());
}
}
}
if self.config.aiquant_transaction_cost if self.config.aiquant_transaction_cost
&& self.config.rotation_enabled && self.config.rotation_enabled
&& trading_ratio > 0.0 && trading_ratio > 0.0
@@ -10737,7 +10676,7 @@ mod tests {
} }
#[test] #[test]
fn platform_aiquant_forced_risk_exit_precedes_weak_market_shrink() { fn platform_aiquant_buy_disabled_does_not_force_exit_existing_position() {
let date = d(2023, 5, 5); let date = d(2023, 5, 5);
let symbol = "300621.SZ"; let symbol = "300621.SZ";
let data = DataSet::from_components( let data = DataSet::from_components(
@@ -10829,17 +10768,16 @@ mod tests {
let mut cfg = PlatformExprStrategyConfig::microcap_rotation(); let mut cfg = PlatformExprStrategyConfig::microcap_rotation();
cfg.aiquant_transaction_cost = true; cfg.aiquant_transaction_cost = true;
cfg.signal_symbol = symbol.to_string(); cfg.signal_symbol = symbol.to_string();
cfg.exposure_expr = "0.5".to_string(); cfg.exposure_expr = "1.0".to_string();
cfg.selection_limit_expr = "40".to_string(); cfg.selection_limit_expr = "40".to_string();
cfg.stock_filter_expr = "false".to_string(); cfg.stock_filter_expr = "true".to_string();
cfg.stop_loss_expr.clear(); cfg.stop_loss_expr.clear();
cfg.take_profit_expr.clear(); cfg.take_profit_expr.clear();
cfg.weak_market_shrink_overweight_threshold = Some(1.10);
let mut strategy = PlatformExprStrategy::new(cfg); let mut strategy = PlatformExprStrategy::new(cfg);
let decision = strategy.on_day(&ctx).expect("platform decision"); let decision = strategy.on_day(&ctx).expect("platform decision");
assert!(decision.order_intents.iter().any(|intent| matches!( assert!(!decision.order_intents.iter().any(|intent| matches!(
intent, intent,
OrderIntent::TargetValue { OrderIntent::TargetValue {
symbol: intent_symbol, symbol: intent_symbol,
@@ -10847,14 +10785,6 @@ mod tests {
reason, reason,
} if intent_symbol == symbol && *target_value == 0.0 && reason == "risk_forced_exit" } if intent_symbol == symbol && *target_value == 0.0 && reason == "risk_forced_exit"
))); )));
assert!(!decision.order_intents.iter().any(|intent| matches!(
intent,
OrderIntent::Shares {
symbol: intent_symbol,
reason,
..
} if intent_symbol == symbol && reason == "daily_position_target_adjust"
)));
} }
#[test] #[test]