Skip to main content

wickra_backtest_core/
report.rs

1//! The backtest result: metrics, the trade log and the equity curve.
2
3use serde::Serialize;
4
5use crate::metrics::Metrics;
6use crate::portfolio::Trade;
7
8/// Current report schema version.
9pub const REPORT_SCHEMA_VERSION: u32 = 1;
10
11/// One point on the equity curve (marked at each bar close).
12#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
13pub struct EquityPoint {
14    /// Bar time.
15    pub time: i64,
16    /// Mark-to-market equity at the bar close.
17    pub equity: f64,
18}
19
20/// The result of a backtest run.
21#[derive(Debug, Clone, PartialEq, Serialize)]
22pub struct BacktestReport {
23    /// Report schema version.
24    pub schema_version: u32,
25    /// The instrument the spec was written for, echoed from it.
26    ///
27    /// The engine reads whatever candles it is given and does not check them
28    /// against this, so it is a label rather than a guarantee -- but without it a
29    /// stored report does not say what it is a report of, which makes a directory
30    /// of them unreadable.
31    pub symbol: String,
32    /// The bar size the spec was written for, echoed from it. A label, like
33    /// `symbol`.
34    pub timeframe: String,
35    /// Summary metrics.
36    pub metrics: Metrics,
37    /// Completed trades.
38    pub trades: Vec<Trade>,
39    /// Per-bar equity curve.
40    pub equity: Vec<EquityPoint>,
41    /// Total fees paid.
42    pub fees_paid: f64,
43    /// Starting capital.
44    pub initial_capital: f64,
45}