Skip to content

rigneshroot/quantitative-trading-lab

Repository files navigation

Quantitative Trading Lab

Python 3.8+ License: MIT Code style: black

Your hands-on workspace for learning quantitative trading from the ground up.

Think of this as your personal research lab where you can explore how professional traders actually think about markets. I've taken three foundational papers from industry legends and turned them into working Python code you can experiment with.

📚 What's Inside

I've implemented three major frameworks that cover the core of quantitative trading:

Muller - How Prop Traders Think

Dive into the notes →

Learn what actually matters when you're trading with real money. Peter Muller (Morgan Stanley) breaks down:

  • Why Sharpe Ratio is king for market-neutral strategies
  • The Grinold-Kahn framework (the math behind "more bets vs better bets")
  • How transaction costs kill strategies that look great on paper
  • Risk management that actually works

Almgren-Chriss - The Art of Executing Big Orders

Explore the implementation →

Ever wonder how institutions trade millions of shares without moving the market? This shows you:

  • The fundamental trade-off: execute fast (high impact) vs slow (high risk)
  • How to calculate the optimal execution trajectory
  • Why the answer is usually "exponential decay" (trade more upfront, taper off)

Hasbrouck - What's Really Happening in the Market

Check out the microstructure tools →

Get inside the mechanics of how markets actually work:

  • Order flow imbalance (buy pressure vs sell pressure)
  • Bid-ask spreads (what you're really paying to trade)
  • Price impact (how your trades move the market)

🗂️ Structure

trading-lab/
│
├── papers/                         # Paper-based conceptual work
│   ├── muller_proprietary_trading/
│   │   ├── notes.md               # Key concepts & insights
│   │   ├── references.md          # Citations & links
│   │   └── Muller_Proprietary_trading.pdf
│   │
│   ├── almgren_chriss_execution/
│   │   ├── notes.md               # Execution theory
│   │   └── references.md
│   │
│   └── hasbrouck_microstructure/
│       ├── notes.md               # Microstructure concepts
│       ├── empirical_notes.md     # Data patterns
│       └── references.md
│
├── notebooks/                     # Interactive experiments
│   ├── muller_proprietary_trading.ipynb
│   ├── microstructure/            # (future)
│   └── execution/                 # (future)
│
├── src/                           # Reusable code
│   ├── muller_framework.py
│   ├── portfolio_construction.py
│   ├── microstructure/            # (future)
│   ├── execution/                 # (future)
│   └── utils/
│
├── experiments/                   # Robustness analysis
│   ├── robustness_tests.md
│   ├── parameter_instability.md
│   └── regime_dependence.md
│
├── data/                          # Datasets
│   ├── raw/
│   └── processed/
│
└── references.md                  # Master reading list

🚀 Getting Started

Install Dependencies

First, grab the Python packages you'll need:

cd quantitative-trading-lab
pip install -r requirements.txt

That's it! You're ready to start exploring.

Muller Framework

from src.muller_framework import SharpeRatioCalculator, StrategyEvaluator
import numpy as np

# Calculate Sharpe Ratio
returns = np.random.normal(0.001, 0.02, 252)
calc = SharpeRatioCalculator()
sharpe = calc.calculate(returns)

# Evaluate strategy
evaluator = StrategyEvaluator()
metrics = evaluator.evaluate(returns)

Almgren-Chriss Optimal Execution

from src.execution.almgren_chriss import AlmgrenChrissModel, MarketParams, ExecutionParams

# Define parameters
market = MarketParams(volatility=0.02, lambda_temp=0.01, gamma_perm=0.001)
execution = ExecutionParams(total_shares=100000, num_periods=10, risk_aversion=1.0)

# Calculate optimal trajectory
model = AlmgrenChrissModel(market, execution)
holdings = model.optimal_trajectory()
expected_cost = model.expected_cost()

Hasbrouck Market Microstructure

from src.microstructure.order_flow import OrderFlowAnalyzer
from src.microstructure.spread import SpreadAnalyzer
from src.microstructure.impact import PriceImpactAnalyzer

# Order flow analysis
analyzer = OrderFlowAnalyzer()
ofi = analyzer.calculate_ofi(trades, window='1min')

# Spread analysis
spread_analyzer = SpreadAnalyzer()
effective_spread = spread_analyzer.effective_spread(price, bid, ask, direction)

# Price impact
impact_analyzer = PriceImpactAnalyzer()
kyle_lambda = impact_analyzer.estimate_kyle_lambda(price_changes, signed_volumes)

Interactive Notebooks

jupyter notebook notebooks/muller_proprietary_trading.ipynb
jupyter notebook notebooks/execution/almgren_chriss_simulation.ipynb
jupyter notebook notebooks/microstructure/order_flow_imbalance.ipynb

📖 Learn More

Each paper comes with detailed notes that explain not just what the math says, but why it matters:

  • notes.md - The key ideas, explained in plain English
  • references.md - Where to go deeper
  • empirical_notes.md - What to actually look for when you analyze real data

Start Here

🗺️ Future Projects

This is the foundation for a series of quantitative trading research projects. I've planned out 10 additional projects that progressively build understanding of market microstructure, execution, and trading systems.

Check out the full ROADMAP for detailed plans including:

Phase 1: Microstructure Foundations

  • Limit Order Book Simulator
  • Liquidity Regime Lab
  • Order Flow & Absorption Diagnostics (optional)
  • Execution Cost Model (Almgren-Chriss)

Phase 2: Market Structure & Time Effects

  • FX Session Microstructure
  • Stylized Facts of FX Markets

Phase 3: Impact, Discovery & Complexity

  • Slippage & Market Impact Analyzer
  • Price Discovery & Fragmentation Lab
  • Market as Complex Adaptive System

Phase 4: Robustness, Failure & Production

  • Strategy Failure Modes Library
  • Microstructure-Aware Backtesting Engine

Each project includes visual diagrams, core components, and clear learning objectives. The roadmap focuses on mechanism, diagnosis, and execution realism—not alpha chasing.

🔬 Research Philosophy

  1. Paper-First: Start with academic/industry research
  2. Understand Deeply: Create detailed notes on concepts and failure modes
  3. Implement Cleanly: Build modular, well-documented code
  4. Test Rigorously: Robustness tests, regime analysis, out-of-sample validation
  5. Document Findings: Track what works, what doesn't, and why

🎯 Core Concepts

Muller - Proprietary Trading

Sharpe Ratio: Primary metric for market-neutral strategies

SR = Annual Excess Return / Annualized Std Dev

Grinold-Kahn Framework: Fundamental Law of Active Management

SR² = N × (IC² / (1 - IC²))

Key Insight: Focus on depth (improving one strategy) over breadth (many weak strategies)

Almgren-Chriss - Optimal Execution (Planned)

Trade-off: Market impact vs price risk

Optimal Strategy: Balance execution speed with cost minimization

Hasbrouck - Market Microstructure (Planned)

Order Flow: Buy/sell imbalance predicts short-term price moves

Spread Components: Processing costs + adverse selection + inventory costs

🧪 Experiments

Robustness Testing

  • Parameter sensitivity analysis
  • Out-of-sample validation
  • Regime testing (bull/bear, high/low vol)
  • Data quality stress tests

Failure Mode Analysis

  • When do models break?
  • Parameter instability detection
  • Regime change identification
  • Crisis behavior

See experiments/ for detailed frameworks.

📊 Implementation Status

Paper Notes Code Notebooks Status
Muller ✅ (1) Complete
Almgren-Chriss ✅ (1) Complete
Hasbrouck ✅ (3) Complete

Total: 3 papers, 7 Python modules, 5 Jupyter notebooks

What's Implemented

Muller - Proprietary Trading:

  • src/muller_framework.py - Sharpe Ratio, risk management, Grinold-Kahn
  • src/portfolio_construction.py - Position sizing, portfolio optimization
  • notebooks/muller_proprietary_trading.ipynb - Interactive tutorial

Almgren-Chriss - Optimal Execution:

  • src/execution/almgren_chriss.py - Optimal trajectory, cost analysis, simulation
  • notebooks/execution/almgren_chriss_simulation.ipynb - Execution strategies

Hasbrouck - Market Microstructure:

  • src/microstructure/order_flow.py - OFI, trade classification, VAR models
  • src/microstructure/spread.py - Spread decomposition, Roll model
  • src/microstructure/impact.py - Kyle's lambda, impact models
  • notebooks/microstructure/order_flow_imbalance.ipynb - OFI analysis
  • notebooks/microstructure/bid_ask_spread.ipynb - Spread analysis
  • notebooks/microstructure/price_impact.ipynb - Impact analysis

Utilities:

  • src/utils/data_loader.py - Data generation and validation
  • src/utils/plotting.py - Visualization utilities

🤝 Contributing

We welcome contributions! Whether you want to:

  • Implement a new paper
  • Add unit tests
  • Improve documentation
  • Fix bugs
  • Add examples

Check out CONTRIBUTING.md for guidelines.

Ideas for Contributions

  • New Papers: Fama-French factors, momentum strategies, volatility models
  • Tests: Unit tests for core modules
  • Examples: Real data analysis, strategy backtests
  • Documentation: Clarify concepts, add tutorials

📄 License

MIT License - See LICENSE

⚠️ Real Talk

This is a learning tool, not a money-printing machine. Trading is hard, and most people lose money. Use this to understand the concepts, test ideas, and learn—but don't bet your rent money on anything you build here.

Seriously: paper trade first, backtest thoroughly, and never risk more than you can afford to lose.

📚 References

See references.md for complete reading list.

Core Papers:

👤 Author

Rignesh


Happy trading! 📈

Questions? Found a bug? Want to add a new paper? Open an issue or submit a PR. This is a learning project—let's make it better together.

About

Hands-on quantitative trading lab: implement classic papers in Python with Jupyter notebooks and complete documentation

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors