Options strategies

Strategy specs: an options strategy as data, with no code

How Veloce describes an options strategy as a JSON spec, field by field, with a real iron condor example, validation errors, and sweeps that vary spec fields.

By
Veloce team
Published
Reading time
10 min read
On this page
  1. Why describe a strategy as data
  2. A real spec: the reference iron condor
  3. The parts of a spec
  4. Legs, hedges first
  5. Signals and bearish legs
  6. Your own indicator rules
  7. When a spec is wrong
  8. Running a spec
  9. Sweeping spec fields
  10. What to sweep, and what not to
  11. What a spec cannot express
  12. Questions traders ask
  13. Try it in Veloce

A strategy spec describes an options strategy as data instead of code: a JSON document that says which candles to use, when to enter, which legs to open, when to exit, what limits apply and what each trade costs. Veloce validates the spec against a published schema, compiles it into a strategy and backtests it on one-minute data, with fills at the next candle’s open and itemised charges. Because the strategy is data, a sweep can vary any field in it by name. This guide walks through a real spec, field by field, shows what happens when one is wrong, and explains how sweeps vary spec fields such as legs.2.strike.steps.

Why describe a strategy as data

Writing a strategy in code is flexible but has costs: every strategy is a new program, every change needs testing, and two strategies that differ in one number are two copies of nearly the same code. A spec trades some flexibility for three things:

  • Checked before it runs. A spec that sells a leg with no side, or squares off before its last entry, is rejected with the exact field, before any data is fetched.
  • Comparable. Two specs that differ in one field differ only in that field. The run history stores the full spec with each run.
  • Sweepable. Any number, time or choice in the spec can be varied in a sweep by its path.

The same spec can be edited in the app’s strategy builder, written by hand in a file, or sent to the API.

A real spec: the reference iron condor

This is Veloce’s reference weekly iron condor, with whitespace compacted:

{
  "name": "iron-condor",
  "description": "sell weekly iron condors",
  "candle_minutes": 1,
  "entry": {
    "signal": null,
    "signal_cutoff": null,
    "first_entry": "10:00:00",
    "last_entry": null,
    "weekdays": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"],
    "min_days_to_expiry": 5,
    "reenter": "each_expiry"
  },
  "lots": 1,
  "legs": [
    { "kind": "option", "option_type": "put", "side": "buy", "ratio": 1,
      "strike": { "kind": "atm_offset", "steps": 8 }, "expiry": { "kind": "nth", "rank": 1 } },
    { "kind": "option", "option_type": "call", "side": "buy", "ratio": 1,
      "strike": { "kind": "atm_offset", "steps": 8 }, "expiry": { "kind": "nth", "rank": 1 } },
    { "kind": "option", "option_type": "put", "side": "sell", "ratio": 1,
      "strike": { "kind": "atm_offset", "steps": 4 }, "expiry": { "kind": "nth", "rank": 1 } },
    { "kind": "option", "option_type": "call", "side": "sell", "ratio": 1,
      "strike": { "kind": "atm_offset", "steps": 4 }, "expiry": { "kind": "nth", "rank": 1 } }
  ],
  "bearish_legs": [],
  "square_off": null,
  "exits": {
    "group_by": "expiry",
    "rules": [
      { "kind": "take_profit", "amount": { "kind": "share_of_credit", "fraction": "0.5" } },
      { "kind": "stop_loss", "amount": { "kind": "share_of_credit", "fraction": "2" } },
      { "kind": "before_expiry", "days": 1 }
    ]
  },
  "risk": { "rules": [], "daily_loss_limit": null },
  "day": { "exit_by": null, "target": null, "stop": null, "skip": null },
  "costs": {
    "charges": [{ "kind": "index_options", "stt_rate": null }],
    "fill": { "kind": "next_open" },
    "slippage": { "kind": "ticks", "ticks": 1 }
  }
}

Read in plain words: on one-minute candles, from 10:00 on any day when the nearest expiry is at least five calendar days away, open once per expiry: buy the put and the call eight strike steps out of the money, sell the put and the call four steps out, all in the nearest expiry. Treat the four legs as one position. Close it at half the credit in profit, at a loss of twice the credit, or one day before expiry. Charge NSE or BSE index option charges, fill at the next candle’s open, and add one tick of slippage.

On NIFTY, with 50-point strikes, four steps is 200 points and eight steps is 400 points. On BANK NIFTY or SENSEX, with 100-point strikes, the same spec opens the shorts 400 points out and the wings 800 points out. The spec counts steps, not points, so it carries across indices.

The parts of a spec

Every axis that can vary is a list of kinds. Each kind is an object with a kind field naming it and its own settings.

