DEV Community

shakti tiwari
shakti tiwari

Posted on Originally published at optiontradingwithai.in

Building an AI Options-Trading Risk Filter (XGBoost + Guardrails)

Building an AI Options-Trading Risk Filter

Most retail AI trading projects fail not because the model is wrong, but because nothing sits between the model's probability and the trade. A predictor is a junior analyst; the risk filter is the risk manager. This post walks through a practical filter that wraps an XGBoost Nifty options signal.

Why a filter, not just a model

A model outputs a probability: "62% chance Nifty closes up." That number alone is dangerous. Without guardrails:

  • It trades through volatility spikes it was never trained to survive
  • It sizes by conviction, not by risk
  • It ignores that the underlying might be halting or the chain might be broken

The filter is where discipline becomes code.

The band check

We only act inside a calibrated probability band:

SAFE_BAND = (0.58, 0.80)
if not (0.58 <= p <= 0.80):
    block()   # too uncertain or too certain = skip
Enter fullscreen mode Exit fullscreen mode

Below 0.58 the edge is noise. Above 0.80 we distrust overconfident outputs (often regime-specific overfitting).

Volatility gate

India VIX as a z-score, not a level:

vix_z = (vix - vix_rolling_mean) / vix_rolling_std
if vix_z > 2:
    block()   # panic regime, stand aside
Enter fullscreen mode Exit fullscreen mode

Level alone lies; regime context is what matters.

Max-pain floor

If price is within 0.3% of max pain and DTE < 2, we cut size by half rather than block — writers tend to pin.

Sizing by risk, not lots

max_risk_pct = 0.02
if vix_z > 1.5:
    max_risk_pct *= 0.5
position = risk_budget / premium_at_risk
Enter fullscreen mode Exit fullscreen mode

Survival is a function of how small you go when wrong.

Validation before trust

Train walk-forward, never random-split. Report out-of-sample Sharpe next to in-sample. If out-of-sample is below half of in-sample, the model overfit. Inject synthetic nulls to test robustness. A filter cannot save a leaked model.

Wrap-up

The model proposes, the filter disposes, you own the risk. Build the guardrails first — they are the only part that survives a real drawdown.

Full research and free tools: https://optiontradingwithai.vercel.app (canonical: https://optiontradingwithai.in/shakti-tiwari/)

Shakti Tiwari — NISM XII certified. Educational only, not investment advice.

Top comments (0)