Veloxformerly AlphaFlow
Six strategies, an 18-step signal pipeline, ML gating, VaR and a tiered circuit breaker, all behind one command. It trades US equities through Alpaca and runs in your terminal. No browser, no web server.
VELOX V12 | PAPER MODE | Regime: BULLISH | PnL Lock: NORMAL | Up: 3h12m ────────────────────────────────────────────────────── PORTFOLIO Value: $106,240 Cash: $61,340 Day P&L: +$1,426 +1.4% Week: +$2,480 +2.4% RISK STATE Vol Scalar 1.08 Beta +0.12 Consistency 78/100 Circuit INACTIVE STRATEGY ALLOCATION MR ########...................... 28% (2 open) PAIRS #########..................... 31% (2 open) PEAD ######........................ 20% (1 open) VWAP ####.......................... 15% (0 open) MICRO #............................. 6% (0 open) ORB .............................. 0% disabled OPEN POSITIONS (5/12) AAPL MR entry=$231.40 qty=60 41m MSFT MR entry=$428.10 qty=30 17m SHORT XOM PAIR entry=$112.85 qty=120 24h59m SWING RECENT TRADES 17:09 BUY INTC STAT_MR +$42 W (take_profit) 16:08 BUY AMD VWAP -$22 L (stop_loss)
One trading day, start to finish
Velox is a single long-running process. It wakes up before the open, scans the universe each cycle, sends the survivors through a pipeline of checks, and manages every position until it exits. Times are US Eastern.
Prepare the universe
A dynamic universe picks ~127 symbols by volume, market cap and the current regime. Statistical mean reversion filters them with the Hurst exponent, an ADF stationarity test and the Ornstein-Uhlenbeck half-life. A pre-open gap analysis calibrates the mean-reversion and breakout strategies.
Scan, every ~2 minutes
All strategies scan for signals. The interval adapts to market activity (SCAN_INTERVAL_SEC defaults to 120). Each signal becomes a Signal object with an entry, stop-loss and take-profit.
Qualify, size, submit
Every signal runs the 18-step pipeline below: hard gates first, then a sizing stage where ML confidence, volatility targeting and sentiment adjust the position, then a bracket order with OMS tracking.
Manage exits
A single ExitOrchestrator decides every exit with a 10-level priority cascade. A WebSocket monitor watches prices so stops react between scans.
Housekeeping
A beta neutraliser hedges with SPY if portfolio beta passes ±0.3. Corporate actions and broker reconciliation run every 30 minutes. The correlation matrix refreshes intraday.
Close out
Day-hold positions are closed before the 16:00 bell and overnight holds are chosen. On Fridays a tax-loss harvesting scan runs, with wash-sale checks.
Summary
The day's P&L, per-strategy breakdown and consistency score are written to the SQLite database and shown in the dashboard. Weekly, KalmanPairs reselects its cointegrated pairs and a walk-forward check validates out-of-sample Sharpe.
Eighteen steps between an idea and an order
Pick a step to see what it does. A gate can stop the signal. A sizing step can only make it smaller. Anything optional fails open, so a missing data source never freezes trading.
Six strategies, five of them allocated
Capital is split across strategies that earn in different conditions. Allocations come from config/settings.py and always sum to 100% across the active ones.
| Strategy | Allocation | Type | Hold | Idea |
|---|---|---|---|---|
StatMeanReversionSTAT_MR | 28% | Mean reversion | Intraday | Fits an Ornstein-Uhlenbeck process to 2-minute bars and enters on extreme z-scores, filtered by Hurst and ADF tests. |
KalmanPairsTraderKALMAN_PAIRS | 31% | Market-neutral | Multi-day | A Kalman filter tracks a dynamic hedge ratio on cointegrated sector pairs and trades the spread. |
PEADPEAD | 20% | Event-driven | Multi-day | Post-earnings announcement drift, confirmed by FinBERT sentiment on the news. |
VWAP v2 HybridVWAP | 15% | Mean reversion | Intraday | VWAP deviation plus an OU z-score as dual confirmation, with a bid-ask spread filter. |
IntradayMicroMomentumMICRO_MOM | 6% | Event-driven | ~8 min | Spots SPY volume spikes and scalps high-beta stocks in the direction of the move. |
ORB v2ORB | 0% | Breakout | Day | Opening-range breakout with gap and range quality filters. Disabled since an alpha-decay alert on 2026-04-17; the code is kept. |
Want to know whether a strategy earns its allocation? velox backtest runs four classic baselines (EMA crossover, RSI, momentum, Bollinger mean reversion) as yardsticks.
Built to survive a bad day first
The defaults lean cautious: paper trading is on, short selling is off, and risk limits tighten automatically as losses build.
Tiered circuit breaker
Driven by the day's P&L, plus a trigger for sudden VIX spikes. Each tier is stricter than the last.
Exit cascade
One orchestrator decides every exit. The first matching level wins, so a hard stop always beats a trailing stop.
- Hard stop loss
- Strategy-specific exits
- Adaptive VIX exit (mean reversion)
- Scaled take-profit and profit tiers
- ATR trailing stop
- RSI momentum exit
- Volatility-expansion exit
- Dead-signal detection
- Scale out of a loser
- Time stops
Order management
Every order is tracked through a state machine with idempotency keys, so a retry never double-submits. Five API failures in five minutes trip the kill switch.
Portfolio guards
- VaR monitor: parametric, historical and Monte Carlo (10,000 paths) at 95% and 99%.
- Correlation limiter: eigenvalue-based effective bets plus a 30% sector cap.
- Volatility targeting: sizes positions toward a 1% daily portfolio volatility.
- Daily P&L lock: sizing drops to 30% after +1.5%, and new trades halt at −1.0%.
- TWAP execution: orders over $2,000 are split into five slices.
- Restart recovery: positions are reconciled with the broker on startup.
A plain Python stack
One process, one SQLite file, no message broker and no web framework. Pinned versions live in requirements.txt.
Broker and data
Orders, positions and market data from Alpaca, VIX and daily bars from Yahoo, live price updates over WebSocket.
Machine learning
A four-model averaging ensemble scores signals from 50 features. Optuna tunes hyperparameters.
Statistics
ADF and cointegration tests, HMM market regimes, Kalman-filter hedge ratios and technical indicators.
Language models
FinBERT runs locally for news sentiment. A Claude model can optionally score signals.
Terminal interface
Rich draws the live dashboard and the tables. Structured JSON logs are available for servers.
Storage and ops
Trades, positions and snapshots live in bot.db. CI runs the suite on Python 3.12 and 3.13.
From clone to running, in minutes
You need Python 3.12+ and, to trade, a free Alpaca paper-trading account. You can explore the dashboard and backtests without any account at all.
Install
Clone the repository and install the dependencies in a virtual environment.
Preview the dashboard
Renders the live terminal view with synthetic data, so you can see what the bot shows without a broker.
Backtest the baselines
Runs four classic strategies on bundled sample data, with each symbol's buy-and-hold return for comparison.
Create an Alpaca paper account
Sign up at alpaca.markets, open the paper-trading dashboard and generate an API key and secret. Paper money only.
Add your keys
Copy the template and fill in ALPACA_API_KEY and ALPACA_API_SECRET. Leave ALPACA_LIVE=false.
Run it
Starts the bot with the live dashboard in this terminal. Press Ctrl-C for a clean shutdown.
Watch it, and know how to stop it
From a second terminal, check on it or ask it to close everything.
Configure
Copy .env.example to .env and add your paper keys.
Start the stack
Runs the bot plus a daily SQLite backup service. The health check reads the bot's heartbeat file.
Attach to the dashboard
The terminal dashboard is the interface. Detach with Ctrl-P then Ctrl-Q.
config/settings.py end to end, and keep ALPACA_LIVE=false until you understand every limit. Velox is experimental software and carries real risk of loss.Command reference
velox run [--live] [--diagnose]Run the bot here with the live dashboard.velox start / stopRun in the background, or stop gracefully.velox status [--watch]Heartbeat, open positions, recent trades.velox killClose all positions and cancel all orders.velox healthExit 0 if the heartbeat is fresh.velox backtestBaselines on CSV or yfinance data, or --strategy velox.velox tearsheet --days 90Performance report from the trade database.velox demoThe dashboard with synthetic data.velox strategiesStrategies, allocations and baselines.Where things live
Roughly 51,000 lines of Python in a flat set of packages, with about 1,500 tests.
velox.py # the CLI: run, status, kill, backtest, ... main.py # startup, position recovery, the main trading loop dashboard.py # Rich live terminal dashboard config/ # every strategy and risk parameter (settings.py) database.py # SQLite: trades, positions, snapshots, signal log engine/ # the trading engine scanner.py # strategy scans, adaptive intervals signal_processor.py# the 18-step pipeline exit_orchestrator.py # 10-level exit cascade broker_sync.py # reconciliation with the broker daily_tasks.py # daily reset, weekly tasks, EOD close strategies/ # StatMR, KalmanPairs, PEAD, VWAP, MicroMomentum, ORB risk/ # circuit breaker, VaR, correlation, vol targeting, P&L lock oms/ # order state machine, idempotency, kill switch execution/ # bracket orders, TWAP, chase logic ml/ # features, ensemble inference, training, FinBERT analytics/ # metrics, OU fitting, Hurst, HMM regimes backtesting/ # Monte Carlo, classic baselines data/ # market data, feed monitor, sample CSVs compliance/ ops/ # audit trail, PDT rule; disaster recovery, tax harvesting tests/ # pytest suite
Where Velox came from
Velox grew over twelve major versions. In 2026 it absorbed two earlier projects and became terminal-only.
AlphaFlow
A Python and FastAPI trading platform for Alpaca with a strategy engine, backtester, risk manager and a React interface. Velox is its direct successor.
Trading Algorithms
A Rust workspace with SIMD indicators and a backtester. Its MA-crossover, RSI, momentum and Bollinger strategies now live on as Velox's backtest baselines.
Terminal only
The web dashboard, Prometheus and Grafana were removed. A velox command, a terminal kill switch and a heartbeat health check replaced them.