~kris/dots

srice

srice/doc/trading/research-python-tools.md -rw-r--r-- 6.9 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago

#title: "Python Tools for Solo Systematic Trading" date: 2026-05-21 source: agent research

#Python Tools for Solo Systematic Trading

Scripts, utilities, and libraries for day-to-day systematic trading on Python 3.12+ with VectorBT + NautilusTrader as core stack.

#1. Market Data Warehousing

Tool Stars What It Does Fit
yfinance 15k Download OHLCV bars from Yahoo Finance. Free, no API key. Rate-limited 2k req/day. Prototyping. Not for production backtests (survivorship-biased).
pandas-datareader 2.7k Unified interface to Yahoo, Federal Reserve, NASDAQ, Quandl, Alpha Vantage, Eurostat. Macro/economic data alongside market data.
alpha_vantage 4.2k Wrapper around Alpha Vantage API. OHLCV, intraday (1-min), FX, crypto, options. Backup when yfinance rate-limits. Supports 1-min bars.
DuckDB + Parquet N/A Store in Parquet (columnar, compressed), query with DuckDB (embedded, no server). Scan terabytes in seconds. Zero-ops warehouse. Pairs with yfinance -> Parquet -> DuckDB.
TimescaleDB N/A Postgres extension. Continuous aggregates auto-materialize OHLC candles from ticks. Live tick data on STARGATE. Multi-threaded, crash-safe.

Reference: Personal Market Database with DuckDB and Parquet

#2. Portfolio Analytics and Tearsheets

Tool Stars What It Does Fit
quantstats 5.2k 50+ metrics: Sharpe, Sortino, Calmar, max drawdown, VaR, CVaR, ulcer index. Interactive HTML tearsheets. Industry standard. Run daily on live equity curve.
pyfolio 5.5k Tear sheets, return analysis, risk metrics, factor attribution. Originally from Quantopian. Good for factor analysis; more academic than quantstats.
PyPortfolioOpt 7k Modern portfolio theory, efficient frontier, Kelly optimization, risk budgeting. Use .kelly_objective() for position sizing.

#3. Order Execution / Broker Wrappers

Tool Stars What It Does Fit
ib_async 1.5k Async/await wrapper around IBKR TWS/Gateway. Full API: orders, positions, market data, account balance. Production-ready. Handles partial fills, rejections. Successor to ib_insync.
alpaca-py 2.8k Official Alpaca SDK. Market data (5000+ stocks, 20+ crypto), paper/live trading, options, positions. Paper trading is free. Asset-specific clients.
coinbase-advanced-py 500+ Official Coinbase Advanced API wrapper. Order execution, market data, portfolio management. Maintained by Coinbase.
public.com N/A No major Python wrapper found. Implement via REST API directly (httpx). Roll your own.

#4. Risk Management and Position Sizing

Kelly Criterion: Use PyPortfolioOpt's .kelly_objective() or manual:

kelly_pct = (win_rate * reward_ratio - loss_rate) / reward_ratio
# Use 10-25% of full Kelly in practice

Position sizing methods:

  • Fixed size (same contracts/shares per trade)
  • Percent allocation (% of capital)
  • Fixed fractional risk (% of capital per trade x risk ratio)
  • Volatility-targeted (Rob Carver's approach via cvxpy)

Correlation monitoring: franklinjtan/Portfolio-Diversification-Correlation-Risk-Management -- correlation matrices, heatmaps, beta calculations. Run weekly for pairs/stat arb.

#5. Alerts and Notifications

Tool Stars What It Does
TradingView Webhook Bot 2.5k Listen to TradingView alerts via Flask webhooks; forward to Telegram, Discord, Slack, email. Self-hosted.
python-telegram-bot + schedule N/A Monitor price thresholds, drawdown levels, position breach alerts via API polling -> Telegram.

#6. Technical Analysis Indicators

Tool Stars What It Does
pandas-ta 5.5k 150+ indicators as pandas DataFrame extensions. df.ta.rsi(), df.ta.macd(). Vectorized, fast.
alphalens 3k Forward-looking factor analysis. Decay curves, holding period analysis, correlation with returns.
TA-Lib (C backend) N/A 34 core indicators, faster than pandas-ta for large backtests. Overkill for most use cases.

#7. Jupyter Notebook Templates

Source What It Provides
QuantConnect/Research 30+ templates: pairs trading with cointegration, Kalman filtering, fundamental factor analysis, Alphalens integration.
walk-forward-backtester Rolling window optimization with Bayesian optimization. Essential for overfitting prevention.

#8. Mercury Bank API

Tool What It Does
mercury-bank-api (PyPI) Python client for Mercury API. Account queries, ACH transfers, transaction history.
Mercury API docs Direct REST with Bearer token. Script with httpx.
mcp-mercury-banking MCP server for Mercury (LLM-friendly read-only queries).

Cash flow pattern: Mercury Treasury (4-5% APY on idle cash) -> programmatic ACH to broker when buying power needed -> ACH back when flat.

#9. Backtesting Frameworks (Quick Reference)

Tool Stars Best For
VectorBT 4.5k Fastest for parameter sweeps. Numba-accelerated.
backtesting.py 5.2k Clean Pythonic API, easy learning curve.
Zipline-Reloaded 2.8k Best for equity factor research.
NautilusTrader 1.8k Production-grade Rust core. Research -> live bridge.

#Stack Summary

Data flow:     yfinance -> DuckDB/Parquet -> VectorBT backtest
Research:      Jupyter + QuantConnect templates (pairs, factor analysis)
Live:          NautilusTrader executes; ib_async (IBKR) or alpaca-py (paper) for orders
Monitoring:    quantstats daily tearsheets + drawdown alerts (Telegram)
Cash flow:     mercury-bank-api automates yield sweeps
Reconciliation: Compare NautilusTrader fills vs. broker API fills via SQLite OMS
Indicators:    pandas-ta (150+ indicators as DataFrame extensions)