fix: separate historical session capacity audits from execution sizing

This commit is contained in:
boris
2026-09-12 06:32:10 +08:00
parent 4edc70c4c6
commit 4d3a9e0e5b
6 changed files with 112 additions and 59 deletions
+14
View File
@@ -122,6 +122,7 @@ impl DailyEquityPoint {
#[derive(Debug, Clone)]
pub struct BacktestResult {
pub capacity_audit: crate::execution_capacity::CapacityAuditSummary,
pub strategy_name: String,
pub equity_curve: Vec<DailyEquityPoint>,
pub benchmark_series: Vec<BenchmarkSnapshot>,
@@ -280,6 +281,7 @@ pub struct AnalyzerRiskSummary {
#[derive(Debug, Clone, Serialize)]
pub struct AnalyzerReport {
pub capacity_audit: crate::execution_capacity::CapacityAuditSummary,
pub strategy_name: String,
pub trades: Vec<AnalyzerTradeRow>,
pub positions: Vec<AnalyzerPositionRow>,
@@ -294,6 +296,7 @@ pub struct AnalyzerReport {
impl BacktestResult {
pub fn analyzer_report(&self) -> AnalyzerReport {
AnalyzerReport {
capacity_audit: self.capacity_audit.clone(),
strategy_name: self.strategy_name.clone(),
trades: self
.fills
@@ -2102,6 +2105,7 @@ where
.map(|(execution_date, _)| *execution_date)
.collect::<Vec<_>>();
let mut result = BacktestResult {
capacity_audit: self.broker.capacity_audit_summary(),
strategy_name: self.strategy.name().to_string(),
benchmark_series: self
.data
@@ -3415,6 +3419,16 @@ where
execution_date,
);
let daily_fill_count = result.fills.len() - day_fill_start;
for audit in self.broker.audit_completed_session_capacity(execution_date, &self.data)? {
result.capacity_audit.observe(&audit);
// Keep every audit in the durable event store, independent of
// debug phase retention. It never changes earlier executions.
result.process_events.push(ProcessEvent {
date: execution_date, kind: ProcessEventKind::SessionCapacityAudit,
order_id: None, symbol: Some(audit.symbol.clone()), side: None,
detail: serde_json::to_string(&audit).map_err(|error| BacktestError::Execution(error.to_string()))?,
});
}
let daily_order_count = result.order_events.len() - day_order_start;
let execution_risk_decisions =
risk_decisions_from_order_events(&result.order_events[day_order_start..]);