Algo Trading & Quant
Python automation, backtesting frameworks, execution systems, and quantitative research workflows for systematic trading.
Python Automation
IBKR via ib_insync, Zerodha Kite Connect, yfinance for data, scheduled jobs via cron / GitHub Actions.
Backtesting
Event-driven backtester with stop / target / time-stop simulation, R-multiple tracking, drawdown analysis, and walk-forward validation.
Quant Strategies
Mean reversion, trend following, divergence detection, volatility expansion, pairs trading — all with paper-first deployment.
What "algo trading" actually involves
It's not just "let the computer trade." A complete algo system handles every step a discretionary trader would, but in code:
- Implementing technical indicators — RSI, MACD, ATR, Stochastic, EMA, Supertrend, Bollinger Bands. Either via TA-Lib (C-fast) or pure pandas (portable).
- Detecting candlestick patterns — Doji, Hammer, Engulfing, Morning/Evening Star, Marubozu, Shooting Star. TA-Lib has 60+ patterns built-in.
- Calculating stop-loss dynamically — `stop = entry − N × ATR(14)` is the workhorse. Optional "swing-pivot floor" widens the stop to just past the prior structural level if ATR is tighter.
- Calculating target levels — fixed R-multiple (1.5R, 2R) or technical (mean-reversion to BB middle, prior swing high).
- Position sizing & quantity — `qty = int((NAV × risk_pct%) / (entry − stop))`. Floor first, then divide — small but real bug source.
- Order execution — bracket orders (market entry + stop + target as OCO children) via the broker's API. Always log the parent + child IDs to a CSV for audit.
- Risk management — daily kill switch, max concurrent positions, max loss per trade as % of NAV. Enforce in code, not in the prompt.
- Backtesting before live — replay historical bars, simulate fills at next-bar open, track exits realistically. Watch for lookahead bias.
- Paper-first deployment — never flip to live without 60+ days of paper-account proof that the system behaves as designed under real bid-ask + slippage.
A typical signal-to-order pipeline
# 1. Fetch bars ohlc = fetch_bars(ticker, period="6mo", interval="1d") # 2. Compute indicators ohlc["RSI"] = rsi(ohlc["close"], 14) ohlc["MACD"] = macd(ohlc["close"], 12, 26, 9) ohlc["ATR"] = atr(ohlc, 14) # 3. Detect divergence + candlestick confluence divs = find_divergence(ticker, ohlc) ohlc = detect_candle_patterns(ohlc) # 4. If signal fires, build the trade plan if buy_signal(ohlc): entry = ohlc["close"].iloc[-1] stop = entry - 2.0 * ohlc["ATR"].iloc[-1] target = entry + 3.0 * ohlc["ATR"].iloc[-1] # 1.5R qty = int((NAV * 0.01) / (entry - stop)) # 1% risk # 5. Submit bracket order to broker place_bracket(ticker, "BUY", qty, entry, stop, target) log_to_csv(ticker, qty, entry, stop, target)
Tools we use on the channel
- Python — the only realistic language for retail algo trading in 2026
- pandas + numpy — bar / indicator manipulation
- TA-Lib — fast indicator + candle pattern library (C-backed)
- ib_insync — IBKR API wrapper (much cleaner than native ibapi)
- kiteconnect — Zerodha API for Indian markets
- yfinance — free historical data for backtesting + universe scans
- scipy.signal.argrelextrema — pivot detection for divergence + structure
- matplotlib / lightweight-charts — visualization