pub struct Dataset {
pub dates: Vec<String>,
pub closes: BTreeMap<String, Vec<f64>>,
pub dividends: BTreeMap<String, Vec<f64>>,
}Expand description
A point-in-time price dataset.
Fields§
§dates: Vec<String>§closes: BTreeMap<String, Vec<f64>>symbol → closes, each Vec aligned to dates.
dividends: BTreeMap<String, Vec<f64>>symbol → per-share cash dividend paid at each step, aligned to dates.
Empty (the default) means no corporate actions. Stock splits need no entry
here: on a split-adjusted close series they are price-neutral by
construction, so only the cash dividend stream changes total return.
Implementations§
Source§impl Dataset
impl Dataset
pub fn symbols(&self) -> Vec<String>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn close_at(&self, symbol: &str, t: usize) -> Option<f64>
pub fn close_at(&self, symbol: &str, t: usize) -> Option<f64>
Close for symbol at step t, or None if out of range.
Sourcepub fn dividend_at(&self, symbol: &str, t: usize) -> f64
pub fn dividend_at(&self, symbol: &str, t: usize) -> f64
Per-share cash dividend paid by symbol at step t (0.0 if none).
Sourcepub fn with_dividend_yield(self, per_period_yield: f64) -> Self
pub fn with_dividend_yield(self, per_period_yield: f64) -> Self
Attach a constant dividend yield: every symbol pays per_period_yield of
its close as a cash dividend each step (e.g. an annual 4% yield on daily
bars ≈ 0.04 / 252). Models the cash-flow half of corporate actions.
Sourcepub fn history(&self, symbol: &str, t: usize, lookback: usize) -> Vec<f64>
pub fn history(&self, symbol: &str, t: usize, lookback: usize) -> Vec<f64>
Trailing closes ending at step t (inclusive), at most lookback long.
Point-in-time: never includes a bar after t.
Sourcepub fn from_csv(text: &str) -> Result<Dataset, String>
pub fn from_csv(text: &str) -> Result<Dataset, String>
Load a frozen dataset from long-format CSV (date,symbol,close[,dividend],
header required). The series are aligned on the intersection of every
symbol’s dates, so close_at(sym, t) lines up across symbols; ISO
YYYY-MM-DD dates sort chronologically. Pure — no network. The benchmark
only ever reads frozen data (offline fetchers live in the xtask crate),
which is what keeps a score reproducible forever.
Sourcepub fn from_csv_file(path: &str) -> Result<Dataset, String>
pub fn from_csv_file(path: &str) -> Result<Dataset, String>
Load a frozen dataset from a CSV file path. See Dataset::from_csv.
Sourcepub fn synthetic(n_symbols: usize, n_days: usize, seed: u64) -> Dataset
pub fn synthetic(n_symbols: usize, n_days: usize, seed: u64) -> Dataset
Build a deterministic synthetic dataset with mild momentum
autocorrelation — enough to make the reference agents behave differently.
Pure function of seed (no ambient RNG). Thin wrapper over
Dataset::synthetic_parameterized at the calm-market parameters
(unit vol, no jumps) — byte-identical to the standalone generator it
replaced (pinned by synthetic_is_byte_identical_golden).
Sourcepub fn synthetic_parameterized(
n_symbols: usize,
n_days: usize,
seed: u64,
vol_mult: f64,
jump_prob: f64,
jump_size: f64,
) -> Dataset
pub fn synthetic_parameterized( n_symbols: usize, n_days: usize, seed: u64, vol_mult: f64, jump_prob: f64, jump_size: f64, ) -> Dataset
The continuous-vol / jump-diffusion generalization of Dataset::synthetic:
the same drift + AR(1)-momentum path, with each bar’s Gaussian-ish shock
scaled by vol_mult and seeded bounded-uniform jumps of magnitude
jump_size injected with per-bar probability jump_prob (a fat-tail stress
knob). Pure function of seed; only mul/add/div/max (no ln/exp), so the
path is byte-identical across Rust/WASM/Python.
Determinism note: the jump draws are taken only when jump_prob > 0, so
the no-jump call consumes the RNG identically to the original synthetic
(one draw per bar) — vol_mult = 1.0, jump_prob = 0.0 reproduces it exactly.
Prices are kept strictly positive by flooring the per-bar growth factor.
Sourcepub fn flash_crash(
n_symbols: usize,
n_days: usize,
crash_day: usize,
crash_pct: f64,
seed: u64,
) -> Dataset
pub fn flash_crash( n_symbols: usize, n_days: usize, crash_day: usize, crash_pct: f64, seed: u64, ) -> Dataset
Adversarial path: a synthetic series with a sudden one-day flash crash
of crash_pct at crash_day that does not fully recover — a tail-stress
scenario that should blow up agents with no risk discipline.
Sourcepub fn whipsaw(
n_symbols: usize,
n_days: usize,
amplitude: f64,
seed: u64,
) -> Dataset
pub fn whipsaw( n_symbols: usize, n_days: usize, amplitude: f64, seed: u64, ) -> Dataset
Whipsaw regime: sharp alternating up/down moves with no drift. Trend and momentum agents get chopped up by transaction costs.