Skip to content

Repository files navigation

AlgoTrade Platform

Self-hosted algorithmic trading research system — data ingestion, backtesting, report persistence, and strategy visualization for Indian equity markets.

Built as a freelance contract for a trading firm. Production-grade, fully self-hosted, zero cloud dependency.


What This Is

A complete end-to-end quantitative research platform covering the full pipeline:

Module What it does
Data Ingestion Live OHLCV data from Groww API — NSE Equity, F&O, Index Spot, Index F&O. Incremental download, idempotent guarantees, OHLC validation, 5-sigma outlier detection. 12 datasets, 2,567+ persisted bars.
Backtesting Engine Event-driven bar feed, BaseStrategy abstraction, order simulation (market/limit/stop/bracket), slippage + commission models. Full metrics: Sharpe, Sortino, CAGR, Max Drawdown, VaR, Win Rate, Alpha/Beta vs NIFTY 50.
Report Store Immutable versioned reports — every run gets a UUID, metadata in PostgreSQL, artifacts (equity_curve.parquet, trades.parquet, report_full.json) on disk. Full audit trail, run_group linking for continuous backtesting.
Strategy Visualizer React + TypeScript + TradingView Lightweight Charts. Normalized equity comparison, side-by-side Sharpe/Return/Drawdown table, PDF/CSV export.

Stack

Python · FastAPI · PostgreSQL · Apache Parquet / PyArrow · React 18 · TypeScript · TradingView Lightweight Charts · Recharts · Tailwind CSS · SQLite (dev)


Screenshots

Image 18-03-26 at 3 56 PM (1) Image 18-03-26 at 3 56 PM Image 18-03-26 at 3 55 PM (1) Image 18-03-26 at 3 55 PM Image 18-03-26 at 3 54 PM Image 18-03-26 at 3 53 PM


  • algotrade/ingestion/ for Groww instrument and candle ingestion
  • algotrade/core/ for the event-driven backtesting engine
  • algotrade/api/ for the middleware and report store API
  • algotrade/orchestration/ for continuous run scheduling and orchestration
  • frontend/ for the strategy visualizer

Scope

The primary v1 path is:

  • Groww historical ingestion
  • Python backtesting
  • versioned report storage
  • web-based visualization and export

Yahoo is kept only as an optional demo fallback when Groww access is unavailable.

Quick Start

python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[dev]'
algotrade init-db
algotrade serve

Recommended for real Groww ingestion: use PostgreSQL instead of SQLite.

Create a local connection string once:

createdb algotrade
printf '%s' 'postgresql+psycopg:///algotrade' > .secrets/database_url

Then algotrade init-db will use PostgreSQL automatically.

In a second terminal:

cd frontend
npm install
npm run dev

Run A Real Backtest

1. Configure Groww

Set your token:

export ALGOTRADE_GROWW_API_TOKEN='your_token_here'

Or place it in:

  • .secrets/groww_api_token

2. Ingest instruments

algotrade ingest-instruments

For low-disk validation runs, ingest only the symbols you need:

algotrade ingest-instruments \
  --groww-symbol NSE-RELIANCE \
  --groww-symbol NSE-BANKNIFTY \
  --groww-symbol NSE-RELIANCE-30Mar26-FUT \
  --groww-symbol NSE-BANKNIFTY-30Mar26-FUT

3. Download candles

Examples:

algotrade ingest-candles NSE-RELIANCE 1D 2025-01-01 2025-03-01 --segment EQ
algotrade ingest-candles NSE-NIFTY 1D 2025-01-01 2025-03-01 --segment IDX
algotrade ingest-candles NSE-BANKNIFTY-28Apr26-38000-CE 1D 2026-01-01 2026-03-01 --segment IDX_FNO

Supported PRD-style segments:

  • EQ
  • EQ_FNO
  • IDX
  • IDX_FNO

4. Run the backtest engine

algotrade backtest strategies/momentum.py RELIANCE 1D 2025-01-01 2025-03-01 --segment EQ

The report is written under:

  • data/reports/<StrategyName>/<run_id>/

5. Run from the UI

Open:

  • http://127.0.0.1:5173

Then:

  1. Enter the workspace
  2. Go to Runs
  3. Use the Run backtest form
  4. Pick a strategy, instrument, timeframe, and date range
  5. Export report JSON, equity CSV, or trades CSV from the selected run

Demo Mode

If Groww is not available yet, use demo mode explicitly.

algotrade demo-bootstrap
algotrade backtest strategies/momentum.py RELIANCE 1D 2025-09-01 2026-03-13 --segment EQ

For ad hoc demo ingestion:

algotrade ingest-instruments --provider demo
algotrade ingest-candles RELIANCE 1D 2025-09-01 2026-03-13 --segment EQ --provider demo

Continuous Runs

algotrade register-continuous strategies/momentum.py RELIANCE 1D 2025-01-01 --segment EQ
algotrade scheduler --once

API Surface

  • GET /health
  • GET /dashboard/summary
  • GET /backtests/strategies
  • POST /backtests/execute
  • GET /runs
  • GET /runs/{run_id}/equity-curve
  • GET /runs/{run_id}/trades
  • GET /runs/{run_id}/report-full
  • GET /runs/{run_id}/equity-curve.csv
  • GET /runs/{run_id}/trades.csv
  • GET /strategies
  • GET /data/instruments
  • GET /data/candles
  • GET /scheduler/registrations
  • POST /scheduler/registrations
  • POST /scheduler/run-now

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages