Natural language → backtested → optimized → live trading strategies.
- Describe — type a trading idea in plain English
- Parse — Claude converts it to executable Python using vectorbt
- Backtest — runs it against historical OHLCV data (Yahoo Finance)
- Optimize — Bayesian search (Optuna) finds the best parameters
- Suggest — Claude analyzes results and recommends improvements
- Deploy — paper or live execution via Alpaca or Zerodha
strategyai/
├── backend/
│ ├── main.py # FastAPI app + all routes
│ ├── config.py # Settings (reads from .env)
│ ├── celery_app.py # Async task queue
│ ├── requirements.txt
│ ├── Dockerfile
│ ├── models/
│ │ └── schemas.py # Pydantic request/response models
│ ├── services/
│ │ ├── strategy_parser.py # Claude NLP → code
│ │ ├── backtester.py # vectorbt backtest engine
│ │ ├── optimizer.py # Optuna parameter search
│ │ ├── risk_manager.py # Pre-trade risk controls
│ │ └── broker.py # Alpaca / paper broker adapter
│ └── routers/
│ └── async_tasks.py # Async job polling endpoints
├── frontend/
│ ├── index.html
│ ├── vite.config.js
│ ├── package.json
│ └── src/
│ ├── main.jsx
│ ├── App.jsx # Root — step machine
│ ├── index.css
│ ├── lib/
│ │ └── api.js # Typed API client
│ ├── hooks/
│ │ └── useTaskPoller.js # Long-running job polling
│ └── components/
│ ├── StrategyInput.jsx
│ ├── CodeView.jsx
│ ├── BacktestDashboard.jsx
│ ├── Suggestions.jsx
│ ├── ExecutionPanel.jsx
│ └── Stepper.jsx
├── scripts/
│ └── example_strategies.py # Test strategies without the server
├── docker-compose.yml
├── .env.example
└── .gitignore
git clone <your-repo>
cd strategyai
cp .env.example .env
# Edit .env — set ANTHROPIC_API_KEY at minimumdocker-compose up --build- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API docs: http://localhost:8000/docs
Backend:
cd backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reloadFrontend:
cd frontend
npm install
npm run devWorker (for async jobs):
# Redis must be running first
docker run -d -p 6379:6379 redis:7-alpine
cd backend
celery -A celery_app worker --loglevel=info| Method | Endpoint | Description |
|---|---|---|
| POST | /api/parse |
NLP → strategy code |
| POST | /api/backtest |
Run backtest (sync) |
| POST | /api/backtest/async |
Run backtest (async, returns task_id) |
| POST | /api/suggestions |
Get Claude improvement tips |
| POST | /api/optimize |
Run parameter optimization (sync) |
| POST | /api/optimize/async |
Run optimization (async) |
| GET | /api/task/{id} |
Poll async task status |
| POST | /api/risk/check |
Pre-trade risk gate |
| GET | /api/risk/status/{session} |
Current risk state |
| POST | /api/execute/order |
Place paper or live order |
| GET | /api/execute/positions/{broker}/{mode} |
Open positions |
Write a function with this signature and pass strategy_code directly to /api/backtest:
import pandas as pd
import numpy as np
def generate_signals(data: pd.DataFrame):
# data has columns: Open, High, Low, Close, Volume
# Return two boolean Series: (entries, exits)
close = data["Close"]
sma20 = close.rolling(20).mean()
entries = close > sma20
exits = close < sma20
return entries, exits| Goal | Where to change |
|---|---|
| Add a new broker | Subclass BrokerBase in services/broker.py |
| Add new data source | Add a function alongside fetch_ohlcv in backtester.py |
| Add optimization objectives | Extend _score_backtest in optimizer.py |
| Add risk rules | Add methods to RiskManager in risk_manager.py |
| Change AI model | Update model= in strategy_parser.py |
This software is for educational and research purposes only. Algorithmic trading involves significant financial risk. Past backtest performance does not guarantee future results. Never trade with capital you cannot afford to lose.