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 strict timestamped
RawSignalvalues; 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 with P&L, drawdown, and execution artifacts |
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::CostEvent;pub use artifacts::ExecutionMetadata;pub use artifacts::FutureBacktestArtifacts;pub use artifacts::InstrumentSizingArtifact;pub use artifacts::MarketEntrySizingAudit;pub use artifacts::MarketEntrySizingBasis;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::ReplayInstrumentArtifact;pub use artifacts::ReplayInstrumentManifest;pub use artifacts::RiskBasisStatus;pub use artifacts::RiskTranche;pub use data_feed::BarExecutionPrices;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::guarded_instrument_spec;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::EntryProfileRoutingError;pub use profile::PreparedEntryProfiles;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::AnalysisBoundary;pub use strategy::AnalysisBoundaryOutput;pub use strategy::AnalysisContext;pub use strategy::AnalysisError;pub use strategy::AnalysisPipeline;pub use strategy::AnnotationError;pub use strategy::AnnotationId;pub use strategy::AnnotationLimits;pub use strategy::AnnotationTimeline;pub use strategy::AnnotationUse;pub use strategy::BacktestConfiguredStrategyAdapter;pub use strategy::BarSeriesSpec;pub use strategy::BarWindow;pub use strategy::CalendarAdmissionLimits;pub use strategy::CalendarBar;pub use strategy::CalendarError;pub use strategy::CalendarFeatureKind;pub use strategy::CalendarFeatureProjector;pub use strategy::CalendarInputSpec;pub use strategy::CalendarTimeBasis;pub use strategy::ClosedBar;pub use strategy::ConfiguredCalendarFeatureProjector;pub use strategy::ConfiguredCalendarInput;pub use strategy::ConfiguredEntryProfileError;pub use strategy::ConfiguredHistoricalBindings;pub use strategy::ConfiguredNamedInputBinding;pub use strategy::ConfiguredSourceBinding;pub use strategy::ConfiguredStrategyAdapterBuildError;pub use strategy::ConfiguredStrategyAdapterError;pub use strategy::ConfiguredStrategyAdapterPreflightError;pub use strategy::ConfiguredTradingCalendar;pub use strategy::ConfirmedPivotAnalyzer;pub use strategy::ConfirmedSwingFactKind;pub use strategy::ConfirmedSwingFactProjector;pub use strategy::DEFAULT_CALENDAR_SESSION_ID;pub use strategy::FixedUtcSessionError;pub use strategy::FixedUtcSessionProjector;pub use strategy::HistoricalAnalyzer;pub use strategy::HistoricalNamedInputProjector;pub use strategy::HistoricalObservationView;pub use strategy::HistoricalSeriesView;pub use strategy::HistoricalStrategy;pub use strategy::HistoricalVolumeProjection;pub use strategy::IanaTradingCalendar;pub use strategy::JournalKind;pub use strategy::LocalMarketIntervalSpec;pub use strategy::MAX_ANALYZERS;pub use strategy::MAX_ANNOTATION_ID_BYTES;pub use strategy::MAX_ANNOTATION_NOTE_BYTES;pub use strategy::MAX_ANNOTATIONS;pub use strategy::MAX_CHART_REF_BYTES;pub use strategy::MAX_DECISION_LATENCY_MS;pub use strategy::MAX_DECISION_RECORDS;pub use strategy::MAX_EXPERIMENT_LABEL_BYTES;pub use strategy::MAX_INSTRUMENT_BYTES;pub use strategy::MAX_JOURNAL_PER_CALLBACK;pub use strategy::MAX_JOURNAL_REASON_BYTES;pub use strategy::MAX_JOURNAL_RECORDS;pub use strategy::MAX_JOURNAL_VALUE_KEY_BYTES;pub use strategy::MAX_JOURNAL_VALUES;pub use strategy::MAX_OBSERVATION_SOURCE_SERIES;pub use strategy::MAX_OBSERVATIONS_PER_BOUNDARY;pub use strategy::MAX_PIVOT_SIDE_BARS;pub use strategy::MAX_REASON_BYTES;pub use strategy::MAX_RETAINED_BARS;pub use strategy::MAX_RETAINED_OBSERVATIONS;pub use strategy::MAX_SERIES_ID_BYTES;pub use strategy::MAX_SESSION_WINDOWS;pub use strategy::MAX_SIGNALS_PER_CALLBACK;pub use strategy::MAX_STRATEGY_ID_BYTES;pub use strategy::MAX_STRATEGY_REVISION_BYTES;pub use strategy::MAX_STRATEGY_TITLE_BYTES;pub use strategy::MAX_TRADE_ID_BYTES;pub use strategy::MAX_WARMUP_BARS;pub use strategy::MAX_ZONE_ID_BYTES;pub use strategy::MarketScheduleSpec;pub use strategy::MissingIntervalPolicy;pub use strategy::MomentumState;pub use strategy::MultiTimeframeSeries;pub use strategy::NamedInputProjectionContext;pub use strategy::NamedInputProjectionError;pub use strategy::NamedSessionSpec;pub use strategy::ObservationOrigin;pub use strategy::ObservationSelection;pub use strategy::ObservationStore;pub use strategy::ObservationStoreLimits;pub use strategy::ObservationWindow;pub use strategy::OpeningRange;pub use strategy::PivotConfig;pub use strategy::PriceBasis;pub use strategy::PriceZone;pub use strategy::ProjectedNamedInput;pub use strategy::RejectionPattern;pub use strategy::ResolvedSession;pub use strategy::ResolvedSessionOccurrence;pub use strategy::ResolvedTradingDay;pub use strategy::SeriesError;pub use strategy::SeriesGeometry;pub use strategy::SeriesGeometryError;pub use strategy::SeriesId;pub use strategy::SeriesRequirement;pub use strategy::SeriesViewError;pub use strategy::SeriesWarmupState;pub use strategy::SessionOccurrenceId;pub use strategy::SessionScheduleSpec;pub use strategy::SessionSpanSpec;pub use strategy::SourceBarFactKind;pub use strategy::SourceBarFactProjector;pub use strategy::Strategy;pub use strategy::StrategyAnnotation;pub use strategy::StrategyBacktestResult;pub use strategy::StrategyComparisonMetrics;pub use strategy::StrategyComparisonSnapshot;pub use strategy::StrategyConfigError;pub use strategy::StrategyContext;pub use strategy::StrategyDecisionDraft;pub use strategy::StrategyDecisionKind;pub use strategy::StrategyDecisionOutput;pub use strategy::StrategyDecisionRecord;pub use strategy::StrategyDecisionRecorder;pub use strategy::StrategyDecisionRetention;pub use strategy::StrategyDescriptor;pub use strategy::StrategyDomainError;pub use strategy::StrategyEvent;pub use strategy::StrategyExperimentComparison;pub use strategy::StrategyExperimentError;pub use strategy::StrategyFeedback;pub use strategy::StrategyFeedbackEvent;pub use strategy::StrategyId;pub use strategy::StrategyJournalDraft;pub use strategy::StrategyJournalError;pub use strategy::StrategyJournalOutput;pub use strategy::StrategyJournalRecord;pub use strategy::StrategyJournalRecorder;pub use strategy::StrategyJournalRetention;pub use strategy::StrategyObservation;pub use strategy::StrategyObservationDraft;pub use strategy::StrategyObservationValue;pub use strategy::StrategyOutput;pub use strategy::StrategyReplayError;pub use strategy::StrategyReplayInputError;pub use strategy::StrategyRequirements;pub use strategy::StrategyResearchLimits;pub use strategy::StrategyResearchOutput;pub use strategy::StrategyRetentionLimits;pub use strategy::StrategyRuntimeError;pub use strategy::SwingKind;pub use strategy::SwingPoint;pub use strategy::Timeframe;pub use strategy::TradingCalendarSpec;pub use strategy::WarmupRequirement;pub use strategy::WeeklyMarketIntervalSpec;pub use strategy::ZoneId;pub use strategy::ZoneSide;pub use strategy::ZoneSource;pub use strategy::ZoneState;pub use strategy::ConfiguredInstance;pub use strategy::DirectPortfolioInstance;pub use strategy::INSTANCE_POSITION_TAG;pub use strategy::MAX_PORTFOLIO_INSTANCES;pub use strategy::MixedPortfolioBacktestResult;pub use strategy::MixedPortfolioReplayError;pub use strategy::PortfolioBacktestResult;pub use strategy::PortfolioInstanceOutput;pub use strategy::PortfolioReplayError;pub use strategy::SupervisorEvent;pub use strategy::SupervisorHaltAction;pub use strategy::SupervisorOutput;
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
- Historical strategy contracts and the legacy action-producing strategy trait.
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.
- Cost
Charge - One computed signed charge before any account conversion.
- Entry
Level Resolution - Auditable requested and resolved profile levels.
- Entry
Resolution Context - Instrument-aware context for profile-generated price levels.
- FxPair
- One available FX symbol and its registered currencies.
- Generated
Target Resolution - Metadata for one generated target.
- Instrument
Costs - Complete cost specification for one instrument.
- 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.
- Swap
Schedule - Nightly swap magnitude plus the rollover calendar that charges it.
- Target
Resolution - Metadata describing how signal targets were selected and weighted.
Enums§
- Commission
Model - How commission is charged for one instrument.
- 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.
- Cost
Basis - Which currency a computed charge is denominated in.
- Cost
Kind - What produced one charge.
- Cost
Validation Error - Configuration failures detected before a run starts.
- Entry
Geometry Policy - Directional geometry policy for signal stoploss and targets resolved against the execution price.
- 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).
- Price
Grid Source - Origin of the price grid supplied by the replay adapter.
- 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.
- Swap
Amount - Nightly swap magnitude for one instrument, in broker sign convention where negative charges and positive credits.
- Target
Resolution Source - Source recorded for resolved target metadata.
- Target
Selection - Which 1-based target indices participate in strict target resolution.
- Target
Source - Source used to produce initial targets.
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.