pub trait SimulationReport {
// Required methods
fn render_summary(&self) -> Result<String, GraphError>;
fn print_summary(&self) -> Result<(), GraphError>;
fn render_individual_results(&self) -> String;
fn print_individual_results(&self) -> Result<(), GraphError>;
}Expand description
Terminal tables for simulation statistics.
Implemented for
SimulationStatsResult,
the statistics a Simulate::simulate run returns, and for
SimulationStats,
the running accumulator. The summary shows the run count, the trade
outcomes, the P&L figures, the average holding period and the exit
reasons; the individual results show one row per run. Money is written
with a $ sign and Decimal’s {:.2}, which truncates to two decimal
places (as the tables always have). The average holding period of a
SimulationStats summary is rounded half-up to two decimal places
(#691); a SimulationStatsResult summary writes its own with {:.2}.
Exit reasons are listed in the order of their text, so the output is
deterministic.
In colour, headers are blue, and:
- in the
SimulationStatsResultsummary, every P&L figure but the standard deviation is green when positive and red when negative; - in the
SimulationStatssummary, the profitable-close count and share and the maximum profit are always green, the loss-close count and share and the maximum loss always red, and the total and average P&L uncoloured; - in the individual results of both, the final P&L is green when positive and red when negative.
The P&L of a run is its total P&L (realized plus unrealized,
PnL::total_pnl) for both types, the figure each accumulates (#691).
The SimulationStats summary takes its average P&L, extremes and
average holding period from SimulationStats::statistics, so a run
without a P&L counts as zero there, as in the SimulationStatsResult
summary.
This replaces the inherent print_summary and print_individual_results
methods those types had: import the trait and call the same names, now
returning a Result.
Required Methods§
Sourcefn render_summary(&self) -> Result<String, GraphError>
fn render_summary(&self) -> Result<String, GraphError>
The summary tables as plain text, without ANSI escapes.
§Errors
Returns GraphError::Decimal when a derived figure (the total or
the average P&L) leaves the representable Decimal range, and
GraphError::Backtest when the statistics of a SimulationStats
accumulator cannot be computed (its P&L total or variance leaves the
Decimal range).
Sourcefn print_summary(&self) -> Result<(), GraphError>
fn print_summary(&self) -> Result<(), GraphError>
Writes the summary tables to stdout, coloured when stdout is a terminal.
§Errors
Returns the errors of Self::render_summary, and
GraphError::Io when stdout cannot be written.
Sourcefn render_individual_results(&self) -> String
fn render_individual_results(&self) -> String
The per-run table as plain text, without ANSI escapes.
Sourcefn print_individual_results(&self) -> Result<(), GraphError>
fn print_individual_results(&self) -> Result<(), GraphError>
Writes the per-run table to stdout, coloured when stdout is a terminal.
§Errors
Returns GraphError::Io when stdout cannot be written.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".