Quick Start
This guide gets you from zero to a backtested AI trading agent in under 15 minutes. You’ll set up your environment, write a simple trading agent using Backtrader, upload it to our platform for backtesting, and view your performance metrics and tier badge.
Prerequisites
You’ll need basic Python knowledge and a Spooky Labs account. Don’t have an account yet? Join the waitlist.
Step 1: Create Your Agent
Create a file named agent.py with the following code:
import backtrader as bt
from chronos import ChronosPipeline
import torch
class Agent(bt.Strategy):
params = (
('lookback', 20),
('model_name', 'amazon/chronos-t5-small'),
)
def __init__(self):
self.forecaster = ChronosPipeline.from_pretrained(
self.params.model_name,
device_map="auto",
torch_dtype=torch.float32
)
def prenext(self):
self.next()
def next(self):
for d in self.datas:
if len(d) < self.params.lookback:
continue
prices = list(d.close.get(size=self.params.lookback))
context = torch.tensor(prices).unsqueeze(0)
forecast = self.forecaster.predict(context, prediction_length=1)
predicted = forecast[0].mean().item()
pos = self.getposition(d).size
if not pos and predicted > d.close[0]:
size = int(self.broker.getcash() * 0.15 / d.close[0])
self.buy(data=d, size=size)
elif pos and predicted < d.close[0]:
self.close(data=d)
Important requirements:
Your agent must follow these requirements exactly or the backtest will fail:
- File must be named exactly
agent.py - Class must be named exactly
Agent - Must extend
bt.Strategy - Must implement
__init__(),prenext(), andnext() prenext()must callself.next()to avoid waiting for all indicator data
Step 2: Upload via Console
Now that you have your agent file, upload it to the platform. We’ll automatically backtest it against 2 years of historical market and news data from 2024 and 2025, with other data types coming soon, and generate performance metrics.
- Go to your Console
- Click the Upload Agent section
- Select your
agent.pyfile - Click Upload Agent
The platform will store your file securely, start a backtest automatically, show results in the Console once complete, and automatically rank your agent on the Leaderboard.
Step 3: View Your Results
Once the backtest completes, your agent card in the Console will show key performance metrics:
| Metric | Description |
|---|---|
| Portfolio Return | Total percentage return on $10,000 starting capital |
| Sharpe Ratio | Risk-adjusted return (higher = better) |
| Win Rate | Percentage of profitable trades |
| Tier Badge | Unranked / Bronze / Silver / Gold based on return % |
Click View Details to see the full performance breakdown including max drawdown, trade count, and profit factor.
What’s Next?
Your agent passed backtesting? Great! Now you can:
- Deploy to Paper Trading — Trade with live market data and $10,000 virtual capital
- Learn More About Writing Agents — Explore indicators, order types, and advanced patterns
- Understand Your Metrics — Learn what makes a good agent
Quick Reference
Agent Requirements
| Requirement | Value |
|---|---|
| Filename | agent.py (exactly) |
| Class name | Agent (exactly) |
| Base class | bt.Strategy |
| Required methods | __init__(), prenext(), next() |
Status Flow
The status of your agent, shown in both the Console and Agent Detail pages, follows this diagram:
Troubleshooting
Backtest failed? Check the following:
| Issue | Solution |
|---|---|
| Wrong filename | Your file must be named exactly agent.py. |
| Wrong class name | Your class must be named exactly Agent. |
| Missing prenext | You must implement def prenext(self): self.next(). |
| Syntax errors | Ensure there are no syntax errors in your Python code. |
See Troubleshooting for more help.