Open-source quantitative trading framework for detecting and exploiting market inefficiencies across all asset classes via Interactive Brokers TWS API.
AlgoStrategy/
├── config.py # Global configuration & universes
├── ib_connector.py # IB TWS API wrapper (ib_insync)
├── quant_math.py # FFD, HMM, GARCH, OU process
├── scanners/
│ ├── pairs_cointegration.py # Stat arb: Engle-Granger + OU
│ ├── etf_nav_arbitrage.py # ETF premium/discount
│ ├── futures_basis.py # Cash-futures basis
│ ├── options_parity.py # Put-call parity violations
│ └── microstructure.py # OFI, VWAP, volume anomalies
├── execution/
│ ├── position_sizer.py # Half-Kelly + correlation
│ ├── order_manager.py # Smart routing, TWAP, brackets
│ └── risk_manager.py # DD limits, VaR, kill switch
├── analytics/
│ ├── stats.py # Sharpe, Sortino, CAGR, etc.
│ └── reporter.py # HTML dashboard (auto-refresh)
└── fund_v2.py # Crypto momentum strategy (standalone)
| Scanner | Strategy | Expected Sharpe | Asset Classes |
|---|---|---|---|
| Pairs Cointegration | Engle-Granger stat arb with OU half-life | 0.8-1.3 | ETFs, Stocks |
| ETF NAV Arbitrage | Premium/discount vs theoretical NAV | 0.5-0.8 | ETFs |
| Futures Basis | Cash-futures basis vs cost of carry | 0.5-0.9 | Futures |
| Options Parity | Put-call parity violation detection | 0.8-1.2 | Options |
| Microstructure | OFI + VWAP deviation + volume anomalies | 0.3-0.6 | All |
- Python 3.10+
- Interactive Brokers TWS or IB Gateway running
- API enabled in TWS (Edit > Global Configuration > API > Settings)
git clone https://github.com/CypherC0d3/AlgoStrategy.git
cd AlgoStrategy
pip install -r requirements.txt# Test IB connection
python ib_connector.py
# Run pairs scanner (offline mode - no IB needed)
python -m scanners.pairs_cointegration
# Run all scanners
python main.pyAll scanners work without IB connection using yfinance historical data:
from scanners import PairsScanner
scanner = PairsScanner(connector=None) # No IB
signals = scanner.scan()- Max 3% per position (Half-Kelly)
- 5% daily drawdown limit
- 15% monthly drawdown limit
- 3x max gross leverage
- Portfolio VaR at 95% confidence
- Emergency kill switch (flatten all)
See CONTRIBUTING.md for guidelines on adding new scanners.
This software is for educational and research purposes only. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always validate with paper trading before risking real capital.
MIT License - see LICENSE