Sumitx369/Paper_Trading_Backtesting
2
๐ Paper Trading Backtester (Indian stocks)
A paper-trading / strategy-backtesting platform for Indian equities (NSE/BSE). Users define a trading strategy two ways โ by editing a small code template or with a no-code condition builder โ and a fast C++ engine backtests it against historical data pulled from yfinance.
Architecture
Browser (Plotly UI)
โ JWT
โผ
FastAPI โโโบ yfinance + cache (parquet + in-memory TTL)
โ
โ buy/sell expressions โโบ DSL compiler โโบ bytecode + indicator specs
โผ
C++ engine (pybind11) โโบ indicators + expression VM + portfolio sim
โ
โผ
metrics (return, Sharpe, max-DD, win-rate, vs Buy&Hold) + equity/trades- API: FastAPI (JWT auth, SQLite via SQLAlchemy).
- Strategy input compiles to a single JSON expression spec โ bytecode. No user code is ever executed โ code mode is parsed with Python's
astover a strict whitelist (c.rsi(14),c.close,c.crossover(...), โฆ). - Engine: C++ (built with pybind11, no CMake). Computes SMA/EMA/RSI/MACD/Bollinger/ATR, evaluates buy/sell conditions per bar, simulates a long-only portfolio with fees+slippage.
- Market: Indian stocks. NSE tickers
RELIANCE.NS, BSEโฆโ.BO; values in โน. Lookback capped at 1 year; intraday intervals are validated against yfinance limits.
Run locally (conda)
# one-time: build the C++ engine + install deps into the env
conda run -n trading_testing pip install -r requirements.txt
conda run -n trading_testing pip install . # builds `trading_engine`
# run the API + UI
conda run -n trading_testing uvicorn app.main:app --reload --port 8000
# open http://localhost:8000Tests:
conda run -n trading_testing pytest -qRun with Docker
docker build -t trading-backtester .
docker run -p 7860:7860 -e JWT_SECRET=$(openssl rand -hex 32) trading-backtester
# open http://localhost:7860Deploy (Hugging Face Spaces)
Create a Docker Space, push this repo, and set a JWT_SECRET secret. The YAML header at the top of this README configures the Space (port 7860). Note: free-tier storage is ephemeral โ the SQLite DB resets on rebuild. Swap DATABASE_URL to a free Postgres (e.g. Neon) for durable accounts.
