Skip to main content

SimulationReport

Trait SimulationReport 

Source
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 SimulationStatsResult summary, every P&L figure but the standard deviation is green when positive and red when negative;
  • in the SimulationStats summary, 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§

Source

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).

Source

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.

Source

fn render_individual_results(&self) -> String

The per-run table as plain text, without ANSI escapes.

Source

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".

Implementations on Foreign Types§

Source§

impl SimulationReport for SimulationStats

Source§

impl SimulationReport for SimulationStatsResult

Implementors§