Problem Statement: 6) AI for the Indian Investor
Chart Pattern Intelligence — Real-time technical pattern detection (breakouts, reversals, support/resistance, divergences) across the full National Stock Exchange (NSE) universe — with plain-English explanation and historical back-tested success rates for that pattern on that specific stock
Full-universe NSE EQ scanning · intraday structure · same-code backtests · Gemini-powered explanations
A production-style MVP: rotate through the NSE equity registry, detect chart patterns on fresh 5m/15m bars, aggregate a screener and sector heatmap, and serve a Next.js desk UI with charts, timelines, and optional Google Gemini JSON narratives—while daily history backtests use the same deterministic pattern engine for consistency.
| Area | What you get |
|---|---|
| Universe | NSE EQUITY_L.csv (EQ) → SQLite registry; optional sector_map.json + name heuristics |
| Live detection | pattern_logic on intraday OHLCV (Yahoo Finance, TTL cache) |
| Backtests | Same detect_all_at_index slid over daily bars; configurable horizon & success threshold |
| Scanner | Background batches → scan_results |
| AI | Structured Gemini output when GEMINI_API_KEY is set; template fallback otherwise |
| UI | Multi-page app: Overview, Opportunities, Sector heat, Stock terminal (?symbol= deep links) |
Backend: FastAPI · SQLAlchemy · SQLite · Pandas / NumPy · yfinance · httpx · python-dotenv
Frontend: Next.js 15 · React 19 · Tailwind CSS · Recharts · Lucide
ET_GenAI/
├── backend/
│ ├── app/
│ │ ├── main.py # API + lifespan (scanner)
│ │ ├── core/ # config, settings
│ │ ├── db/ # SQLAlchemy models
│ │ ├── services/ # universe, ingest, scanner, patterns, AI, backtest
│ │ └── ...
│ ├── data/
│ │ └── sector_map.json # optional symbol → sector / cap overrides
│ ├── requirements.txt
│ └── .env # create locally (not committed)
├── frontend/
│ ├── app/(app)/ # routed pages: /, /opportunities, /heatmap, /terminal
│ ├── components/
│ └── ...
└── README.md
- Python 3.11+ (recommended)
- Node.js 20+ and npm
- Outbound HTTPS (NSE CSV, Yahoo, Gemini if used)
cd backend
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtCreate backend/.env (see Environment below). Then:
uvicorn app.main:app --reload --port 8000First-time registry: call sync so the DB has EQ symbols (UI: Sync universe, or HTTP below):
POST http://localhost:8000/api/universe/syncThe scanner starts with the app and processes symbols in batches (SCANNER_BATCH_SIZE, SCANNER_INTERVAL_SEC in config).
cd frontend
npm install
npm run devOpen http://localhost:3000.
If the API is not on port 8000, set:
# frontend/.env.local
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000| Variable | Where | Purpose |
|---|---|---|
GEMINI_API_KEY |
backend/.env |
Enables Gemini JSON explanations (AI Studio key) |
GEMINI_MODEL |
backend/.env |
Optional override (default gemini-2.0-flash) |
GEMINI_API_BASE |
backend/.env |
Optional API base URL |
DATABASE_URL |
backend/.env |
Optional; default SQLite backend/data/cpi.db |
NEXT_PUBLIC_API_BASE_URL |
frontend/.env.local |
Backend origin for browser fetches |
Verify Gemini: GET http://localhost:8000/api/ai/ping → ok: true when the key and model work.
| Method | Path | Notes |
|---|---|---|
GET |
/health |
Liveness + scanner flag |
POST |
/api/universe/sync |
Refresh NSE listing into DB |
GET |
/api/universe/stats |
Active EQ count |
GET |
/api/universe/symbols?q=&limit= |
Symbol search (registry) |
GET |
/api/screener/opportunities |
Filtered list (paginated cap) |
GET |
/api/screener/opportunities-full |
Full evaluation rows + filter notes |
GET |
/api/screener/heatmap |
Per-sector bull/bear counts |
GET |
/api/stocks/insight?symbol= |
Chart, signals, backtests, AI, timeline |
GET |
/api/ai/ping |
Gemini connectivity check |
| Path | Purpose |
|---|---|
/ |
Dashboard overview |
/opportunities |
Full screener table → links to terminal |
/heatmap |
Sector signal heat |
/terminal |
Watchlist, chart, insight; use ?symbol=TCS |
- Intraday data drives live signals; daily bars drive historical backtest stats so multi-year samples stay meaningful.
- Detection logic is shared (
pattern_logic); only the OHLCV timeframe differs. - This software is for research and education, not personalized investment advice.
Use a repository rooted in this folder (not your user home directory).
- On GitHub: New repository → name it (e.g.
nse-chart-pattern-intelligence), leave empty (no README/license if you will push existing files).
cd path\to\ET_GenAI
git init
git add .
git commit -m "Initial commit: NSE Chart Pattern Intelligence MVP"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO.git
git push -u origin mainUse SSH if you prefer: git@github.com:YOUR_USERNAME/YOUR_REPO.git
If git status shows your entire home directory, either run the commands above from ET_GenAI only after git init there, or clone a fresh repo and copy the project in.
Add a LICENSE file when you decide how you want to share the code (e.g. MIT).