Skip to content

Feat: Adding support for equity markets in india#305

Open
muku314115 wants to merge 1 commit into
HKUDS:mainfrom
muku314115:feat/india-equity-support
Open

Feat: Adding support for equity markets in india#305
muku314115 wants to merge 1 commit into
HKUDS:mainfrom
muku314115:feat/india-equity-support

Conversation

@muku314115

Copy link
Copy Markdown

Summary

  • Add first-class Indian equity (NSE/BSE) support across the full stack: data ingestion → dedicated backtest engine → equity_in factor universe → live/paper broker + mandate wiring.
  • New IndiaEquityEngine modeling T+1 delivery, no overnight shorts (allow_short opt-in), configurable circuit bands, 1-share lots, and the STT / stamp-duty / exchange / SEBI / GST cost stack.
  • Route .NS/.BO symbols to Yahoo (native NSE/BSE coverage), with yfinance and an opt-in Shoonya/Dhan broker data bridge as fallbacks.

Why

Indian symbols previously had zero research support: they silently misrouted to China infrastructure (tushare loader + ChinaAEngine), producing wrong fills and costs. India was the only market with
live broker connectors (Shoonya/Dhan) but no data/backtest/factor path. This wires the broken middle so the existing strategies, factors, and metrics work on NSE/BSE.

Changes

  • Data ingestion: .NS/.BO routing in market_data.py + _market_hooks.py (new india_equity market type); extended yahoo_loader/yahoo_client and yfinance_loader to accept the suffixes;
    india_equity fallback chain in registry.py; runner.py source map. Regexes allow &/- (e.g. M&M.NS, BAJAJ-AUTO.NS).
  • Engine: new backtest/engines/india_equity.py; wired into composite.py and runner.py single-market routing (precedes source-based routing so India's yahoo source can't fall through to the
    crypto default).
  • Factors: added equity_in to the Universe literal and Market enum (vwap uses the typical-price branch — India bars carry raw price/volume, no Tushare scaling); tagged all 101 Alpha101 and 154
    QLib158 factors for equity_in. GTJA191 left China-only (Tushare-scale math).
  • Live/paper: added AssetClass.IN_EQUITY and wired it into the mandate-enforcement loader chain; new backtest/loaders/india_broker_loader.py bridges Shoonya/Dhan get_historical_bars into the
    backtest layer (opt-in india_broker source, unavailable without broker creds). Live order placement stays structurally disabled (those brokers expose no paper/live switch).
  • Docs: SKILL.md updated (8 engines, 19 sources, India symbol convention, factor coverage, paper/read-only-live limitation).
  • Cost-stack rates and circuit band are config-driven defaults (documented), not magic constants.

Test Plan

  • Existing tests pass (pytest --ignore=agent/tests/e2e_backtest --tb=short -q)
  • New tests added — test_india_equity_engine.py, test_india_backtest_smoke.py, test_india_mandate.py, test_india_broker_loader.py, tests/factors/test_india_universe.py, plus India cases in
    test_market_data.py, test_market_detection.py, test_yahoo_loader.py, test_registry.py
  • Tested manually — registry loads 456 factors (0 failures), 255 listed for equity_in; representative Alpha101/QLib158 factors compute on a synthetic NSE panel; end-to-end India backtest emits metrics
  • run card and shows India costs applied vs the zero-commission US engine; factor purity + lookahead gates pass (911); tools/ci_grep_gates.sh all gates pass; ruff check clean across the contribution
    footprint

Checklist

  • No changes to protected areas (src/agent/, src/session/, src/providers/) without prior discussion
  • No hardcoded values (API keys, file paths, magic numbers) — India cost/band defaults are config-overridable
  • Code follows CONTRIBUTING.md guidelines — ruff check (the configured gate) passes on all new/changed files; public signatures type-annotated; Google-style docstrings
  • Documentation updated (if user-facing change) — SKILL.md

Reviewer notes

  • The first Test Plan box is left unchecked: I verified targeted suites + ruff locally, but not the full pytest --ignore=agent/tests/e2e_backtest run (the sandbox lacks some optional deps, e.g.
    fastmcp). Please let CI confirm the full suite.
  • Exact SEBI/STT/exchange tariffs and any F&O lot sizes should be verified against a current broker schedule before relying on absolute cost figures (rates change periodically); they're exposed as config
    knobs.
  • The india_broker bridge returns a bounded window of recent bars (broker API limit) — use Yahoo for deep history.
  • black was not run: the repo is not black-conformant (untouched core files fail black -l120), so formatting only these files would diverge from house style. Files conform to the configured ruff gate
    instead.

@warren618

Copy link
Copy Markdown
Collaborator

Thanks for the PR — we’ve seen it and will review as soon as we can.

For market-support changes, the main things we’ll check are symbol conventions, loader/data-source behavior, deterministic tests, and whether the first version stays narrowly scoped enough to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants