修正分钟止损缺少quote误触发
This commit is contained in:
@@ -7885,12 +7885,23 @@ impl PlatformExprStrategy {
|
|||||||
if position.quantity == 0 || stop_take_base_price <= 0.0 {
|
if position.quantity == 0 || stop_take_base_price <= 0.0 {
|
||||||
return Ok((false, false));
|
return Ok((false, false));
|
||||||
}
|
}
|
||||||
let stock = match self.stock_state_at_time(
|
let scheduled_time = self.intraday_execution_start_time();
|
||||||
ctx,
|
if self.config.aiquant_transaction_cost
|
||||||
signal_date,
|
&& matches!(
|
||||||
symbol,
|
self.config.matching_type,
|
||||||
Some(self.intraday_execution_start_time()),
|
MatchingType::MinuteLast
|
||||||
) {
|
| MatchingType::MinuteBestOwn
|
||||||
|
| MatchingType::MinuteBestCounterparty
|
||||||
|
| MatchingType::Vwap
|
||||||
|
| MatchingType::Twap
|
||||||
|
)
|
||||||
|
&& self
|
||||||
|
.aiquant_scheduled_quote_at_time(ctx, signal_date, symbol, Some(scheduled_time))
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
return Ok((false, false));
|
||||||
|
}
|
||||||
|
let stock = match self.stock_state_at_time(ctx, signal_date, symbol, Some(scheduled_time)) {
|
||||||
Ok(stock) => stock,
|
Ok(stock) => stock,
|
||||||
Err(BacktestError::Data(crate::data::DataSetError::MissingSnapshot { .. })) => {
|
Err(BacktestError::Data(crate::data::DataSetError::MissingSnapshot { .. })) => {
|
||||||
return Ok((false, false));
|
return Ok((false, false));
|
||||||
@@ -13264,6 +13275,123 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn platform_aiquant_minute_stop_loss_requires_intraday_quote() {
|
||||||
|
let prev_date = d(2025, 3, 13);
|
||||||
|
let date = d(2025, 3, 14);
|
||||||
|
let symbol = "301076.SZ";
|
||||||
|
let data = DataSet::from_components(
|
||||||
|
vec![Instrument {
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
name: symbol.to_string(),
|
||||||
|
board: "SZ".to_string(),
|
||||||
|
round_lot: 100,
|
||||||
|
listed_at: Some(d(2020, 1, 1)),
|
||||||
|
delisted_at: None,
|
||||||
|
status: "active".to_string(),
|
||||||
|
}],
|
||||||
|
vec![DailyMarketSnapshot {
|
||||||
|
date,
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
timestamp: None,
|
||||||
|
day_open: 9.30,
|
||||||
|
open: 9.30,
|
||||||
|
high: 9.35,
|
||||||
|
low: 9.18,
|
||||||
|
close: 9.10,
|
||||||
|
last_price: 9.10,
|
||||||
|
bid1: 9.10,
|
||||||
|
ask1: 9.11,
|
||||||
|
prev_close: 10.00,
|
||||||
|
volume: 1_000_000,
|
||||||
|
minute_volume: 0,
|
||||||
|
bid1_volume: 0,
|
||||||
|
ask1_volume: 0,
|
||||||
|
trading_phase: None,
|
||||||
|
paused: false,
|
||||||
|
upper_limit: 11.00,
|
||||||
|
lower_limit: 9.00,
|
||||||
|
price_tick: 0.01,
|
||||||
|
}],
|
||||||
|
vec![DailyFactorSnapshot {
|
||||||
|
date,
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
market_cap_bn: 3.2,
|
||||||
|
free_float_cap_bn: 2.1,
|
||||||
|
pe_ttm: 8.0,
|
||||||
|
turnover_ratio: Some(3.0),
|
||||||
|
effective_turnover_ratio: Some(3.0),
|
||||||
|
extra_factors: BTreeMap::new(),
|
||||||
|
}],
|
||||||
|
vec![CandidateEligibility {
|
||||||
|
date,
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
is_st: false,
|
||||||
|
is_star_st: false,
|
||||||
|
is_new_listing: false,
|
||||||
|
is_paused: false,
|
||||||
|
allow_buy: true,
|
||||||
|
allow_sell: true,
|
||||||
|
is_kcb: false,
|
||||||
|
is_one_yuan: false,
|
||||||
|
risk_level_code: None,
|
||||||
|
}],
|
||||||
|
vec![BenchmarkSnapshot {
|
||||||
|
date,
|
||||||
|
benchmark: "000852.SH".to_string(),
|
||||||
|
open: 1000.0,
|
||||||
|
close: 1002.0,
|
||||||
|
prev_close: 998.0,
|
||||||
|
volume: 1_000_000,
|
||||||
|
}],
|
||||||
|
)
|
||||||
|
.expect("dataset");
|
||||||
|
let mut portfolio = PortfolioState::new(1_000_000.0);
|
||||||
|
portfolio.position_mut(symbol).buy(prev_date, 100, 10.0);
|
||||||
|
|
||||||
|
let subscriptions = BTreeSet::new();
|
||||||
|
let ctx = StrategyContext {
|
||||||
|
execution_date: date,
|
||||||
|
decision_date: date,
|
||||||
|
decision_index: 40,
|
||||||
|
data: &data,
|
||||||
|
portfolio: &portfolio,
|
||||||
|
futures_account: None,
|
||||||
|
open_orders: &[],
|
||||||
|
dynamic_universe: None,
|
||||||
|
subscriptions: &subscriptions,
|
||||||
|
process_events: &[],
|
||||||
|
active_process_event: None,
|
||||||
|
active_datetime: None,
|
||||||
|
order_events: &[],
|
||||||
|
fills: &[],
|
||||||
|
};
|
||||||
|
let mut cfg = PlatformExprStrategyConfig::microcap_rotation();
|
||||||
|
cfg.rotation_enabled = false;
|
||||||
|
cfg.aiquant_transaction_cost = true;
|
||||||
|
cfg.matching_type = MatchingType::MinuteLast;
|
||||||
|
cfg.intraday_execution_time = Some(NaiveTime::from_hms_opt(10, 18, 0).expect("time"));
|
||||||
|
cfg.signal_symbol = symbol.to_string();
|
||||||
|
cfg.stop_loss_expr = "0.92".to_string();
|
||||||
|
cfg.take_profit_expr.clear();
|
||||||
|
let mut strategy = PlatformExprStrategy::new(cfg);
|
||||||
|
|
||||||
|
let decision = strategy.on_day(&ctx).expect("platform decision");
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
!decision.order_intents.iter().any(|intent| matches!(
|
||||||
|
intent,
|
||||||
|
OrderIntent::TargetValue {
|
||||||
|
symbol: intent_symbol,
|
||||||
|
target_value,
|
||||||
|
reason,
|
||||||
|
} if intent_symbol == symbol && *target_value == 0.0 && reason == "stop_loss_exit"
|
||||||
|
)),
|
||||||
|
"{:?}",
|
||||||
|
decision.order_intents
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn platform_stop_loss_residual_pending_rechecks_signal_next_day() {
|
fn platform_stop_loss_residual_pending_rechecks_signal_next_day() {
|
||||||
let prev_date = d(2025, 1, 6);
|
let prev_date = d(2025, 1, 6);
|
||||||
|
|||||||
Reference in New Issue
Block a user