📖 What is this project?
AlpacaBot V3 is an automated trading bot that manages a US-market portfolio with no manual intervention.
It runs on a cloud server, connects to the Alpaca broker via API, and makes buy/sell decisions using quantitative strategies developed and validated through backtesting.
All money is managed through one savings account split into 5 virtual goals — each goal simulates a separate portfolio with a different strategy, but all orders are aggregated and netted (buys from one goal offset sells from another) before a single order per symbol is sent to the broker.
Currently running in paper trading mode — simulated orders, real money deposited but not at real risk. Moving to live requires surviving a 60-day paper gate and passing performance filters.
🏗️ Architecture — 5 virtual goals
One Alpaca account · each goal holds virtual cash + virtual positions · clearing engine nets everything into one order per symbol
🚗 car — Titan 70/30
$500 deposited · EOD 18:50 UTC + intraday · 70% FBV6 (QQQ core + momentum satellites) + 30% SOXL intraday
📊 check fbv6 — FatherBot V6
$100 deposited · EOD cycle 18:50 UTC · 55% QQQ + top-2 satellites by multi-window momentum
🌐 check sr_fbv6 — Sector-Relative V6
$100 deposited · EOD cycle 18:50 UTC · 55% QQQ + one satellite per sector theme (no two from same sector)
⚡ check SOXL — Intraday
$100 deposited · every 15 min · 14:30–19:00 UTC weekdays · RSI + volume-ratio entry gates
📊 check fbv6_2 — FatherBot V6 (2nd)
$200 deposited · EOD cycle 18:50 UTC · same FBV6 strategy, independent tracking
🔄 EOD Cycle — how each trading day works
18:50 UTC (after US market close) — the bot runs its end-of-day cycle:
1️⃣ Strategy engine fetches market data (400 trading days back), evaluates each strategy, and computes target weights per goal.
2️⃣ Engine compares current virtual holdings to target weights and generates intents — buy/sell orders at goal level.
3️⃣ Clearing engine collects all intents from all goals, nets them (goal A buy + goal B sell = only the difference hits the broker), and submits one order per symbol to Alpaca.
4️⃣ Alpaca fills the order → clearing engine receives confirmation → distributes shares/cash between goals proportionally.
5️⃣ Bot writes an equity snapshot — total value of each goal at end of day.
⚡ Intraday Cycle — SOXL
SOXL is a 3× leveraged ETF on semiconductor stocks (tracks the SOX index). During market hours the bot checks every 15 minutes:
• RSI(9) ≥ 55 — is momentum positive?
• Volume ratio ≥ 1.5× — is current volume above 20-bar average?
Entry: when both conditions are met. Exit: trailing stop triggered, or 19:00 UTC forced close. Always flat overnight — no open position outside market hours.
📐 Strategies — summary
FatherBot V6 (FBV6)
Regime gate: SPY below 200-day SMA → 100% short bonds (defensive). Bull market: 55% QQQ + top-2 momentum satellites from universe (SOXL, PL, MU, PLTR, RKLB…), ranked by composite momentum 1/3/6/12-month. Excludes leveraged ETFs from satellite slots. Backtest: CAGR +17.7%, Sharpe 0.89.
Sector-Relative FBV6 (SR-FBV6)
Same as FBV6 but enforces 1 satellite per sector theme (semis / space / defense / tech…). Prevents over-concentration in one sector. Backtest: Sharpe 1.02, max drawdown −44% vs −56% for FBV6.
Titan 70/30
Max-growth variant — 70% slice runs FBV6 (55% QQQ core + momentum satellites) at EOD, 30% slice trades SOXL intraday. Largest goal ($500 deposited).
SOXL Intraday
Intraday-only on SOXL. Waits for RSI + volume entry signal on 15-min bars, exits via trailing stop or forced close at 19:00 UTC. Never holds overnight.
🛡️ Safety layer
Kill switch
Global halt — stops all trading. Auto-triggers on: daily portfolio loss ≥3% · 3+ goals in trail-stop simultaneously · ≥2 per-goal halts active at the same time (escalation). Also triggerable manually via flag file. Survives bot restart (persisted in DB).
Per-goal daily halt
If a single goal drops ≥15% in one day, that goal is halted for the rest of that calendar day. Auto-resets next morning. If ≥2 goals hit this simultaneously, escalates to global kill switch.
Idempotent orders
Every order gets a unique client_order_id. If the bot crashes mid-cycle and restarts, it won't double-buy. Broker rejects already-used IDs; bot retries with _r1/_r2 suffix.
Atomic clearing
Distributing fills between goals is wrapped in a single DB transaction. A server crash mid-distribution won't leave partial ledger entries.
Clearing lock
Only one clearing cycle runs at a time. DB mutex prevents race between EOD and intraday cycles.
Daily reconciliation
Every morning (Tue–Sat 08:05 UTC): virtual positions vs real Alpaca positions compared. Gap >$15 → Telegram alert. Trend monitored across 7 days — a growing gap signals a real ledger bug.
Snapshot validation
Before saving equity: checks for illegal/negative values and cash + positions = total integrity. Day-over-day jump >20% flagged as suspect.
Data quality guard
After fetching market data: if 0 universe tickers have ≥252 days of data, an error is logged. Catches silent data-feed failures (caught one that ran 18 days undetected).
🤖 Autonomous monitoring departments
Beyond the bot itself, a full stack of scripts uses AI to monitor, analyze, and report:
Risk monitor — every 2h (10–20 UTC weekdays)
Checks daily losses, position concentration, intraday drawdown. Triggers kill switch or per-goal halt if thresholds hit. Telegram alert on any issue.
Cycle checker — 3× daily
Verifies EOD and intraday cycles actually ran on time. 14:40 (intraday open), 19:05 (intraday close), 20:55 (EOD audit).
Heartbeat checker — 21:05 + 23:00 UTC
Dead-man's switch: if zero cycles ran today → Telegram alert. Runs twice nightly for redundancy. Keeps daily record even when everything is fine.
Operations — 06:00 UTC daily
System health: crontab intact? DB accessible? Service running? Disk/RAM OK? Telegram on CRITICAL or WARNING.
Reconciliation — 08:05 UTC (Tue–Sat)
Virtual ledger vs real Alpaca positions and cash. Gaps → Telegram + report.
Analyst — Sunday 09:10 IDT (Mac)
AI weekly market analysis: indices, volatility, regime, macro events. Report → Telegram.
Debugger — Sunday 09:10 IDT (Mac)
AI pass over logs: errors, stop-loss frequency, missing fills, cycle gaps, DB integrity.
Overseer — Tue–Sat 01:10 IDT (Mac)
Meta-bot: reads all dept reports from last 48h, synthesizes cross-dept picture, extracts action items, rates GREEN/YELLOW/RED → Telegram.
Paper→live gate — Sunday 06:30 UTC
Weekly: checks Sharpe ratio, max drawdown, SPY lag. Reports days remaining toward 60-day gate.
Weekly digest — Sunday 08:45 UTC
Per-goal equity, return since deposit, WoW%, alpha vs QQQ, slippage analysis, gate progress bar.
☁️ Infrastructure
Cloud server — Google Cloud
GCP e2-small, us-central1-a (34.67.234.116). Bot runs as a managed systemd service — auto-restarts on crash and on server reboot.
Database — SQLite
All state: goals, virtual positions, intents, equity snapshots, kill switch events, FIFO lots for tax reporting (April 2027). Nightly backup (30 days retained).
Telegram
All alerts: kill switch, per-goal halt, heartbeat, reconciliation, overseer daily report. This miniapp is also delivered via Telegram.
Secrets — GCP Secret Manager
API keys (broker, AI) stored outside codebase in encrypted cloud vault. Loaded at startup; falls back to .env on local dev.
Private network — Tailscale
Mac → server and dashboard access via private VPN (100.100.16.12). No public internet exposure for the dashboard.
🚀 Paper → live gate
Currently: paper trading — simulated orders, real money deposited but not at real risk.
Paper gate started 2026-05-04, target ~2026-07-03 (60 EOD trading days).
All of the following must pass before switching to live:
✅ 60 consecutive EOD cycles without crash
✅ Positive Sharpe ratio + max drawdown within bounds
✅ No meaningful lag vs SPY benchmark
✅ No single day down more than 8%
✅ Manual review of 30 days of reports
✅ Clean reconciliation — virtual ledger matches broker
Live account plan: start with ≤$100 for first 6 months to verify real execution matches backtest before scaling.