Expand description
qs-backtest — Backtesting engine for the quant-system workspace.
This crate provides tools for replaying historical market data through the
qs_core::TradeEngine to evaluate trading strategies and predefined
signal sets.
§Two modes of operation
- Strategy-driven — implement the
Strategytrait; the runner feeds market data tick-by-tick and your strategy decides when to act. - Signal replay — provide a
Vec<Signal>with timestamps; the runner injects them at the correct moments while replaying price data.
§Key types
| Type | Purpose |
|---|---|
BacktestRunner | Orchestrates the backtest loop (both modes) |
BacktestExecutor | Tracks simulated fills, positions, and P&L |
BacktestResult | Final report — P&L, win rate, drawdown, trade log |
DataFeed | Trait for sequential market event sources |
Strategy | Trait for strategy-driven backtests |
Re-exports§
pub use artifacts::CloseEvent;pub use artifacts::CompletedPosition;pub use artifacts::ExecutionMetadata;pub use artifacts::FutureBacktestArtifacts;pub use artifacts::NetPnlOutcome;pub use artifacts::OpenPositionSnapshot;pub use artifacts::PendingOrderLifecycleEvent;pub use artifacts::PendingOrderLifecycleState;pub use artifacts::PendingOrderSnapshot;pub use artifacts::RecordedFill;pub use artifacts::RiskBasisStatus;pub use artifacts::RiskTranche;pub use data_feed::DataFeed;pub use data_feed::MarketEvent;pub use data_feed::VecFeed;pub use economic_support::EconomicSupportError;pub use economic_support::LEGACY_ECONOMIC_GUARD_ID;pub use economic_support::LegacyEconomicModel;pub use economic_support::SupportedLegacyEconomics;pub use economic_support::resolve_legacy_economics;pub use evaluation::BootstrapConfig;pub use evaluation::BreakdownDimension;pub use evaluation::EvaluationContext;pub use evaluation::EvaluationOptions;pub use evaluation::EvaluationReport;pub use evaluation::EvaluationSection;pub use evaluation::GroupFilter;pub use evaluation::PositionFilter;pub use evaluation::PositionSide;pub use executor::BacktestExecutor;pub use future_executor::FutureExecutor;pub use mtm::DEFAULT_MTM_MAX_POINTS;pub use mtm::MAX_MTM_MAX_POINTS;pub use mtm::MIN_MTM_MAX_POINTS;pub use mtm::MtmCurveCollector;pub use mtm::MtmOutputPolicy;pub use mtm::MtmOutputPolicyError;pub use mtm::MtmOutputSummary;pub use profile::ProfileError;pub use profile::ProfileRegistry;pub use profile::ProfileRegistryError;pub use report::BacktestResult;pub use report::CloseReasonStats;pub use report::DurationStats;pub use report::MonthlyReturn;pub use report::PositionSummary;pub use report::RiskMetrics;pub use report::StreakStats;pub use report::SubsetStats;pub use report::TradeResult;pub use runner::BacktestRunner;pub use runner::FutureQuoteConfig;pub use runner::ReplayCancelled;pub use runner::ReplayProgress;pub use runner::StreamingReplayError;pub use strategy::Strategy;
Modules§
- artifacts
- Additive, serializable artifacts for future backtest runners.
- currency
- Compatibility re-exports for currency-conversion domain types moved to
qs-core. - data_
feed - Data feed abstraction for backtesting.
- economic_
support - Fail-closed capability checks for the legacy backtest economic model.
- evaluation
- Additive, report-independent provider evaluation.
- executor
- Backtest executor — simulates fills and tracks P&L.
- future_
executor - Fill-authoritative accounting for the FutureQuoteV1 replay path.
- ledger
- Terminal action lifecycle accounting.
- mtm
- Deterministic mark-to-market output collection.
- portfolio
- Quote-aware portfolio snapshots and online account accounting.
- profile
- Backtest compatibility surface and configuration loader for core management profiles.
- report
- Backtest reporting — trade log, aggregate statistics, and enhanced analytics.
- runner
- Backtest runner — orchestrates the backtest loop.
- sizing
- Compatibility re-exports for position-sizing domain types moved to
qs-core. - strategy
- Strategy trait for strategy-driven backtests.
Structs§
- Conversion
Leg - One directed currency-conversion leg.
- Conversion
LegAudit - Auditable execution details for one route leg.
- Conversion
Quote Book - Historical FX tick store with causal, staleness-bounded lookup.
- Conversion
Result - Result of one identity, direct, inverse, or two-leg conversion.
- FxPair
- One available FX symbol and its registered currencies.
- Management
Profile - A named management profile that resolves raw entry signals before sizing.
- Resolved
Entry - A resolved entry that retains risk intent without assigning concrete lots.
- RunCurrency
Plan - Immutable, validated currency handoff for one backtest run.
- Target
Resolution - Metadata describing how signal targets were selected and weighted.
Enums§
- Conversion
Error - Errors produced by route resolution and quote-backed conversion.
- Conversion
Price Side - Quote side used to execute one signed conversion leg.
- Conversion
Route - Deterministic route selected from a caller-provided available-symbol set.
- FxPair
Direction - Direction in which an FX pair is used for a conversion leg.
- Position
Ref - How a management signal references its target position(s).
- Profile
Application Error - Strict validation failures returned by the canonical entry resolvers.
- Profile
Validation Error - Errors returned while validating a management profile definition.
- Quote
Validation Error - Validation failure for a tick quote submitted to the quote book.
- RawSignal
- A raw signal from an external source — entry or management.
- Rule
Config Def - Profile-specific rule definition with
#[serde(tag = "type")]for TOML. - RunCurrency
Plan Error - Validation errors for an immutable run currency plan.
- Stoploss
Mode - How the profile handles the stoploss from the raw signal.
- Target
Selection - Which 1-based target indices participate in strict target resolution.
Traits§
- Position
Resolver - Resolves a
PositionRefto concrete position ID(s) using engine state.
Functions§
- allocate_
target_ units - Convert an aligned floating lot size to steps and delegate to
allocate_target_steps. - resolve_
conversion_ route - Resolve an identity, direct, inverse, or deterministic two-leg FX route.
- resolve_
fx_ pair - Resolve one directed FX pair from the available-symbol set.
- resolve_
signal - Resolve a non-entry
RawSignalinto concreteAction(s). - resolve_
unprofiled_ entry - Strictly resolve an entry without a management profile.