Algostream_montecarlo.StressStress scenarios applied to a record stream.
The presets are stylized, not replays. black_monday_1987 applies a gap and a volatility multiplier of roughly the magnitude that day is remembered for; it is not a tick replay of 19 October 1987, and this system has no such data. Treat them as shaped what-ifs with round numbers, subject to the same two-significant-figure honesty the rest of the codebase claims.
When enough history exists, conditional is strictly preferable: it bootstraps from the worst windows the instrument actually experienced, so the magnitudes are empirical rather than invented. Reach for the presets when you need a shock more extreme than your sample contains.
module Rng = Algostream_rng.Rngmodule Data_source = Algostream_backtest.Data_sourcetype shock = | Price_pct of floatinstantaneous gap, e.g. -0.22
| Drift_pct_per_day of float| Vol_multiplier of floatscales deviations from the local mean
*)| Spread_multiplier of floatwidens the quoted spread
*)| Depth_multiplier of floatliquidity evaporation; thins synthetic book levels
*)| Halt of {}records suppressed; resting orders age through it
*)val black_monday_1987 : scenarioRound-number scenarios shaped after well-known episodes. Magnitudes are approximate by construction — see the header.
val ltcm_1998 : scenarioval lehman_2008 : scenarioval flash_crash_2010 : scenarioval covid_march_2020 : scenarioval luna_may_2022 : scenarioval ftx_nov_2022 : scenarioval all_presets : scenario arrayval find_preset : string -> scenario optionval apply :
scenario ->
records:Data_source.record array ->
Data_source.record arrayApply a scenario to a record stream. Timestamps are preserved except where a Halt suppresses records entirely.
val at_fraction :
scenario ->
records:Data_source.record array ->
fraction:float ->
scenarioRebase a scenario's onset to a fraction of the way through a record stream — so a preset written with absolute timestamps can be dropped into any sample.
val conditional :
rng:Rng.t ->
data:float array ->
worst_pct:float ->
block_len:int ->
n:int ->
float arrayBootstrap restricted to the worst worst_pct of historical windows of length block_len. Empirical stress with no invented magnitudes. Prefer this when the sample is long enough to contain the kind of event you want to stress against.
val scenario_to_string : scenario -> string