Skip to main content

Crate optionstratlib_simulation

Crate optionstratlib_simulation 

Source
Expand description

§optionstratlib-simulation

The simulation engine of OptionStratLib: random walks, stochastic processes, simulators, exit policies and the generic evaluation and statistics of simulated paths. It depends on optionstratlib-core and optionstratlib-pricing, and on no option chain, strategy, backtesting, plotting, I/O or terminal-presentation code.

Prices along a path are Positive, drifts and statistics Decimal; f64 stays inside the kernels, and a non-finite value at an f64 → Decimal boundary is reported as error::SimulationError::NonFinite.

The evaluation of a strategy over simulated paths, its statistics report and the charts of a walk stay with the backtesting and visualization layers, which the optionstratlib facade provides; the chain and series generators built on these walks are in optionstratlib-market, behind its synthetic feature.

§Imports

There is no prelude, as in the other component crates (ADR-0001 D7): the simulation module root re-exports the capability, and the optionstratlib facade prelude serves broad imports.

§Place in the workspace

  • Depends on optionstratlib-core and optionstratlib-pricing.
  • Must not depend on optionstratlib-market, -analytics, -strategies, -backtest and -visualization; make check-graph enforces the layering (ADR-0001 D9).
  • In the facade: optionstratlib::simulation and SimulationError / SimulationResult in optionstratlib::error, under the facade feature simulation. The facade paths are the same types as the paths here; the ownership map lists every one with its feature.

Moving from 0.21? The 0.22 architecture and adoption guide maps each redesign to its replacement workflow; 0.22 keeps no compatibility with 0.21.

§Minimal example

use optionstratlib_core::pos_or_panic;
use optionstratlib_simulation::simulation::generate_ou_process;

// An Ornstein-Uhlenbeck path of 50 steps mean-reverting to 100.
let path = generate_ou_process(
    pos_or_panic!(100.0),
    pos_or_panic!(100.0),
    pos_or_panic!(0.5),
    pos_or_panic!(0.2),
    pos_or_panic!(0.01),
    50,
)?;
assert_eq!(path.len(), 50);

§Runnable example

A runnable program that depends on this crate directly, with the smallest dependency set and no facade, is osl-example-direct-simulation; make tree-example-direct-simulation asserts its resolved graph.

§Features

  • schema (off by default): derives utoipa::ToSchema on the simulation types and enables schema in core and pricing.

Modules§

error
Errors raised by the simulation layer. Errors owned by the simulation layer.
simulation
Random walks, stochastic processes, simulators, exit policies and the generic evaluation of simulated paths.

Constants§

VERSION
Version of the optionstratlib-simulation crate.