Live Monitoring Dashboard:
http://uspairs.dr2112.com
📸 Screenshots:
See the /screenshots folder for a quick view of the dashboard.
This project is a fully deployed statistical arbitrage system that trades mean reversion across 50+ US equity pairs.
The system:
- Runs continuously on a VPS
- Evaluates signals every minute during NYSE hours
- Simulates execution via a stateful portfolio engine
- Exposes a real-time monitoring dashboard
It is designed as a production trading system
Polygon.io
│
▼
Historical Data Loader
│
▼
┌─────────────────────┐
│ Analytics Layer │
│ (15m statistical) │
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Strategy Engine │
│ (1m signal logic) │
└─────────────────────┘
│
▼
┌─────────────────────┐
│ Portfolio Simulator │
│ Position Manager │
└─────────────────────┘
│
▼
SQLite Trading DB
│ │
▼ ▼
Streamlit Dashboard Telegram Alerts
Spread is defined as a price ratio:
spread = price_1 / price_2Z-score:
z = (spread - rolling_30d_mean) / rolling_30d_stdFeatures:
- 30 trading day lookback
- Weekly rebalance of slow statistics (Fridays only)
- Statistics forward-filled intra-week
- Lookahead bias removed via
shift(1)
|z| ≥ 3.5
Additional signal filter:
- 2-of-3 consecutive 1-minute bars must exceed the threshold
- Reduces microstructure noise and false signals
|z| ≤ 1.0
Dynamic widening near events:
- Earnings multiplier
- Dividend multiplier
- Macro event multiplier
Maximum exit threshold cap:
|z| ≤ 1.5
- No cooldown
- New signals allowed immediately after exit
Two-layer hedge system:
- Instantaneous hedge ratio
- Updated every bar
- 30-day rolling regression
- Rebalanced weekly
- Forward-filled intra-week
Purpose:
- Reduce hedge noise
- Preserve statistical calibration
Beta-adjusted dollar-neutral sizing:
capital_per_trade = equity * alloc_pct
leg1 = capital_per_trade / (1 + beta)
leg2 = leg1 * betaDefault parameters:
| Parameter | Value |
|---|---|
| Starting Equity | $100,000 |
| Allocation per trade | 6.5% |
A realistic four-component cost model is applied to every trade.
$0.005 per share
$1.00 minimum per leg
Applied to all four executions in a round-trip pairs trade.
FINRA TAF:
$0.000195 per share sold
Cap: $9.79 per trade
SEC Section 31:
$0.00 per dollar sold
(Current rate as of May 2025)
Applied to the two sell executions.
Default:
0.5% annual
Accrued daily on short-leg notional.
Calculation:
borrow_cost = short_notional * rate * days_held / 365Half-spread estimate:
1 basis point per execution
slippage = notional * 1 / 10000- All costs deducted at trade close
- Unrealized P&L reflects estimated round-trip costs
Trade records store:
- Commission
- Regulatory fees
- Borrow cost
- Slippage
for full cost attribution.
The system implements multi-layered risk protection:
- Beta drift entry filter (6.5%)
- Beta drift in-position stop (10%)
- Earnings event multiplier (1.5×)
- Dividend multiplier (1.3×)
- Macro event multiplier (1.2×)
- Exit threshold cap (1.5)
- Market-hours gating
- One position per pair
- Persistence filter
- Data staleness detection
- Engine heartbeat monitoring
- Telegram alert throttling
Rather than disabling trading around events, the system adapts risk dynamically.
Equity snapshots:
- Every 15 minutes intraday
- End-of-day mark-to-market equity
Includes:
- Realized P&L
- Unrealized P&L
Computed from daily MTM equity returns:
Sharpe = mean(daily_returns) / std(daily_returns) * sqrt(252)The monitoring dashboard displays:
- Total Trades
- Win Rate
- Sharpe Ratio
- Average P&L per Trade
- Average Hold Time
- Total Fees Paid
Real-time alerts include:
- Pair
- Z-score
- Position sizing
- Net P&L
- Fee breakdown
- Holding period
- Realized P&L
- Total fees paid
- Equity
- Win/loss count
The engine uses a dual-layer signal architecture.
Responsible for:
- Rolling mean
- Rolling standard deviation
- Hedge ratio estimation
Characteristics:
- Weekly rebalance
- Cached computations
Responsible for:
- Signal evaluation
- Risk filter application
- Trade simulation
- Portfolio updates
Signals evaluated every 60 seconds.
Deployment stack:
| Component | Description |
|---|---|
| VPS | DigitalOcean (Ubuntu) |
| Services | systemd-managed processes |
| Database | SQLite (WAL mode) |
| Dashboard | Streamlit terminal UI |
| Alerts | Telegram bot |
| Deployment | GitHub → VPS auto-pull |
Features:
- Crash recovery via persistent state
- Concurrent engine/dashboard database access
- Event calendar integration
- Modular architecture
analytics → strategy → execution → persistence → monitoring
Market Data:
- Polygon.io
- 1-minute OHLCV
- 15-minute OHLCV
Additional datasets:
- Earnings calendar
- Dividend events
Historical warmup:
75 trading days
Storage:
- Append-only CSV history
- SQLite trading database
The engine currently supports:
- 50+ concurrent pairs
- 1-minute signal evaluation
- Medium-frequency stat arb
Design focus:
- Robustness
- Operational reliability
- Research reproducibility
(Not ultra-low-latency HFT)
Key design features:
- Weekly hedge rebalance to reduce beta noise
- Explicit lookahead bias prevention
- Event-aware dynamic exit thresholds
- Beta drift enforcement during entry and holding
- Persistence filter to reduce microstructure noise
- Full four-component transaction cost model
- Mark-to-market equity with proper Sharpe calculation
- Real-time monitoring dashboard
- Production deployment infrastructure
This project bridges research logic and production trading systems.
This project is provided for educational and research purposes only.
It does not constitute investment advice and should not be used for live trading without proper risk controls and regulatory compliance.