Your first backtest
From zero to a backtest you can see, in about five minutes. (Engine details are handled for you — you just write Python.)
1. Install + scaffold
curl -fsSL https://signal-ai-mu.vercel.app/install.sh | sh # the signalai CLI
pip install signalai-quant # the Python library
signalai login # opens your browser to sign in
signalai init my_strategy.py
2. Write a strategy
A tiny mean-reversion idea: buy when a bar closes red, sell when it closes green. You subclass Strategy, subscribe to bars, and place orders — you never touch an engine.
from signalai_quant import Strategy, Bar, Side, OrderType
class MyStrategy(Strategy):
def init(self):
self.subscribe(Bar, self.on_bar)
def on_bar(self, bar):
held = self.portfolio[bar.symbol].qty
if bar.close < bar.open and held == 0:
self.order(bar.symbol, Side.BUY, 10, OrderType.MARKET)
elif bar.close > bar.open and held > 0:
self.order(bar.symbol, Side.SELL, held, OrderType.MARKET)
3. Submit it
Backtest it in the cloud over years of real data:
signalai submit my_strategy.py --symbols AAPL --from 2015-01-01 --to 2024-12-31
signalai status <id>
When it finishes, view the equity curve, trades, and stats at your backtests:
- equity curve — account value over time
- trades — every fill (timestamp, side, qty, price)
- stats — return, max drawdown, Sharpe
What to try next
- Switch to
--resolution minuteto backtest it as an intraday strategy. - Browse the SDK reference for every method you can call.