Part Field Kinds and settings
Candles candle_minutes 1 to 1,440 minutes, built from one-minute data
Entry entry.signal moving_average_cross, ema_cross, supertrend_flip, rsi_reversal, macd_trend, opening_range_breakout, rules, or null to enter whenever the other entry rules allow
entry.first_entry, last_entry Earliest and latest candle close to enter on
entry.weekdays, min_days_to_expiry Which days to enter, and how close to expiry is too close
entry.reenter when_flat, each_day or each_expiry
Legs legs, bearish_legs option (call or put, buy or sell, ratio, strike, expiry) or underlying (the future itself)
Strike legs.N.strike atm_offset (steps from the money, −50 to 50) or closest_premium (the strike trading nearest a premium)
Expiry legs.N.expiry nth (1 for the nearest) or at_least_days_away
Exits exits.group_by leg (each contract alone) or expiry (all legs of an expiry together)
exits.rules stop_loss, take_profit, trailing_stop, before_expiry
Amounts inside exit rules rupees, share_of_credit, share_of_cost, share_of_peak
Risk risk.rules max_lots, equity_share, gross_exposure, cash, futures_margin, max_loss_at_expiry
risk.daily_loss_limit Rupees lost in a day after which only closing trades are allowed
Day day exit_by time, daily target and stop (in rupees or a share of equity), days to skip (weekdays, expiry days)
Costs costs.charges index_options, mcx_futures, or your own per_order, on_turnover and tax lines
costs.fill, costs.slippage next_open; none, ticks or share_of_price

Some rules span fields and are checked together: last_entry must be before square_off, bearish_legs need a signal, a spec needs legs or bearish legs, and signal_cutoff needs a signal.

Legs, hedges first

Legs open in the order listed. List hedges before the legs they protect. The max-loss-at-expiry risk rule never lets a sold call exceed the calls already bought in that expiry, so with that rule on, a spec that listed the short call before its hedge would have the short call cut.

Signals and bearish legs

With a signal, legs open on a bullish signal and bearish_legs on a bearish one. Without a signal, legs open whenever the entry rules allow and bearish_legs must be empty. The moving average crossover guide, opening range breakout guide and MACD guide each show a signal spec.

Your own indicator rules

The rules signal combines indicators with conditions. Indicators are named, and conditions compare them with each other or with a number using crosses_above, crosses_below, above or below. The reference gold futures spec uses a 9 and 21 EMA cross:

{
  "kind": "rules",
  "indicators": [
    { "name": "fast", "kind": "ema", "period": 9 },
    { "name": "slow", "kind": "ema", "period": 21 }
  ],
  "bullish": [{ "left": "fast", "comparison": "crosses_above", "right": "slow" }],
  "bearish": [{ "left": "fast", "comparison": "crosses_below", "right": "slow" }]
}

Bullish holds when every bullish condition holds on the same candle, and likewise for bearish.

When a spec is wrong

A spec is checked in full before any data is fetched, and every problem is reported with its field path. Changing the opening range breakout spec so that it enters from 14:00 but stops entering at 13:00, and giving its first leg the side “hold”, produces exactly these two problems:

entry: first_entry must not be after last_entry, got 14:00:00 > 13:00:00
legs.0.side: Input should be 'buy' or 'sell'

The path tells you where to look: legs.0.side is the side of the first leg. The same paths are what a sweep uses.

Running a spec

The strategy builder in the app edits the same spec through a form generated from the schema, and each backtest is stored in your run history with the spec that produced it. For programs, the HTTP API serves the spec’s JSON schema at GET /api/specs/schema, the reference specs at GET /api/specs/examples, and accepts {spec, underlying, from, to, capital} at POST /api/backtests.

Sweeping spec fields

A sweep backtests every combination of values at the field paths you name, ranks them by net P&L on the tuning period and, with a check end date, reruns the best few on the period after.

Field paths. Object fields and list positions, counted from 0, joined by dots. legs.2.strike.steps is the strike steps of the third leg, the short put in the iron condor. The kind of a union is left out of the path: it is legs.2.strike.steps, not legs.2.strike.atm_offset.steps.

Values. Read the way the spec reads text: 2 is a number and 15:00 is a time.

To vary the short strikes of the iron condor, both sides together, sweep legs.2.strike.steps and legs.3.strike.steps over 3, 4 and 5.

That is nine combinations: every pair of put and call distances. To keep the condor symmetric, vary one side and accept that the other stays at four, or run three separate specs.

Rejected combinations are skipped, not fatal. A combination the spec rejects is listed with the problem at its field path, in its place, and the sweep goes on. Varying the iron condor’s short put distance and its stop multiple, with one invalid value, gives:

Settings Result
legs.2.strike.steps 3, exits.rules.1.amount.fraction 1 runs
legs.2.strike.steps 3, exits.rules.1.amount.fraction -1 skipped: exits.rules.1.amount.fraction: Input should be greater than 0
legs.2.strike.steps 4, exits.rules.1.amount.fraction 1 runs
legs.2.strike.steps 4, exits.rules.1.amount.fraction -1 skipped: same reason

