Delta Hedging
Use delta selectors to balance a position at entry and Adjustments to rebalance it during a backtest.
Portfolios supports single-strategy portfolios as well as portfolios combining multiple strategies. To apply portfolio-level delta hedging to one strategy, create a portfolio containing that strategy's backtest and configure its delta-hedging settings.
The examples below cover option-leg selection and adjustments. For portfolio-level delta hedging, see Portfolios.
Open the AI Editor to try the examples. See Create and run a backtest for the validation and execution workflow.
Balance a short strangle
Start with two short option legs:
- One call option: sold at around 160 DTE with the Strike closest to 10 delta. This leg will be referred to as
short_call. - One put option: sold at the same expiration as the call with the Strike selected to bring the whole structure (Short Call and Short Put together) closest to 0 delta. Practically that delta will also be around 10, but we’ve chosen to do this calculation dynamically. This leg will be referred to as
short_put.
The JSON below is a fragment to place inside the relevant Strategy Definition section; keep the other required fields.
"Structure": {
"Name": "ShortStrangle",
"Expirations": [
{
"Name": "160dte",
"DTE": "160",
"Min": 140,
"Max": 190
}
],
"Legs": [
{
"Name": "short_call",
"Qty": "-1",
"ExpirationName": "160dte",
"StrikeSelector": {
"Min": 5,
"Max": 15,
"Delta": "10"
},
"OptionType": "Call"
},
{
"Name": "short_put",
"Qty": "-1",
"ExpirationName": "160dte",
"StrikeSelector": {
"Min": 5,
"Max": 15,
"Delta": "leg_short_call_delta * -1"
},
"OptionType": "Put"
}
]
}
The delta selector for the short_put leg uses the previously defined short_call leg’s delta.
The resulting structure’s overall delta will be around 0.
Balance a three-leg structure
For a structure with more legs, use pos_delta to account for the legs selected so far. The following broken-wing butterfly example uses it to choose the final put leg.
Place this Legs array inside Structure and retain the other required fields, including the expiration named 160dte:
"Legs": [
{
"Name": "upper_long",
"Qty": "1",
"ExpirationName": "160dte",
"StrikeSelector": {
"Delta": "40"
},
"OptionType": "Put"
},
{
"Name": "short",
"Qty": "-2",
"ExpirationName": "160dte",
"StrikeSelector": {
"Delta": "30"
},
"OptionType": "Put"
},
{
"Name": "lower_long",
"Qty": "1",
"ExpirationName": "160dte",
"StrikeSelector": {
"Delta": "pos_delta"
},
"OptionType": "Put"
}
]
In the above example, the last leg’s (lower_long) delta is specified using a statement that is calculated based on the overall position delta so far.
At the time of the statement evaluation, two legs are already considered, and pos_delta represents their sum:
pos_delta = [ leg_upper_long_delta ] + [ leg_short_delta ]
= [1 x (-40)] + [-2 x (-30)]
= -40 + 60
= 20
If we take this delta value (which should be around: (2*30)-40=20) and choose the last (lower_long) leg using this delta value then the final put offsets the existing delta, giving an approximately delta-neutral position at entry.
Rebalance delta with Adjustments
Adjustments can rebalance an open position as its delta changes. Several built-in adjustment examples use this approach: move one option leg to a new strike so its delta offsets the other legs.
Example: SPX-Strangle-Adjusting
Open the AI Editor and select [SPX-Strangle-Adjusting], the built-in adjusting short-strangle template. It starts with a roughly delta-neutral short call and short put, then checks for adjustments each day, 30 minutes before market close.
- When
pos_delta > 5, moveshort_callto offset the remaining position delta. - When
pos_delta < -5, moveshort_putto offset the remaining position delta. - When delta is between −5 and +5, including the endpoints, neither adjustment condition is met.
The following Adjustment section comes from the built-in template. Place it at the top level of the Strategy Definition, alongside Structure, Entry, and Exit:
"Adjustment": {
"Schedule": {
"BeforeMarketCloseMinutes": "30",
"Every": "day"
},
"ConditionalAdjustments": {
"pos_delta > 5": {
"MoveLegAdjustment": {
"LegName": "short_call",
"StrikeSelector": {
"Delta": "abs(pos_delta - leg_short_call_delta) / abs(leg_short_call_qty)"
}
}
},
"pos_delta < -5": {
"MoveLegAdjustment": {
"LegName": "short_put",
"StrikeSelector": {
"Delta": "abs(pos_delta - leg_short_put_delta) / abs(leg_short_put_qty)"
}
}
}
},
"MaxAdjustmentCount": "5"
}
How the new delta is selected
The selector subtracts the leg being moved from pos_delta, leaving the delta of the other legs. It then divides the absolute value by the moved leg's absolute quantity to calculate the target delta per contract.
For example, suppose the short call contributes −10 delta and the short put contributes +20 delta. The position has +10 delta, so the call adjustment condition is met. For one short call contract, its new target is:
abs(10 - (-10)) / abs(-1) = 20
A short call selected at approximately 20 delta contributes approximately −20 position delta, offsetting the put's +20. The available strikes determine how close the position gets to zero.
The schedule and adjustment limit matter. This template checks at the scheduled time, rather than continuously. After five adjustments, a subsequent triggered adjustment causes the position to close because MaxAdjustmentCount has been reached.
Inspect the adjustments in Events Viewer and the resulting delta in Position Monitor. Use Clone to test a different delta threshold or schedule while keeping other settings unchanged.
Continue experimenting
Review position Greeks and inspect the result in Position Monitor. Use Clone to change one input at a time and compare runs.
For complete strategy examples, see the Strategy Library.