Skip to content

psatam21/alphaengine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AlphaEngine

Open-source factor investing backtester for Indian equities (NSE).

Build, test, and analyze momentum, low-volatility, quality, and value strategies on 10+ years of Indian market data — in your browser, for free.

License: MIT Python React FastAPI PRs Welcome

What is this?

Factor investing selects stocks by measurable characteristics ("factors") that have historically predicted returns — the approach behind smart-beta funds worldwide, grounded in academic work by Fama-French and Carhart:

  • Momentum — stocks that went up tend to keep going up (3/6/9/12-month returns, with optional 1-month lag)
  • Low Volatility — calmer stocks have historically delivered better risk-adjusted returns
  • Quality — profitable, well-run companies (ROE, ROCE)
  • Value — cheap stocks by P/E, P/B, dividend yield

AlphaEngine lets you combine these into custom strategies (e.g., 30% momentum + 20% low-vol + 30% quality + 20% value), backtest them against Indian market history, and inspect CAGR, Sharpe ratio, drawdowns, and calendar-year returns.

Features

  • 4 factor families with multiple parameter choices each, plus multi-factor combinations with custom weights
  • 6 weighting methods: Equal, Market Cap, Inverse Market Cap, Factor-weighted, Market Cap × Factor, and more
  • Universe filtering: NSE 500, Nifty 200, and other index universes
  • Industry filters: Non-Financial / Financial-Lending / Financial-Non-Lending groups
  • Configurable rebalancing frequency and portfolio size, with score capping
  • Full analytics: equity curve vs benchmark, CAGR, Sharpe, max drawdown, calendar-year returns table
  • JWT-authenticated API with persistent backtest results

Architecture

flowchart LR
    A[React + Vite frontend] -->|Axios / JSON| B[FastAPI backend]
    B --> C[Backtest engine<br/>pandas + NumPy]
    C --> D[(SQLite<br/>prices, fundamentals,<br/>universes)]
Loading

Quick start

Backend (Python 3.10+):

cd backend
python -m venv venv && source venv/bin/activate   # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000

Frontend (Node 20+):

cd frontend
npm install
npm run dev        # opens http://localhost:5173

Default dev credentials are admin / admin123 — override with environment variables (see backend/.env.example) before deploying anywhere public.

Getting data

The engine reads from a SQLite database (backend/alphaengine.db, path configurable via DB_PATH). The database is not shipped in this repo — populate it with your own data (NSE bhavcopy, yfinance, or any vendor) using this schema:

CREATE TABLE scrips (
  symbol TEXT PRIMARY KEY, name TEXT NOT NULL, isin TEXT,
  industry_name TEXT, industry_type TEXT
);

CREATE TABLE daily_prices (
  symbol TEXT, date TEXT,
  open REAL, high REAL, low REAL, close REAL NOT NULL,
  volume INTEGER, free_float_market_cap REAL,
  PRIMARY KEY (symbol, date)
);

CREATE TABLE index_prices (
  index_name TEXT, date TEXT,
  open REAL, high REAL, low REAL, close REAL NOT NULL,
  PRIMARY KEY (index_name, date)
);

CREATE TABLE daily_metrics (
  symbol TEXT, date TEXT,
  pe_ratio REAL, pb_ratio REAL, volume REAL,
  volatility_90d REAL, beta_adj REAL, ev_to_ebitda REAL,
  PRIMARY KEY (symbol, date)
);

CREATE TABLE quarterly_metrics (
  symbol TEXT, date TEXT,
  profit_margin REAL, net_income REAL, operating_margin REAL,
  eps REAL, debt_to_equity REAL, ebitda REAL,
  PRIMARY KEY (symbol, date)
);

backend/ingest_data.py and backend/scripts/ contain ingestion helpers; backend/scripts/update_prices.py keeps prices current via yfinance.

Configuration

Env var Default Purpose
ADMIN_USERNAME admin Login username
ADMIN_PASSWORD admin123 Login password (change it)
ADMIN_JWT_SECRET dev default JWT signing secret (change it)
DB_PATH backend/alphaengine.db SQLite database location
VITE_API_URL auto Frontend → backend API base URL

Disclaimer

AlphaEngine is a research and educational tool. Backtest results are hypothetical, do not fully account for transaction costs, slippage, taxes, or survivorship bias, and are not investment advice or a recommendation to buy or sell any security.

Contributing

Contributions welcome — see CONTRIBUTING.md. Good first areas: new factor definitions, data ingestion adapters, analytics, and tests.

License

MIT © 2026 Prathamesh Satam

About

Open-source factor investing backtester for Indian equities (NSE) — momentum, low volatility, quality & value strategies on 10+ years of data

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages