How rajmaurya0904/bhav works
Bhav is an NSE options backtesting product with CLI and web entry points. Users configure a run and provide a Python strategy; the runner loads live Upstox or offline workbook data, resolves contracts, simulates bars and portfolio costs, computes metrics and Monte Carlo robustness, then writes run artifacts for the dashboard. Strategy generation and validation form a separate capability. The graph follows relationships shown in excerpts or the README; unsampled API, frontend, and runtime wiring is represented conservatively.
Main entry points: bar_engine.py Bar engine · cli.py Bhav CLI · server.py Runs API · writer.py Result writer
Components 28
Run interfaces
- Bhav CLI
bhav/cli.py - Runs API
bhav/api/server.py - Web UI
frontend/app/new/page.tsx - Run dashboard
frontend/app/backtests/[id]/page.tsx
Market data
- Upstox API
- Upstox client
bhav/data/upstox_client.py - Contract resolver
bhav/data/instruments.py - Live data reader
bhav/data/reader.py - Candle cache
bhav/data/cache.py - Workbook source
bhav/data/excel_source.py - Trading calendar
bhav/data/calendar.py - Underlying rules
bhav/data/underlyings.py - Futures roll
bhav/data/futures.py
Backtest simulation
- User strategy
bhav/engine/strategy.py - Bar engine
bhav/engine/bar_engine.py - Portfolio ledger
bhav/engine/portfolio.py - Indian cost model
bhav/engine/costs.py
Results and analysis
- Performance metrics
bhav/metrics/report.py - Monte Carlo
bhav/metrics/montecarlo.py - Result writer
bhav/output/writer.py - Run artifacts
Strategy generation
- Claude CLI
- Strategy generator
bhav/ai/claude_generator.py - Strategy prompt
bhav/ai/prompt.py - AST safety gate
bhav/ai/validate.py - AI frontend client
frontend/lib/ai-prompt.ts
Other components
- CLI user
- Web user
Connections 37
- CLI user → Bhav CLI: runs backtest
- Web user → Web UI: configures run
- Web UI → Runs API: submits run
- Runs API → Bar engine: launches run
bhav/api/server.py - Bhav CLI → Bar engine: runs simulation
bhav/cli.py - Bhav CLI → Workbook source: selects offline data
bhav/cli.py - Bhav CLI → Live data reader: selects live reader
bhav/cli.py - Bhav CLI → Contract resolver: selects live resolver
bhav/cli.py - Bhav CLI → Performance metrics: computes metrics
bhav/cli.py - Bhav CLI → Monte Carlo: bootstraps trades
bhav/cli.py - Bhav CLI → Result writer: writes results
bhav/cli.py - Upstox client → Upstox API: requests candles
bhav/data/upstox_client.py - Contract resolver → Upstox client: loads contracts
bhav/data/instruments.py - Live data reader → Upstox client: fetches candles
bhav/data/reader.py - Live data reader → Candle cache: reads and writes
bhav/data/reader.py - Bar engine → Live data reader: reads bars
bhav/engine/bar_engine.py - Bar engine → Contract resolver: resolves options
bhav/engine/bar_engine.py - Bar engine → Trading calendar: gets trading days
bhav/engine/bar_engine.py - Bar engine → Underlying rules: gets lot size
bhav/engine/bar_engine.py - Bar engine → Futures roll: rolls future
- Bar engine → User strategy: dispatches bars
bhav/engine/bar_engine.py - Bar engine → Portfolio ledger: updates positions
bhav/engine/bar_engine.py - Portfolio ledger → Indian cost model: prices and charges
bhav/engine/portfolio.py - Performance metrics → Portfolio ledger: reads trades and equity
bhav/metrics/report.py - Monte Carlo → Portfolio ledger: resamples trades
bhav/metrics/montecarlo.py - Result writer → Portfolio ledger: serializes trades
bhav/output/writer.py - Result writer → Performance metrics: serializes metrics
bhav/output/writer.py - Result writer → Monte Carlo: serializes robustness
bhav/output/writer.py - Result writer → Run artifacts: writes artifacts
bhav/output/writer.py - Runs API → Run artifacts: lists run artifacts
bhav/api/server.py - Run dashboard → Runs API: loads run details
- AI frontend client → Runs API: requests generation
- Runs API → Strategy generator: generates strategy
bhav/api/server.py - Strategy generator → Claude CLI: drives CLI
bhav/ai/claude_generator.py - Strategy generator → Strategy prompt: builds prompt
bhav/ai/claude_generator.py - Strategy generator → AST safety gate: validates output
bhav/ai/claude_generator.py - AST safety gate → Runs API: guards uploads