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.
simulation: the stochastic processes (simulation::WalkType: Brownian, geometric Brownian, log-returns, mean-reverting, jump diffusion, GARCH, Heston, telegraph, custom and historical) and their default kernels (simulation::WalkTypeAble); walk parameters and steps (simulation::WalkParams,simulation::steps::Step,simulation::steps::Xstep,simulation::steps::Ystep); the walk driver shared by every generator (simulation::walk_steps,simulation::walk_steps_par,simulation::generator_positive);simulation::randomwalk::RandomWalkandsimulation::simulator::Simulator; the Ornstein-Uhlenbeck process (simulation::generate_ou_process); exit policies (simulation::ExitPolicy,simulation::check_exit_policy); and the generic path evaluation (simulation::PathEvaluator,simulation::PathOutcome,simulation::PathStatistics,simulation::evaluate_paths).error:error::SimulationErroranderror::SimulationResult.
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-coreandoptionstratlib-pricing. - Must not depend on
optionstratlib-market,-analytics,-strategies,-backtestand-visualization;make check-graphenforces the layering (ADR-0001 D9). - In the facade:
optionstratlib::simulationandSimulationError/SimulationResultinoptionstratlib::error, under the facade featuresimulation. 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): derivesutoipa::ToSchemaon the simulation types and enablesschemain 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-simulationcrate.