Skip to main content

Crate yuzu_core

Crate yuzu_core 

Source
Expand description

Pure, I/O-free evaluator for strategy specs over (dates × symbols) data panels. A spec::Expr tree plus a data context evaluates to a boolean position matrix (panel::Panel) — the input the backtest loop consumes.

No network, no platform deps: f64 matrices in, Panel out. Compiles to both native and WASM. See docs/backtest-engine.md for the full overview.

Re-exports§

pub use eval::run_backtest;
pub use eval::run_strategy;
pub use eval::EvalContext;

Modules§

align
align reshapes two panels onto a shared index before an elementwise op: rows = union of dates (sorted), columns = intersection of symbols (left’s order). Absent cells become NaN (standard reshape/align semantics).
backtest
Daily-equity NAV loop: turns a position-weight matrix + price panel into an equity curve and a trade list. See docs/backtest-engine.md for the model.
bootstrap
Circular block bootstrap over daily returns: resample the return series in blocks (preserving short-range autocorrelation), rebuild synthetic equity curves, and report percentile confidence intervals for the headline metrics. Deterministic — a built-in SplitMix64 PRNG with a fixed seed, no external dependencies (WASM-safe).
error
EngineError: shape violations from panel construction and evaluation failures.
eval
Evaluates an Expr tree against a data context (HashMap<String, Panel>). run_strategy parses a JSON spec and evaluates it to a position matrix.
metrics
Standard performance metrics (CAGR, Sharpe, Sortino, max drawdown, etc.). All functions operate on a daily equity curve (&[f64], base 1.0) or a daily returns slice. Conventions: annualization 252, rf = 0, std ddof = 1.
ops
DSL operations, grouped by family. Each submodule adds impl Panel methods.
panel
The Panel type: a dense f64 matrix indexed by dates (rows, YYYYMMDD) and symbols (columns). NaN = missing; booleans are 1.0/0.0 with NaN falsy (see is_true).
report
Serializable backtest report — the JSON contract the web app renders (equity/drawdown series + trade list + metrics). Engine computes; frontend draws.
research
Factor diagnostics and event studies — research workflows that take panels and return JSON, deliberately kept out of the lemon AST (see issue #45). These are library entry points, not strategy ops: they don’t produce positions or change backtest NAV semantics.
spec
Expr: the serializable strategy AST. A JSON tree (tagged by "op") that the website and the batch runner both emit; the engine’s evaluator walks it against a data context to produce a position matrix.