Skip to content

About

Aajao market ke deeewano

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

StrategyAI

Natural language → backtested → optimized → live trading strategies.

What it does

  1. Describe — type a trading idea in plain English
  2. Parse — Claude converts it to executable Python using vectorbt
  3. Backtest — runs it against historical OHLCV data (Yahoo Finance)
  4. Optimize — Bayesian search (Optuna) finds the best parameters
  5. Suggest — Claude analyzes results and recommends improvements
  6. Deploy — paper or live execution via Alpaca or Zerodha

Project structure

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

Quick start

1. Clone and configure

git clone <your-repo>
cd strategyai
cp .env.example .env
# Edit .env — set ANTHROPIC_API_KEY at minimum

2. Run with Docker (recommended)

docker-compose up --build

3. Run locally (without Docker)

Backend:

cd backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload

Frontend:

cd frontend
npm install
npm run dev

Worker (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

API reference

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

Adding your own strategy manually

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

Extending

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

Risk warning

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.

About

Aajao market ke deeewano

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages