HARSH KAWATRA

DOSSIER 01

A trading brain that grades its own homework

An autonomous research system for NSE equities: a four-layer model ensemble that generates signals, paper-trades them, and re-weights itself every market day on what actually happened.

Python · FastAPI · LightGBM · Kronos · TimescaleDB · React


The setup

Retail screeners surface patterns; none of them close the loop. A signal without a recorded outcome, a resolved P&L, and a consequence for the model that produced it is an opinion, not a system.

StockSense treats a trading decision as a pipeline with an audit trail — and treats yesterday’s outcomes as tomorrow’s training signal.

A confident number is not the same as a correct one.

The machine

±0.10 nudgehourly re-weightingNSE OHLCV · news RSSTimescaleDB hypertablesA · LightGBM40+ features · SHAPB · Kronos1–5 day price pathsC · Macro layer14-sector sentimentWeighted combinegate ≥ 0.55 confidenceD · LLM synthesisconfirm / reject + learningsauto_trade → auto_exitpaper P&L · audit log
PLATE 01 — The four-layer signal ensemble. A LightGBM directional prior (A) and a Kronos time-series forecast (B) are fused with a macro sentiment nudge (C) in a weighted combine, gated at 0.55 confidence, and confirmed or rejected by an LLM synthesis pass (D). Resolved outcomes re-weight the combine hourly.

The hard parts

On the record

The pipeline fires every thirty minutes during market hours. For each of roughly 2,500 tradeable names it loads ~300 daily candles, computes 40-plus engineered features, and asks four models in sequence: a LightGBM classifier supplies the directional prior with its top five SHAP features attached 1; a fine-tuned Kronos foundation model maps a one-to-five-day price path, from which the system interpolates a fractional “touches target in ~2.5 days” estimate; a small macro model scores fourteen sectors from live headlines and nudges confidence by at most ±0.10; and an LLM synthesis pass confirms or rejects the survivors.

The part worth reading twice is not the ensemble but the loop around it. Signals that clear the 0.55 confidence gate are paper-bought automatically, monitored every thirty minutes, and exited on target, stop, or expiry. Resolved trades become structured learnings that are injected into the next cycle’s synthesis prompt as retrieval context 2. Rolling per-model accuracy re-weights the combine hourly, and a drift tracker retrains the LightGBM model when accuracy decays 3.

Validated out of sample by year, the ensemble held 57% directional accuracy 4. The more valuable finding was where it failed — see the errata.

The numbers

MeasureValueSource
Universe~2,475 live EQ/BE namesticker_sync, delisted names pruned
Cadencesignals every 30 min in market hoursAPScheduler, 12 IST cron jobs
Directional accuracy57% out-of-samplevalidation split by year
Autonomybuy, monitor, exit — no manual buttonsauto_trader.py; watch-only holdings excluded

Errata & Failures

The re-weighting overfit

The hourly re-weighting looked strong in backtest and decayed out of sample: it was overfitting to recent market regimes. That failure changed how I work — I stopped trusting a model because it returned a confident number and started asking whether it was actually right.

Thin evidence, no tuning

In quiet periods many signals expire without touching target or stop. The nightly calibration deliberately refuses to tune on such weak evidence and records zero changes — silence is a valid calibration result.

■ References

Repository ↗