修正AiQuant盘中组合估值口径
This commit is contained in:
@@ -939,8 +939,8 @@ impl PlatformExprStrategy {
|
||||
continue;
|
||||
}
|
||||
let mark_price = if self.config.aiquant_transaction_cost {
|
||||
ctx.data
|
||||
.price(date, &position.symbol, PriceField::Last)
|
||||
self.aiquant_scheduled_last_price(ctx, date, &position.symbol)
|
||||
.or_else(|| ctx.data.price(date, &position.symbol, PriceField::Last))
|
||||
.or_else(|| {
|
||||
ctx.data
|
||||
.price_on_or_before(date, &position.symbol, PriceField::Last)
|
||||
@@ -7332,6 +7332,118 @@ mod tests {
|
||||
assert!((marked - 1_293.0).abs() < 1e-6, "{marked}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn platform_aiquant_marked_total_value_uses_scheduled_quote() {
|
||||
let prev_date = d(2025, 6, 20);
|
||||
let date = d(2025, 6, 23);
|
||||
let symbol = "605303.SH";
|
||||
let data = DataSet::from_components_with_actions_and_quotes(
|
||||
vec![Instrument {
|
||||
symbol: symbol.to_string(),
|
||||
name: symbol.to_string(),
|
||||
board: "SH".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-06-23 15:00:00".to_string()),
|
||||
day_open: 11.50,
|
||||
open: 11.50,
|
||||
high: 12.20,
|
||||
low: 11.40,
|
||||
close: 12.00,
|
||||
last_price: 12.00,
|
||||
bid1: 12.00,
|
||||
ask1: 12.00,
|
||||
prev_close: 11.40,
|
||||
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: 12.54,
|
||||
lower_limit: 10.26,
|
||||
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,
|
||||
}],
|
||||
Vec::new(),
|
||||
vec![IntradayExecutionQuote {
|
||||
date,
|
||||
symbol: symbol.to_string(),
|
||||
timestamp: date.and_hms_opt(10, 39, 59).unwrap(),
|
||||
last_price: 11.50,
|
||||
bid1: 11.49,
|
||||
ask1: 11.50,
|
||||
bid1_volume: 2_000,
|
||||
ask1_volume: 2_000,
|
||||
volume_delta: 10_000,
|
||||
amount_delta: 115_000.0,
|
||||
trading_phase: Some("continuous".to_string()),
|
||||
}],
|
||||
)
|
||||
.expect("dataset");
|
||||
let mut portfolio = PortfolioState::new(100.0);
|
||||
portfolio.position_mut(symbol).buy(prev_date, 100, 10.00);
|
||||
let subscriptions = BTreeSet::new();
|
||||
let ctx = StrategyContext {
|
||||
execution_date: date,
|
||||
decision_date: date,
|
||||
decision_index: 0,
|
||||
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;
|
||||
cfg.intraday_execution_time = Some(NaiveTime::from_hms_opt(10, 40, 0).unwrap());
|
||||
let strategy = PlatformExprStrategy::new(cfg);
|
||||
|
||||
let marked = strategy.marked_total_value(&ctx, date);
|
||||
|
||||
assert!((marked - 1_250.0).abs() < 1e-6, "{marked}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn platform_take_profit_false_does_not_track_upper_limit_pending_sell() {
|
||||
let prev_date = d(2025, 2, 6);
|
||||
@@ -9492,7 +9604,7 @@ mod tests {
|
||||
);
|
||||
assert!(matches!(
|
||||
decision.order_intents.first(),
|
||||
Some(OrderIntent::Value { symbol, .. }) if symbol == fallback_symbol
|
||||
Some(OrderIntent::Shares { symbol, quantity, .. }) if symbol == fallback_symbol && *quantity > 0
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user