Commit graph

2 commits

Author SHA1 Message Date
Manohar
1fbc9279a4 fix: parse SENSEX weekly symbol format DD+MON+STRIKE (no year)
Angel One SENSEX weeklies use e.g. SENSEX26JUN77300PE where 26=day,
JUN=month, 77300=strike — no year in the symbol. The previous parser
tried YY+MON+DD, treating 26 as year and 77 as day, giving an invalid
date (2026-06-77) and returning null for ALL option positions.

Added Format 3: DD(1-2) + MON(3-letter) + STRIKE + TYPE
Year is inferred: current year, or next year if date is >7 days past.
Format 2 (YY+MON+DD) is left as-is so it still falls through to Format 3
when its parsed date is invalid (day=77 etc).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 16:02:50 +05:30
Manohar
dca5fea679 feat: add Analysis tab with position intelligence engine
Phase 1 of the position-tracker → analysis port:

Backend:
- src/ai/types.ts       — shared types (AnalysisInput, ClassifiedPosition, AnalysisResult, etc.)
- src/ai/greeks.ts      — added calcTheoreticalPrice() export for scenario analysis
- src/ai/classifier.ts  — pure-function position classifier (DEAD_WEIGHT/WORKING/UNDER_PRESSURE/HEDGE/DANGER_SHORT) with module-level hysteresis Map
- src/ai/portfolio-greeks.ts — aggregates per-unit Greeks × quantity into portfolio totals
- src/ai/risk-assessor.ts   — naked short detection, concentration, side imbalance, Greeks breach checks
- src/ai/scenario.ts        — P&L grid at ±100..±1000 spot moves per underlying
- src/ai/analyze.ts         — orchestrator: maps Position[] → AnalysisInput[], reads spot from market_cache, stores JSON in analysis_snapshots
- src/db/client.ts      — analysis_snapshots table + index
- src/tracker/poll.ts   — runAnalysis() called after every pollTick + forcePoll
- src/api/server.ts     — GET /api/analysis endpoint

Frontend (public/index.html):
- Multi-page nav with Dashboard | Analysis tabs (showView())
- Analysis view: summary cards (delta/theta/vega/risk level), action list (urgent positions sorted by urgency score), classification table with urgency bars, risk assessment details, scenario P&L grid per underlying
- loadAnalysis() + renderAnalysis() wired to tab switch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 14:07:24 +05:30