移除回测兼容语义残留

This commit is contained in:
boris
2026-06-26 13:39:21 +08:00
parent 7f40cfdab0
commit 380c34aa66
15 changed files with 265 additions and 300 deletions
+22 -22
View File
@@ -170,7 +170,7 @@ pub struct BrokerSimulator<C, R> {
inactive_limit: bool,
liquidity_limit: bool,
strict_value_budget: bool,
aiquant_rqalpha_execution_rules: bool,
aiquant_execution_rules: bool,
same_day_buy_close_mark_at_fill: bool,
intraday_execution_start_time: Option<NaiveTime>,
runtime_intraday_start_time: Cell<Option<NaiveTime>>,
@@ -193,7 +193,7 @@ impl<C, R> BrokerSimulator<C, R> {
inactive_limit: true,
liquidity_limit: true,
strict_value_budget: false,
aiquant_rqalpha_execution_rules: false,
aiquant_execution_rules: false,
same_day_buy_close_mark_at_fill: false,
intraday_execution_start_time: None,
runtime_intraday_start_time: Cell::new(None),
@@ -220,7 +220,7 @@ impl<C, R> BrokerSimulator<C, R> {
inactive_limit: true,
liquidity_limit: true,
strict_value_budget: false,
aiquant_rqalpha_execution_rules: false,
aiquant_execution_rules: false,
same_day_buy_close_mark_at_fill: false,
intraday_execution_start_time: None,
runtime_intraday_start_time: Cell::new(None),
@@ -250,8 +250,8 @@ impl<C, R> BrokerSimulator<C, R> {
self
}
pub fn with_aiquant_rqalpha_execution_rules(mut self, enabled: bool) -> Self {
self.aiquant_rqalpha_execution_rules = enabled;
pub fn with_aiquant_execution_rules(mut self, enabled: bool) -> Self {
self.aiquant_execution_rules = enabled;
self
}
@@ -362,7 +362,7 @@ where
symbol: &str,
snapshot: &crate::data::DailyMarketSnapshot,
) -> f64 {
if self.aiquant_rqalpha_execution_rules && self.execution_price_field == PriceField::Last {
if self.aiquant_execution_rules && self.execution_price_field == PriceField::Last {
let start_cursor = self
.runtime_intraday_start_time
.get()
@@ -2088,7 +2088,7 @@ where
candidate: &crate::data::CandidateEligibility,
instrument: Option<&Instrument>,
) -> RuleCheck {
let check_price = if self.aiquant_rqalpha_execution_rules {
let check_price = if self.aiquant_execution_rules {
self.aiquant_limit_check_price(snapshot, OrderSide::Buy)
} else {
ChinaAShareRiskControl::buy_check_price(snapshot, self.execution_price_field)
@@ -2102,7 +2102,7 @@ where
) {
return RuleCheck::reject(reason);
}
if !self.aiquant_rqalpha_execution_rules {
if !self.aiquant_execution_rules {
return self
.rules
.can_buy(date, snapshot, candidate, self.execution_price_field);
@@ -2120,7 +2120,7 @@ where
instrument: Option<&Instrument>,
algo_request: Option<&AlgoExecutionRequest>,
) -> RuleCheck {
let check_price = if self.aiquant_rqalpha_execution_rules {
let check_price = if self.aiquant_execution_rules {
self.aiquant_order_limit_check_price(
date,
data,
@@ -2141,7 +2141,7 @@ where
) {
return RuleCheck::reject(reason);
}
if !self.aiquant_rqalpha_execution_rules {
if !self.aiquant_execution_rules {
return self
.rules
.can_buy(date, snapshot, candidate, self.execution_price_field);
@@ -2160,10 +2160,10 @@ where
position: &crate::portfolio::Position,
algo_request: Option<&AlgoExecutionRequest>,
) -> RuleCheck {
if !self.aiquant_rqalpha_execution_rules && !candidate.allow_sell {
if !self.aiquant_execution_rules && !candidate.allow_sell {
return RuleCheck::reject("sell_disabled");
}
let check_price = if self.aiquant_rqalpha_execution_rules {
let check_price = if self.aiquant_execution_rules {
self.aiquant_order_limit_check_price(
date,
data,
@@ -2185,7 +2185,7 @@ where
) {
return RuleCheck::reject(reason);
}
if !self.aiquant_rqalpha_execution_rules {
if !self.aiquant_execution_rules {
return self.rules.can_sell(
date,
snapshot,
@@ -2991,7 +2991,7 @@ where
return Ok(());
}
let current_value = if self.aiquant_rqalpha_execution_rules {
let current_value = if self.aiquant_execution_rules {
let valuation_price = self.target_value_valuation_price(date, data, symbol, snapshot);
valuation_price * current_qty as f64
} else {
@@ -4805,7 +4805,7 @@ where
return Ok(0);
}
if self.inactive_limit && snapshot.tick_volume == 0 {
if self.inactive_limit && snapshot.minute_volume == 0 {
return Err("minute no volume".to_string());
}
@@ -4832,7 +4832,7 @@ where
}
if self.volume_limit {
let raw_limit = ((snapshot.tick_volume as f64) * self.volume_percent).round() as i64
let raw_limit = ((snapshot.minute_volume as f64) * self.volume_percent).round() as i64
- consumed_turnover as i64;
if raw_limit <= 0 {
return Err("minute volume limit".to_string());
@@ -5418,7 +5418,7 @@ mod tests {
ask1: 10.0,
prev_close: 10.0,
volume: 1_000_000,
tick_volume: 10_000,
minute_volume: 10_000,
bid1_volume: 1_000,
ask1_volume: 1_000,
trading_phase: Some("continuous".to_string()),
@@ -5512,7 +5512,7 @@ mod tests {
}
#[test]
fn target_value_valuation_uses_daily_snapshot_but_value_order_sizing_uses_intraday_tick() {
fn target_value_valuation_uses_daily_snapshot_but_value_order_sizing_uses_intraday_minute() {
let date = chrono::NaiveDate::from_ymd_opt(2025, 1, 2).expect("valid date");
let broker = BrokerSimulator::new_with_execution_price(
ChinaAShareCostModel::default(),
@@ -5645,7 +5645,7 @@ mod tests {
.with_intraday_execution_start_time(date.and_hms_opt(10, 40, 0).unwrap().time())
.with_slippage_model(SlippageModel::PriceRatio(0.002))
.with_strict_value_budget(true)
.with_aiquant_rqalpha_execution_rules(true)
.with_aiquant_execution_rules(true)
.with_volume_limit(false)
.with_liquidity_limit(false)
.with_inactive_limit(false);
@@ -5663,7 +5663,7 @@ mod tests {
ask1: 5.83,
prev_close: 5.85,
volume: 1_000_000,
tick_volume: 262,
minute_volume: 262,
bid1_volume: 54,
ask1_volume: 143,
trading_phase: Some("continuous".to_string()),
@@ -6068,7 +6068,7 @@ mod tests {
ChinaEquityRuleHooks,
PriceField::Last,
)
.with_aiquant_rqalpha_execution_rules(true);
.with_aiquant_execution_rules(true);
let aiquant_rule = aiquant_broker.buy_rule_check(date, &snapshot, &candidate, None);
assert!(!aiquant_rule.allowed);
assert_eq!(aiquant_rule.reason.as_deref(), Some("buy_disabled"));
@@ -6131,7 +6131,7 @@ mod tests {
ChinaEquityRuleHooks,
PriceField::Last,
)
.with_aiquant_rqalpha_execution_rules(true)
.with_aiquant_execution_rules(true)
.with_intraday_execution_start_time(date.and_hms_opt(10, 18, 0).unwrap().time())
.with_volume_limit(false)
.with_liquidity_limit(false)