Quantitative Trading Platform

python-trading integrates OpenBB data ingestion, RRG/Dow signal research, Black-Litterman allocation, VectorBT walk-forward backtests, and Alpaca-ready execution controls. Built as a test-driven Python system, it emphasizes deterministic workflows, measurable risk controls, and reproducible strategy validation from data quality gates to portfolio action.

Overview

python-trading is a personal research project applying machine learning and quantitative methods to financial markets. It is an operational quantitative trading platform focused on process quality and reproducibility.

Its architecture is organized into dedicated services for data ingestion, signal generation, portfolio optimization, backtesting, execution, and risk controls. The platform uses OpenBB as the provider abstraction layer, computes relative-strength and market-regime signals, maps those signals into Black-Litterman views, and validates portfolio logic through vectorized walk-forward simulation. Operational quality is enforced through automated tests, linting, and type checks, with environment routing that defaults to paper mode before any production promotion. The result is a disciplined engineering workflow for strategy development and execution readiness, rather than opaque discretionary trading.

System Architecture

cloud_download

Market Data

OpenBB provider abstraction with configurable dev/paper/prod routing, Parquet-backed caching, and data quality gates that validate completeness before downstream consumption.

ssid_chart

Signal Generation

RS-Ratio and RS-Momentum computation with quadrant transitions and Dow Theory regime filtering. Explicit signal contracts between research and allocation layers.

pie_chart

Portfolio Optimization

Black-Litterman model with view mapping (P, Q, Omega matrices) and constraint-aware allocation. Converts signal confidence into position sizes through a principled Bayesian framework.

history

Backtesting

VectorBT-powered walk-forward simulation with strategy comparison. Reports Sharpe, Sortino, Calmar ratios, drawdown analysis, and turnover impact before promotion.

swap_horiz

Execution

Alpaca integration with paper/live routing and full order lifecycle management. Environment-aware configuration defaults to paper mode for safe iteration.

shield

Risk Controls

Circuit breakers, exposure guards, and risk-first defaults. Production execution is gated behind stable paper-trading behavior and walk-forward validation.

Machine Learning & Genetic Algorithms

Machine Learning and Genetic Algorithms are complementary AI methodologies used in this platform to solve complex optimization, classification, and forecasting problems in financial markets.

Machine Learning Paradigms

The platform leverages both supervised and unsupervised learning. Supervised learning uses labeled historical data to predict future outcomes — including regression for continuous outputs and classification for discrete signals (e.g., buy vs. not-buy). Unsupervised learning finds hidden structure without labels, commonly used here for clustering assets by risk profile and behavioral similarity.

Model Trade-offs

Interpretability vs. flexibility is a core design trade-off. Simpler models like decision trees are easier to explain, while more flexible models like random forests and neural networks capture richer nonlinear patterns. Boosting families such as XGBoost improve predictive power by combining many weak learners sequentially — each new learner focuses on prior errors, with regularization to reduce overfitting risk.

Feature Engineering

Robust feature engineering is critical. Normalization aligns variables with different scales (price vs. volume) for stable optimization. Detrending removes broad market drift to improve tactical signal detectability. Feature selection uses Boruta-style methods that compare real features against randomized shadow features, keeping all genuinely relevant variables rather than only a minimal subset.

Genetic Algorithms

Genetic Algorithms are evolutionary search methods inspired by natural selection. Candidate solutions are encoded as chromosomes (e.g., entry/exit rule sets). An initial population is scored with a multi-objective fitness function that includes risk, stability, and turnover controls — not just profit. High-fitness candidates reproduce through crossover, random mutation introduces controlled diversity, and over generations robust rule combinations emerge.

Design rules ensure robustness: sufficiently large populations preserve diversity, and iteration limits prevent over-specialization to historical noise.

Practical Integration

Modern workflows combine methods rather than using them in isolation. Unsupervised ML clusters assets by latent structure. Supervised probabilistic ML produces tactical binary states for inclusion decisions. Global optimizers (GA, swarm-intelligence families) tune portfolio-level behavior. LLM layers can enrich numeric models by extracting macro and sector signals from text corpora before those shifts are fully visible in price data.

Signal Frameworks

trending_up

Relative Strength

Levy/Mansfield RS cross-sectional ranking. Smoothed relative strength with momentum ROC to isolate outperforming candidates vs. benchmark.

show_chart

KAMA

Kaufman's Adaptive Moving Average for trend filtering. Slows in noisy congestion, accelerates in directional phases. Used as an adaptive trailing-stop anchor.

bar_chart

VWMA

Volume-Weighted Moving Average for trend confirmation. Gives more weight to price moves backed by high volume. Strengthens regime confirmation in the Dow filter.

equalizer

Market Profile

Point of Control, Value Area, and Initial Balance for execution context. Provides support/resistance and acceptance/rejection context for signal-validated entries.

Governance & Quality

The platform enforces quality through multiple automated gates. Test-driven development with pytest and coverage reporting ensures behavioral correctness. Ruff handles linting and formatting, while mypy provides static type checking across the entire codebase.

Strategy evaluation must report Sharpe, Sortino, and Calmar ratios, drawdown, and turnover impact before promotion to execution phases. Production execution is gated behind stable paper-trading behavior, and walk-forward validation ensures strategies generalize beyond their training period.

"The platform is designed to increase decision discipline and auditability, not to promise returns. Its value is in repeatable methods, explicit constraints, and measurable risk-aware workflow controls."