Skip to main content

Plan: Cost-of-Carry and Arbitrage Intelligence (14 Oct 2026)

Reference: Cost of Carry (methodology, API, sample analysis).

Existing architecture found​

  • FastAPI routers in backend/app/api/*, registered in app/main.py behind require_min_rank("DEVELOPER"); sync data helpers run via run_in_threadpool; results as {success, data}.
  • Price history behind stores, never raw tables: eq_store (cash and index), fo_store (NSE F&O, monthly Parquet + 90-day staging), mcx_fo_store, mcx_spot_store (MonthStore instances). Masters: scr_master (typ 2 index, typ 3 futures), scr_mcx_master (typ 20 spot, typ 21 futures, unit and pricequote). scr_indexpepb.divyie, te_price (SBI FD).
  • Frontend: React 18 + Vite, recharts, Tailwind trading-* tokens, all calls in services/api.js, routes in App.jsx, links in Sidebar.jsx.
  • Pytest runs against the real local Postgres (tests/conftest.py).

Gaps found​

  1. MCX futures history 2009-03 to 2026-07 is absent locally (see follow-up 1).
  2. No dividend yield before 2012-02; financing series ends 2025-12-31.
  3. No bid-ask, margin or historical brokerage anywhere.
  4. No cost or tax module in the platform: BrokerageCalculator is a single current-rate Zerodha intraday approximation, unsuitable for a historical, effective-dated net carry, so carry/costs.py was added.

Built​

backend/carry/{calc,costs,data,service}.py, backend/app/api/carry.py, frontend page CarryDashboard.jsx, 83 tests. Migrations: none (derived results are cached in memory keyed by parameters, calc version and store dates; nothing persisted).

Follow-ups​

  1. Load MCX F&O history 2009-03 to 2026-07 locally (mcxeod.mcx_archive_import import, then mcx_fo_store export) or copy from the VPS; then Gold / Silver gain about 17 years. Re-run python -m scratch.coc_sample.
  2. Refresh the financing proxy beyond 2025-12 (add an MIBOR / repo / T-bill series to te_asset) so net carry stops relying on a carried-forward rate; the cost code only needs FIN_PROXY_CODE changed or a second source.
  3. Verify the statutory schedules in costs.SCHEDULES against circulars (especially STT from 2026-04).
  4. If margin or bid-ask data ever lands (broker API), feed the scanner's margin and liquidity fields.
  5. Optional: persist daily scanner snapshots to measure what happened after each classification (a real backtest would be the only way to claim win rate or Sharpe).