修复平台策略执行行情投影判断
This commit is contained in:
@@ -1531,7 +1531,7 @@ impl PlatformExprStrategy {
|
|||||||
symbol,
|
symbol,
|
||||||
execution_state,
|
execution_state,
|
||||||
execution_time,
|
execution_time,
|
||||||
) && !ctx.data.has_execution_quotes_on_date(date)
|
) && ctx.data.execution_quotes_on(date, symbol).is_empty()
|
||||||
{
|
{
|
||||||
Some(ProjectedExecutionFill {
|
Some(ProjectedExecutionFill {
|
||||||
price: self.projected_execution_price(market, OrderSide::Sell),
|
price: self.projected_execution_price(market, OrderSide::Sell),
|
||||||
@@ -1887,7 +1887,7 @@ impl PlatformExprStrategy {
|
|||||||
)
|
)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
if !self.has_execution_quote_at_or_before(ctx, date, symbol, execution_state)
|
if !self.has_execution_quote_at_or_before(ctx, date, symbol, execution_state)
|
||||||
&& !ctx.data.has_execution_quotes_on_date(date)
|
&& ctx.data.execution_quotes_on(date, symbol).is_empty()
|
||||||
{
|
{
|
||||||
Some(ProjectedExecutionFill {
|
Some(ProjectedExecutionFill {
|
||||||
price: sizing_price,
|
price: sizing_price,
|
||||||
@@ -15146,60 +15146,73 @@ mod tests {
|
|||||||
fn platform_aiquant_projection_uses_snapshot_before_execution_quotes_are_loaded() {
|
fn platform_aiquant_projection_uses_snapshot_before_execution_quotes_are_loaded() {
|
||||||
let date = d(2025, 5, 14);
|
let date = d(2025, 5, 14);
|
||||||
let symbol = "000003.SZ";
|
let symbol = "000003.SZ";
|
||||||
let data = DataSet::from_components(
|
let other_symbol = "000004.SZ";
|
||||||
vec![Instrument {
|
let data = DataSet::from_components_with_actions_and_quotes(
|
||||||
symbol: symbol.to_string(),
|
[symbol, other_symbol]
|
||||||
name: symbol.to_string(),
|
.into_iter()
|
||||||
board: "SZ".to_string(),
|
.map(|item| Instrument {
|
||||||
round_lot: 100,
|
symbol: item.to_string(),
|
||||||
listed_at: Some(d(2020, 1, 1)),
|
name: item.to_string(),
|
||||||
delisted_at: None,
|
board: "SZ".to_string(),
|
||||||
status: "active".to_string(),
|
round_lot: 100,
|
||||||
}],
|
listed_at: Some(d(2020, 1, 1)),
|
||||||
vec![DailyMarketSnapshot {
|
delisted_at: None,
|
||||||
date,
|
status: "active".to_string(),
|
||||||
symbol: symbol.to_string(),
|
})
|
||||||
timestamp: Some("2025-05-14 14:59:00".to_string()),
|
.collect(),
|
||||||
day_open: 10.0,
|
[symbol, other_symbol]
|
||||||
open: 10.0,
|
.into_iter()
|
||||||
high: 10.5,
|
.map(|item| DailyMarketSnapshot {
|
||||||
low: 9.8,
|
date,
|
||||||
close: 10.0,
|
symbol: item.to_string(),
|
||||||
last_price: 10.0,
|
timestamp: Some("2025-05-14 14:59:00".to_string()),
|
||||||
bid1: 10.0,
|
day_open: 10.0,
|
||||||
ask1: 10.0,
|
open: 10.0,
|
||||||
prev_close: 9.9,
|
high: 10.5,
|
||||||
volume: 1_000_000,
|
low: 9.8,
|
||||||
tick_volume: 10_000,
|
close: 10.0,
|
||||||
bid1_volume: 2_000,
|
last_price: 10.0,
|
||||||
ask1_volume: 2_000,
|
bid1: 10.0,
|
||||||
trading_phase: Some("continuous".to_string()),
|
ask1: 10.0,
|
||||||
paused: false,
|
prev_close: 9.9,
|
||||||
upper_limit: 11.0,
|
volume: 1_000_000,
|
||||||
lower_limit: 9.0,
|
tick_volume: 10_000,
|
||||||
price_tick: 0.01,
|
bid1_volume: 2_000,
|
||||||
}],
|
ask1_volume: 2_000,
|
||||||
vec![DailyFactorSnapshot {
|
trading_phase: Some("continuous".to_string()),
|
||||||
date,
|
paused: false,
|
||||||
symbol: symbol.to_string(),
|
upper_limit: 11.0,
|
||||||
market_cap_bn: 10.0,
|
lower_limit: 9.0,
|
||||||
free_float_cap_bn: 10.0,
|
price_tick: 0.01,
|
||||||
pe_ttm: 8.0,
|
})
|
||||||
turnover_ratio: Some(1.0),
|
.collect(),
|
||||||
effective_turnover_ratio: Some(1.0),
|
[symbol, other_symbol]
|
||||||
extra_factors: BTreeMap::new(),
|
.into_iter()
|
||||||
}],
|
.map(|item| DailyFactorSnapshot {
|
||||||
vec![CandidateEligibility {
|
date,
|
||||||
date,
|
symbol: item.to_string(),
|
||||||
symbol: symbol.to_string(),
|
market_cap_bn: 10.0,
|
||||||
is_st: false,
|
free_float_cap_bn: 10.0,
|
||||||
is_new_listing: false,
|
pe_ttm: 8.0,
|
||||||
is_paused: false,
|
turnover_ratio: Some(1.0),
|
||||||
allow_buy: true,
|
effective_turnover_ratio: Some(1.0),
|
||||||
allow_sell: true,
|
extra_factors: BTreeMap::new(),
|
||||||
is_kcb: false,
|
})
|
||||||
is_one_yuan: false,
|
.collect(),
|
||||||
}],
|
[symbol, other_symbol]
|
||||||
|
.into_iter()
|
||||||
|
.map(|item| CandidateEligibility {
|
||||||
|
date,
|
||||||
|
symbol: item.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,
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
vec![BenchmarkSnapshot {
|
vec![BenchmarkSnapshot {
|
||||||
date,
|
date,
|
||||||
benchmark: "000852.SH".to_string(),
|
benchmark: "000852.SH".to_string(),
|
||||||
@@ -15208,6 +15221,20 @@ mod tests {
|
|||||||
prev_close: 998.0,
|
prev_close: 998.0,
|
||||||
volume: 1_000_000,
|
volume: 1_000_000,
|
||||||
}],
|
}],
|
||||||
|
Vec::new(),
|
||||||
|
vec![IntradayExecutionQuote {
|
||||||
|
date,
|
||||||
|
symbol: other_symbol.to_string(),
|
||||||
|
timestamp: date.and_hms_opt(10, 18, 0).unwrap(),
|
||||||
|
last_price: 10.0,
|
||||||
|
bid1: 10.0,
|
||||||
|
ask1: 10.0,
|
||||||
|
bid1_volume: 1_000,
|
||||||
|
ask1_volume: 1_000,
|
||||||
|
volume_delta: 100,
|
||||||
|
amount_delta: 1_000.0,
|
||||||
|
trading_phase: Some("continuous".to_string()),
|
||||||
|
}],
|
||||||
)
|
)
|
||||||
.expect("dataset");
|
.expect("dataset");
|
||||||
|
|
||||||
@@ -15236,6 +15263,7 @@ mod tests {
|
|||||||
let mut execution_state = super::ProjectedExecutionState::default();
|
let mut execution_state = super::ProjectedExecutionState::default();
|
||||||
|
|
||||||
assert!(ctx.data.execution_quotes_on(date, symbol).is_empty());
|
assert!(ctx.data.execution_quotes_on(date, symbol).is_empty());
|
||||||
|
assert!(!ctx.data.execution_quotes_on(date, other_symbol).is_empty());
|
||||||
let filled = strategy.project_order_value(
|
let filled = strategy.project_order_value(
|
||||||
&ctx,
|
&ctx,
|
||||||
&mut projected,
|
&mut projected,
|
||||||
|
|||||||
Reference in New Issue
Block a user