Module Algostream_montecarlo.Generator

How one Monte Carlo run gets its data.

A generator is a pure function of a generator spec and an Rng.t — that, plus Rng.substream ~root_seed ~index, is what makes run k reproducible independently of how many Domains ran the batch. Nothing here reads a clock or consults shared mutable state.

module Rng = Algostream_rng.Rng
module Data_source = Algostream_backtest.Data_source
type price_series = {
  1. symbol : string;
  2. s0 : float;
  3. start_ts_ns : int64;
  4. step_ns : int64;
  5. spread_bps : float;
  6. volume : float;
}
type t =
  1. | Historical of Data_source.record array
    (*

    the same data every run; only execution noise varies. The control against which every synthetic generator should be read

    *)
  2. | Iid_bootstrap of {
    1. returns : float array;
    2. series : price_series;
    }
  3. | Block_bootstrap of {
    1. returns : float array;
    2. block_len : int;
    3. series : price_series;
    }
  4. | Stationary_bootstrap of {
    1. returns : float array;
    2. mean_block_len : float;
    3. series : price_series;
    }
  5. | Record_bootstrap of {
    1. records : Data_source.record array;
    2. block_len : int;
    }
    (*

    resamples whole records, preserving whatever structure they carry, and rewrites timestamps onto a monotone grid

    *)
  6. | Gbm of {
    1. mu : float;
    2. sigma : float;
    3. dt : float;
    4. series : price_series;
    }
  7. | Garch_path of {
    1. model : Garch11.t;
    2. series : price_series;
    }
  8. | Ou_path of {
    1. params : Ornstein_uhlenbeck.params;
    2. dt : float;
    3. series : price_series;
    }
  9. | Jump_diffusion of {
    1. mu : float;
    2. sigma : float;
    3. lambda : float;
    4. jump_mu : float;
    5. jump_sigma : float;
    6. dt : float;
    7. series : price_series;
    }
  10. | Multivariate of {
    1. symbols : string array;
    2. s0 : float array;
    3. mu : float array;
    4. cov : float array array;
    5. dt : float;
    6. start_ts_ns : int64;
    7. step_ns : int64;
    8. spread_bps : float;
    9. volume : float;
    }
    (*

    Use this, not several independent single-asset generators, whenever the strategy trades a relationship. Independent paths contain no relationship, so a pairs strategy backtested against them has nothing to trade and the Monte Carlo reports a strategy that cannot possibly work.

    *)
  11. | Regime_switching of {
    1. spec : Regime_sim.spec;
    2. series : price_series;
    }
  12. | Stressed of {
    1. base : t;
    2. scenario : Stress.scenario;
    3. at_fraction : float;
    }
val default_series : symbol:string -> s0:float -> price_series
val build : t -> rng:Rng.t -> n_steps:int -> Data_source.t

Build one run's data. n_steps is ignored by Historical and Record_bootstrap, which are sized by their input.

val to_string : t -> string