A comprehensive, educational, production-grade quantitative finance platform written in Rust.
Mission: Rationalize quantitative finance domain knowledge through idiomatic Rust, explicit design patterns, and rigorous testing.
- Philosophy
- Architecture
- Workspace Crates
- Design Patterns
- Quick Start
- Testing Strategy
- Docker / Podman
- Data Providers
- Educational Resources
- References
- Contributing
This project is built on three pillars:
- Education First: Every module explains the why behind the implementation. Design patterns are explicit, documented, and justified.
- Rust Idioms: Zero-cost abstractions, fearless concurrency, and type-safe domain modeling. If a pattern exists in another language but not Rust, we reimplement it as a first-class crate.
- Production Grade: Comprehensive testing (unit, integration, e2e, performance), Docker containerization, and observability from day one.
┌─────────────────────────────────────────────────────────────────────┐
│ ferrous-quant CLI / API │
├─────────────────────────────────────────────────────────────────────┤
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌───────────┐ │
│ │ Strategies │ │ Backtest │ │ Execution │ │ Risk │ │
│ │ Engine │ │ Engine │ │ Engine │ │ Engine │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └─────┬─────┘ │
│ │ │ │ │ │
│ ┌──────┴────────────────┴────────────────┴───────────────┘ │
│ │ quant-core (Domain Primitives) │
│ │ Symbol, Price, Quantity, OHLCV, TimeSeries, Currency, Tick │
│ └────────────────────────────────────────────────────────────────┘ │
│ │ │ │ │ │
│ ┌──────┴────────────────┴────────────────┴───────────────┘ │
│ │ quant-data (Data Providers) │
│ │ Yahoo Finance │ IBKR TWS │ FRED │ CSV │ Parquet │ In-Memory │
│ └────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ┌──────┴────────────────────────────────────────────────────────┐│
│ │ quant-indicators (Technical Analysis) ││
│ │ SMA, EMA, RSI, MACD, Bollinger Bands, ATR, VWAP, ... ││
│ └────────────────────────────────────────────────────────────────┘│
│ │ │
│ ┌──────┴────────────────────────────────────────────────────────┐│
│ │ quant-patterns (Design Patterns) ││
│ │ Builder, Strategy, Observer, Command, State, Pipeline, ││
│ │ Actor, Chain of Responsibility, Visitor, Repository ││
│ └────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────┘
| Crate | Purpose | Patterns Used |
|---|---|---|
quant-patterns |
Reusable design patterns for financial systems | Builder, Strategy, Observer, Command, State, Pipeline, Actor, Chain of Responsibility, Repository |
quant-core |
Domain primitives and type system | Newtype, Typestate, PhantomData, Zero-cost abstractions |
quant-indicators |
Technical analysis indicators | Iterator, Strategy, Builder |
quant-data |
Data ingestion abstractions and providers | Repository, Adapter, Factory |
quant-ibkr |
Interactive Brokers TWS API client | Builder, Command, Observer, State Machine |
quant-backtest |
Event-driven backtesting engine | Event Sourcing, Strategy, Observer, Pipeline |
quant-risk |
Risk metrics and portfolio analytics | Visitor, Strategy, Builder |
quant-execution |
Order execution and paper trading | Command, State, Chain of Responsibility |
quant-cli |
Command-line interface | Builder, Command |
quant-book |
Educational documentation and runnable examples | - |
We adopt and adapt classical design patterns for Rust's ownership and trait system. Each pattern is:
- Documented with financial domain rationale
- Implemented as a reusable generic crate component
- Tested with unit, integration, and property-based tests
- Benchmarked where performance matters
See docs/DESIGN_PATTERNS.md for the full catalog.
| Pattern | Financial Use Case | Rust Implementation |
|---|---|---|
| Builder | Order construction, strategy configuration | OrderBuilder, StrategyBuilder |
| Strategy | Trading algorithms, risk models | trait TradingStrategy |
| Observer | Market data subscriptions, event notifications | trait MarketDataObserver + channels |
| Command | Order commands, audit trail | trait OrderCommand + CommandBus |
| State | Order lifecycle (Pending → Filled → Cancelled) | enum OrderState + state transitions |
| Pipeline | Data ETL, indicator computation chains | struct Pipeline + trait Processor |
| Actor | Concurrent execution engines, market data handlers | trait Actor + tokio::sync::mpsc |
| Chain of Responsibility | Risk checks, order validation | trait RiskCheck + RiskCheckChain |
| Repository | Data access abstraction | trait DataRepository |
| Visitor | Portfolio analytics, risk aggregation | trait PortfolioVisitor |
| Newtype | Type-safe prices, quantities, currencies | struct Price(f64); struct Quantity(f64); |
| Typestate | Compile-time state validation | struct Order<State: OrderStateTrait> |
- Rust 1.85+ (
rustup update stable) - Docker or Podman
just(task runner) —cargo install just
git clone https://github.com/kevincouton/ferrous-quant.git
cd ferrous-quant
cargo build --workspace# Start the full stack
just podman-up
# Or individually
podman-compose up -d
# Run the CLI
podman run --rm -it ferrous-quant-cli:latest --help# All tests
cargo test --workspace
# With coverage
cargo llvm-cov --workspace --html
# Benchmarks
cargo bench --workspace
# E2E tests (requires IB Gateway paper account)
cargo test --workspace --features e2e| Level | Scope | Tools | Location |
|---|---|---|---|
| Unit | Individual functions, types | #[test] + proptest |
src/ inline |
| Integration | Module interactions, APIs | tests/ directories |
tests/integration/ |
| E2E | Full workflows, broker APIs | tests/e2e/ + Docker |
tests/e2e/ |
| Performance | Latency, throughput | criterion.rs |
benches/ |
| Property | Invariants, correctness | proptest |
Mixed |
| Fuzz | Edge cases, panics | cargo-fuzz |
fuzz/ |
See docs/TESTING.md for detailed testing philosophy and examples.
All services run in containers using Podman locally:
# Development stack
podman-compose -f compose.dev.yml up -d
# Services:
# - IB Gateway (paper trading)
# - PostgreSQL (audit trail)
# - ClickHouse (analytics)
# - Grafana (monitoring)
# - Redpanda (event streaming)See deploy/ for Kubernetes manifests and docs/DEPLOYMENT.md.
| Provider | Crate | Status | Notes |
|---|---|---|---|
| Yahoo Finance | quant-data |
✅ | Free, historical + real-time |
| Interactive Brokers | quant-ibkr |
✅ | TWS API, live + paper trading |
| FRED | quant-data |
🔄 | Macroeconomic data |
| CoinMetrics | quant-data |
🔄 | Crypto on-chain data |
| CSV / Parquet | quant-data |
✅ | Local file ingestion |
| In-Memory | quant-data |
✅ | Test fixtures, synthetic data |
The quant-book/ crate contains runnable examples and deep-dives:
quant-book/src/ch01_design_patterns.rs— Design Patterns in Financial Systemsquant-book/src/ch02_market_data.rs— Modeling Market Dataquant-book/src/ch03_technical_indicators.rs— Technical Indicator Implementationsquant-book/src/ch04_backtesting.rs— Event-Driven Backtestingquant-book/src/ch05_risk_management.rs— Risk Metrics and Portfolio Theoryquant-book/src/ch06_ibkr_integration.rs— Connecting to Interactive Brokers
Each chapter is a standalone binary you can run:
cargo run --bin ch01_design_patternsThis project draws inspiration from the quant community:
- awesome-quant by Wilson Freitas — comprehensive library catalog
- awesome-quant-ai by leoncuhk — AI/ML in quant finance
- NautilusTrader — high-performance event-driven trading platform
- RustQuant — quantitative finance library in Rust
- Barter — Rust trading framework
Key texts informing the architecture:
- Advances in Financial Machine Learning by Marcos Lopez de Prado
- Systematic Trading by Robert Carver
- Algorithmic Trading by Ernest Chan
- Building Reliable Trading Systems by Keith Fitschen
Contributions are welcome. Please read CONTRIBUTING.md for guidelines.
All code must pass:
cargo clippy --workspace --all-targets --all-features -- -D warningscargo fmt --all -- --checkcargo test --workspacecargo doc --workspace --no-deps
Dual-licensed under MIT or Apache-2.0.
Built with 🦀 Rust for quantitative finance