A cross-sectional momentum analytics platform for the NSE 500 — ingests daily trading data for all 500 constituents, computes ranked performance across configurable time windows, runs algorithmic backtests, and surfaces everything through a live dashboard with sector breakdowns, return distributions, and a searchable, exportable leaderboard.
| Module | Status |
|---|---|
| Cross-sectional screener | ✅ Complete — KPI cards, sector breakdown, return histogram, sortable/paginated table, CSV export, watchlist |
| Momentum analytics | ✅ Complete — dual-lookback ranking, confirmation filter, top-N portfolio selection |
| Algo backtest | ✅ Complete — momentum strategy with configurable lookback windows, equity curve, risk metrics, period-by-period breakdown |
| CLI tool | ✅ Complete — standalone interactive terminal script, 8 pytest cases passing |
| File | Purpose |
|---|---|
app/main.py |
FastAPI application entry point: CORS middleware, route registration, /api/health and /api/market-status endpoints |
app/nse_client.py |
NSE data layer: constituent list fetcher, bhavcopy downloader, index-close archive reader, trading-day fallback logic, tenacity retry with exponential backoff |
app/compare.py |
Core comparison engine: two-date performance calculation, per-stock backfill for missing symbols, sector aggregation, return-distribution histogram bucketing |
app/momentum.py |
Momentum signal engine: dual-lookback scoring (short + long window), confirmation filter, top-N ranking |
app/backtest.py |
Backtesting engine: monthly rebalancing loop, equity curve construction, Sharpe ratio, max drawdown, win rate, period-by-period return log |
app/cache.py |
In-memory TTL cache: immutable bhavcopy files cached forever, constituent list cached 12h |
app/disk_cache.py |
Persistent disk cache: Parquet-backed storage for downloaded data files |
app/schemas.py |
Pydantic response models: typed schemas for all API responses |
| File | Purpose |
|---|---|
app/page.tsx |
Dashboard page: period selector, KPI cards, sector chart, histogram, data table |
app/backtest/page.tsx |
Backtest page: parameter controls, equity curve, risk metrics, period breakdown table |
components/KpiCards.tsx |
Summary cards: top gainer, top loser, median return, advance/decline ratio |
components/DataTable.tsx |
Sortable, searchable, paginated stock table with star-to-watchlist and inline alerts |
components/SectorPanel.tsx |
Sector performance bar chart (Recharts) |
components/DistributionChart.tsx |
Return distribution histogram (Recharts) |
components/EquityCurveChart.tsx |
Backtest equity curve line chart (Recharts) |
components/RiskMetricsCards.tsx |
Backtest risk metrics display: Sharpe, max drawdown, win rate |
components/PeriodsTable.tsx |
Backtest period-by-period breakdown table |
components/BacktestControls.tsx |
Backtest parameter input form: date range, lookback windows, top-N, confirmation toggle |
components/TickerTape.tsx |
Scrolling ticker tape of top movers |
components/DateRangeControl.tsx |
Period preset buttons (1W / 1M / 3M / 6M / 1Y / YTD) |
components/Header.tsx |
Navigation header with page links |
components/StatusPill.tsx |
Market open/closed status indicator |
components/LoadingSkeleton.tsx |
Skeleton loading placeholder |
components/ErrorBanner.tsx |
Error state display banner |
lib/api.ts |
API client: typed fetch wrappers for /api/compare, /api/backtest, /api/market-status |
lib/csv.ts |
Client-side CSV export from filtered/sorted table data |
lib/types.ts |
TypeScript type definitions for API response shapes |
lib/format.ts |
Number and date formatting utilities |
lib/useWatchlist.ts |
React hook: localStorage-persisted watchlist (star/unstar) |
| File | Purpose |
|---|---|
nse_stock_info.py |
Standalone interactive terminal script: live snapshot fetch, bhavcopy fallback, per-stock backfill, percentage change calculation, CSV export |
NSE public data archives FastAPI backend Next.js dashboard
(constituent list, ────────▶ fetch · cache · retry ───▶ charts · table
daily price files, compute analytics KPIs · export
index close values) JSON API
The backend does all NSE-specific work — fetching, trading-day fallback for weekends/holidays, per-stock backfill for suspended or newly-listed symbols, sector aggregation, histogram bucketing, and momentum scoring — so the frontend just renders whatever JSON comes back.
| Layer | Stack |
|---|---|
| Backend | Python, FastAPI, pandas, nsepython, tenacity (retry/backoff), pyarrow |
| Frontend | Next.js 14 (App Router), TypeScript, Tailwind CSS, Recharts |
| CLI | Python, pandas, nsepython |
| Endpoint | Description |
|---|---|
GET /api/health |
Liveness check |
GET /api/market-status |
Whether NSE is currently in trading hours (IST) |
GET /api/compare |
Full comparison dataset for a given date range |
GET /api/backtest |
Momentum backtest with equity curve and risk metrics |
GET /api/compare query parameters:
| Param | Values | Notes |
|---|---|---|
end |
today (default) or YYYY-MM-DD |
|
period |
1w 1m 3m 6m 1y ytd custom |
|
start |
YYYY-MM-DD |
Required only when period=custom |
GET /api/backtest query parameters:
| Param | Values | Notes |
|---|---|---|
start |
YYYY-MM-DD |
Backtest start date |
end |
YYYY-MM-DD |
Backtest end date |
top_n |
Integer (default 30) |
Number of top-ranked stocks to hold |
short_lookback_months |
Integer (default 1) |
Short momentum lookback window |
long_lookback_months |
Integer (default 6) |
Long momentum lookback window |
require_confirmation |
Boolean (default true) |
Require both lookbacks to agree |
- Python 3.10+
- Node.js 18+
cd backend
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn app.main:app --reload --port 8000The API is now running at http://localhost:8000 (interactive docs at http://localhost:8000/docs).
Open a new terminal (leave the backend running), then:
cd frontend
cp .env.local.example .env.local
npm install
npm run devOpen http://localhost:3000 — the dashboard should load with live data.
Two independent test suites, since they cover different layers:
# CLI script (interactive input, CSV output)
cd cli && pip install -r requirements-dev.txt && pytest tests/ -v
# Backend API (async functions, HTTP endpoints, JSON responses)
cd backend && pip install -r requirements-dev.txt && pytest -v46 tests total (8 CLI + 38 backend), all passing.
| Data | Source | Cache policy |
|---|---|---|
| NIFTY 500 constituent list (symbol, company, sector) | NSE static archive | Cached 12h (changes only at semi-annual reconstitution) |
| Daily stock prices (open/high/low/close/volume/turnover) | NSE daily bhavcopy files | Cached indefinitely (immutable once published) |
| Official NIFTY 500 index value (OHLC) | NSE daily index-close archive | Cached indefinitely (immutable once published) |
All three sources are fetched with automatic fallback to the nearest prior trading day (for weekends/holidays) and retry with exponential backoff on transient network errors.
This is a two-service app:
- Frontend → Vercel: import the repo, set root directory to
frontend/, setNEXT_PUBLIC_API_URLto your deployed backend URL - Backend → Railway or Render: point at
backend/, start commanduvicorn app.main:app --host 0.0.0.0 --port $PORT
Before going live, update the CORS allow_origins list in backend/app/main.py from ["*"] to your actual frontend origin.
- Corporate actions (stock splits, bonus issues) are not adjusted for — a split between the selected start and end dates will show as a false large loss
- Symbol renames/mergers are not tracked across multi-year comparisons
- End-of-day data only — "today" resolves to the most recently published daily close, not an intraday tick feed
- No authentication — built as a single-user tool, not multi-tenant
- Cross-sectional momentum signal layer (dual-lookback windows, not just single-period return)
- Parquet-backed historical storage for reproducible backtesting
- YAML-driven configuration for deterministic universe construction
- Risk module (VaR, CVaR, Markowitz optimization)