A path that names no field at all (a typo such as legs.2.strik.steps) stops the sweep with an error naming the path, because no combination could ever run. Each field can be varied once per sweep.

spec legs 2: sell put strike steps legs.2.strike.steps = 3, 4, 5 list positions count from 0; the union kind atm_offset is left out
How a field path names one value inside a spec.

What to sweep, and what not to

Sweep fields that express a real choice you are unsure of: the short strike distance, the wing width, the entry time, the take-profit share, the days before expiry to exit. Avoid sweeping many fields at once: three values each for four fields is 81 combinations, and the best of 81 is very likely to look better than it is. The walk-forward guide explains what the check period does and does not prove, and the Monte Carlo guide how to judge luck in a single result.

One check worth doing with the iron condor: its stop at two times the credit can only fire when the credit is less than a third of the wing width. The option selling guide works through why. Sweeping exits.rules.1.amount.fraction and seeing identical results for every value is a sign the stop never triggered.

What a spec cannot express

A spec is a fixed vocabulary. It cannot:

  • Adjust a position by rolling a tested leg further out while keeping the others.
  • Pick a leg from another leg’s price, such as buying the wing that costs a quarter of the short’s premium (though closest_premium picks a strike by its own premium).
  • Compute something new, beyond the built-in signals and the indicators available to rules.

When a strategy needs one of those, the spec grows by adding a new kind to the relevant axis: a dataclass with a kind, a member of that axis’s list and a builder that turns it into strategy parts. Every kind is covered by the same schema, form and sweep paths as soon as it exists.

Questions traders ask

Is a spec the same as a strategy template? It is more specific: a template usually fixes the structure and lets you change a few numbers. A spec describes the whole strategy, including the costs and risk limits, and every field can be changed.

Can I share a spec? A spec is a JSON file, so it can be copied, versioned and compared like any text file. Two specs can be diffed line by line to see exactly how two strategies differ.

Does the spec include costs? Yes. Charges, fill price and slippage are part of the spec, so a result can always be traced to the costs that produced it. The charges guide explains the index option charges, and the slippage guide the slippage kinds.

Do lot sizes go in the spec? No. The spec counts lots; the lot size in units comes from the exchange’s schedule for each expiry date, so a spec run across the January 2026 NIFTY lot change from 75 to 65 is priced correctly on both sides of it.

Try it in Veloce

Veloce runs strategy specs on NIFTY 50 weekly, BANK NIFTY monthly and SENSEX weekly options and on MCX gold and gold mini futures, on one-minute data with next-open fills, slippage and itemised charges. Start from a reference spec in the strategy builder, see the strategies page for the built-in ones, and the parameter sweeps page for varying spec fields with a held-back check period. Paper trading on live data and live trading through Zerodha are coming soon.

Create a free Veloce account and open the iron condor spec in the builder. For the method behind a sound test, see how to backtest an options strategy.

Frequently asked questions

What is a strategy spec?
A JSON document that describes a whole strategy: the candle size, when to enter, which option legs to open, when to exit, the risk limits and the trading costs. Veloce checks it against a schema, compiles it into a strategy and backtests it on recorded one-minute data. No code is written.
Can I backtest an options strategy in Veloce without coding?
Yes. The strategy builder in the app edits a spec through a form, and you can also paste or edit the spec as JSON. Both produce the same spec and the same backtest.
How do I vary a spec field in a sweep?
Name the field by its path, with object fields and list positions counted from 0 separated by dots, and list the values: legs.2.strike.steps=3,4,5 tries the third leg's strike at 3, 4 and 5 steps from the money. Every combination of the varied fields is backtested, and combinations the spec rejects are skipped with the reason.
What happens if my spec has a mistake?
Veloce rejects it before fetching any data and lists every problem with the field path it applies to, such as legs.0.side: Input should be 'buy' or 'sell'. Nothing runs until the spec is valid.
Which markets can a spec trade?
NIFTY 50 and BANK NIFTY options on NSE, SENSEX options on BSE, and MCX gold and gold mini futures. The same option spec runs on any of the three indices; strikes are counted in that index's strike steps.
What can a spec not express?
Anything outside its fields: adjustments that roll a leg when the market moves, legs that depend on other legs' prices, or custom calculations beyond the built-in signals and indicator rules. Those need new kinds added to the spec, which is how it grows.
Will the same spec run in paper or live trading?
Paper trading on live data and live trading through Zerodha are coming soon. The engine is built so that the same strategy runs unchanged in each, with only the data source and the order executor swapped.

Sources

  1. JSON Schema: specificationjson-schema.org, accessed
  2. NSE circular NSE/FAOP/70616: revision in market lot of derivative contracts on indices (October 3, 2025)nsearchives.nseindia.com, accessed
  3. Union Budget 2026-27, Memorandum explaining the provisions of the Finance Bill (STT on options and futures)indiabudget.gov.in, accessed
esc
↑↓Move↵Open