Trade and Portfolio. We run a delta-hedged short ATM straddle on COM.BRN so we can see both code paths in action: option greeks from OptionValues and the future fallback (delta=1, gamma=theta=vega=0).
Imports
Strategy
A minimal delta-hedged short ATM straddle. Each month it opens an ATM call + ATM put (short), then on every pulse it hedges the net delta with a front-month future (opens or rebalances).Run
Output
Equity

Portfolio-level greeks per pulse
The portfolio keeps no greek aggregate, so the book’s exposure is built from the trades: each trade’s*_contract_history runs in lock-step with its own datetimes, and summing them per pulse gives the net position. Delta should oscillate near zero if the hedge is working; gamma/theta/vega come from the option legs only.

Per-trade greeks (option leg)
Pick the first call leg and plot its per-unit and size-multiplied greek histories. Per-unit delta should sit in[-1, 0] for a short call; delta_contract = delta * units should track the same shape, scaled by quantity.
Output

Per-leg greeks across the backtest
Stitch every trade’s history together by leg type (call / put / future). The three legs should roughly offset: the call and put are short with opposite-signed deltas, and the future hedge brings the sum near zero each pulse. Gamma/theta/vega come from the option legs only - the future contributes zero by construction.
Future hedge: quantity and units
Each hedge trade is a future, and futures are not traded in lots here (is_lots=False), so units == quantity. The plot below shows how the hedge size evolves - it gets rebalanced every pulse to offset the option legs’ net delta, and a new future is opened each month when the previous one is closed at the monthly reset.
Output


