修正策略投影tick依赖
This commit is contained in:
@@ -1191,14 +1191,14 @@ impl PlatformExprStrategy {
|
|||||||
)
|
)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
if ctx.data.execution_quotes_on(date, symbol).is_empty() {
|
if ctx.data.execution_quotes_on(date, symbol).is_empty() {
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(ProjectedExecutionFill {
|
Some(ProjectedExecutionFill {
|
||||||
price: self.projected_execution_price(market, OrderSide::Sell),
|
price: self.projected_execution_price(market, OrderSide::Sell),
|
||||||
quantity,
|
quantity,
|
||||||
next_cursor: date.and_time(self.intraday_execution_start_time())
|
next_cursor: date.and_time(self.intraday_execution_start_time())
|
||||||
+ Duration::seconds(1),
|
+ Duration::seconds(1),
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
let gross_amount = fill.price * fill.quantity as f64;
|
let gross_amount = fill.price * fill.quantity as f64;
|
||||||
@@ -1392,14 +1392,14 @@ impl PlatformExprStrategy {
|
|||||||
)
|
)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
if ctx.data.execution_quotes_on(date, symbol).is_empty() {
|
if ctx.data.execution_quotes_on(date, symbol).is_empty() {
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(ProjectedExecutionFill {
|
Some(ProjectedExecutionFill {
|
||||||
price: execution_price,
|
price: execution_price,
|
||||||
quantity,
|
quantity,
|
||||||
next_cursor: date.and_time(self.intraday_execution_start_time())
|
next_cursor: date.and_time(self.intraday_execution_start_time())
|
||||||
+ Duration::seconds(1),
|
+ Duration::seconds(1),
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let Some(fill) = fill else {
|
let Some(fill) = fill else {
|
||||||
@@ -10537,6 +10537,117 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn platform_aiquant_projection_uses_snapshot_before_execution_quotes_are_loaded() {
|
||||||
|
let date = d(2025, 5, 14);
|
||||||
|
let symbol = "000003.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: Some("2025-05-14 14:59:00".to_string()),
|
||||||
|
day_open: 10.0,
|
||||||
|
open: 10.0,
|
||||||
|
high: 10.5,
|
||||||
|
low: 9.8,
|
||||||
|
close: 10.0,
|
||||||
|
last_price: 10.0,
|
||||||
|
bid1: 10.0,
|
||||||
|
ask1: 10.0,
|
||||||
|
prev_close: 9.9,
|
||||||
|
volume: 1_000_000,
|
||||||
|
tick_volume: 10_000,
|
||||||
|
bid1_volume: 2_000,
|
||||||
|
ask1_volume: 2_000,
|
||||||
|
trading_phase: Some("continuous".to_string()),
|
||||||
|
paused: false,
|
||||||
|
upper_limit: 11.0,
|
||||||
|
lower_limit: 9.0,
|
||||||
|
price_tick: 0.01,
|
||||||
|
}],
|
||||||
|
vec![DailyFactorSnapshot {
|
||||||
|
date,
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
market_cap_bn: 10.0,
|
||||||
|
free_float_cap_bn: 10.0,
|
||||||
|
pe_ttm: 8.0,
|
||||||
|
turnover_ratio: Some(1.0),
|
||||||
|
effective_turnover_ratio: Some(1.0),
|
||||||
|
extra_factors: BTreeMap::new(),
|
||||||
|
}],
|
||||||
|
vec![CandidateEligibility {
|
||||||
|
date,
|
||||||
|
symbol: symbol.to_string(),
|
||||||
|
is_st: false,
|
||||||
|
is_new_listing: false,
|
||||||
|
is_paused: false,
|
||||||
|
allow_buy: true,
|
||||||
|
allow_sell: true,
|
||||||
|
is_kcb: false,
|
||||||
|
is_one_yuan: false,
|
||||||
|
}],
|
||||||
|
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 subscriptions = BTreeSet::new();
|
||||||
|
let portfolio = PortfolioState::new(100_000.0);
|
||||||
|
let ctx = StrategyContext {
|
||||||
|
execution_date: date,
|
||||||
|
decision_date: date,
|
||||||
|
decision_index: 20,
|
||||||
|
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.aiquant_transaction_cost = true;
|
||||||
|
let strategy = PlatformExprStrategy::new(cfg);
|
||||||
|
let mut projected = portfolio.clone();
|
||||||
|
let mut execution_state = super::ProjectedExecutionState::default();
|
||||||
|
|
||||||
|
assert!(ctx.data.execution_quotes_on(date, symbol).is_empty());
|
||||||
|
let filled = strategy.project_order_value(
|
||||||
|
&ctx,
|
||||||
|
&mut projected,
|
||||||
|
date,
|
||||||
|
symbol,
|
||||||
|
10_000.0,
|
||||||
|
&mut execution_state,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(filled > 0);
|
||||||
|
assert_eq!(
|
||||||
|
projected.position(symbol).map(|position| position.quantity),
|
||||||
|
Some(filled)
|
||||||
|
);
|
||||||
|
assert!(projected.cash() < portfolio.cash());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn platform_projection_does_not_consume_cash_from_unfillable_sell() {
|
fn platform_projection_does_not_consume_cash_from_unfillable_sell() {
|
||||||
let prev_date = d(2025, 3, 18);
|
let prev_date = d(2025, 3, 18);
|
||||||
|
|||||||
Reference in New Issue
Block a user