Skip to main content

Dataset

Struct Dataset 

Source
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

Source

pub fn symbols(&self) -> Vec<String>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn close_at(&self, symbol: &str, t: usize) -> Option<f64>

Close for symbol at step t, or None if out of range.

Source

pub fn dividend_at(&self, symbol: &str, t: usize) -> f64

Per-share cash dividend paid by symbol at step t (0.0 if none).

Source

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.

Source

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.

Source

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.

Source

pub fn from_csv_file(path: &str) -> Result<Dataset, String>

Load a frozen dataset from a CSV file path. See Dataset::from_csv.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn stress_suite(seed: u64) -> Vec<(&'static str, Dataset)>

A named adversarial stress suite — each scenario tests survival, not calm-market return.

Source

pub fn masked(&self) -> Dataset

A contamination-masked copy: symbols renamed to opaque ids and dates replaced with plain indices, so an agent can’t pattern-match a memorized ticker or calendar window. Prices are preserved. (After KTD-Fin’s data-side masking.)

Trait Implementations§

Source§

impl Clone for Dataset

Source§

fn clone(&self) -> Dataset

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dataset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Dataset

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Dataset

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.