Option Strategies
Short Put Calendar Spread
Introduction
Put calendar spread, also known as put horizontal spread, is a combination of a longer-term (far-leg/front-month) put and a shorter-term (near-leg/back-month) put, where both puts have the same underlying stock and the same strike price. The short put calendar spread consists of selling a longer-term put and buying a shorter-term put. This strategy profits from an increase in price movement.
Implementation
Follow these steps to implement the short put calendar spread strategy:
- In the
Initializeinitializemethod, set the start date, end date, cash, and Option universe. - In the
OnDataon_datamethod, select the strike price and expiration dates of the contracts in the strategy legs. - In the
OnDataon_datamethod, select the contracts and place the orders.
private Symbol _symbol;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(500000);
UniverseSettings.Asynchronous = true;
var option = AddOption("GOOG", Resolution.Minute);
_symbol = option.Symbol;
option.SetFilter(universe => universe.IncludeWeeklys().PutCalendarSpread(0, 30, 60));
} def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(500000)
self.universe_settings.asynchronous = True
option = self.add_option("GOOG", Resolution.MINUTE)
self._symbol = option.symbol
option.set_filter(lambda universe: universe.include_weeklys().put_calendar_spread(0, 30, 60))
The PutCalendarSpreadput_calendar_spread filter narrows the universe down to just the two contracts you need to form a short put calendar spread.
public override void OnData(Slice slice)
{
if (Portfolio.Invested ||
!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}
// Get the ATM strike
var atmStrike = chain.OrderBy(x => Math.Abs(x.Strike - chain.Underlying.Price)).First().Strike;
// Select the ATM put Option contracts
var puts = chain.Where(x => x.Strike == atmStrike && x.Right == OptionRight.Put);
if (puts.Count() == 0) return;
// Select the near and far expiry contracts
var expiries = puts.Select(x => x.Expiry).ToList();
var nearExpiry = expiries.Min();
var farExpiry = expiries.Max(); def on_data(self, slice: Slice) -> None:
if self.portfolio.invested:
return
# Get the OptionChain
chain = slice.option_chains.get(self._symbol, None)
if not chain:
return
# Get the ATM strike
atm_strike = sorted(chain, key=lambda x: abs(x.strike - chain.underlying.price))[0].strike
# Select the ATM put Option contracts
puts = [i for i in chain if i.strike == atm_strike and i.right == OptionRight.PUT]
if len(puts) == 0:
return
# Select the near and far expiry dates
expiries = sorted([x.expiry for x in puts])
near_expiry = expiries[0]
far_expiry = expiries[-1]
Approach A: Call the OptionStrategies.ShortPutCalendarSpreadOptionStrategies.short_put_calendar_spread method with the details of each leg and then pass the result to the Buybuy method.
var optionStrategy = OptionStrategies.ShortPutCalendarSpread(_symbol, atmStrike, nearExpiry, farExpiry); Buy(optionStrategy, 1);
option_strategy = OptionStrategies.short_put_calendar_spread(self._symbol, atm_strike, near_expiry, far_expiry) self.buy(option_strategy, 1)
Approach B: Create a list of Leg objects and then call the Combo Market Ordercombo_market_order, Combo Limit Ordercombo_limit_order, or Combo Leg Limit Ordercombo_leg_limit_order method.
var nearExpiryPut = puts.Single(x => x.Expiry == nearExpiry);
var farExpiryPut = puts.Single(x => x.Expiry == farExpiry);
var legs = new List<Leg>()
{
Leg.Create(nearExpiryPut.Symbol, 1),
Leg.Create(farExpiryPut.Symbol, -1)
};
ComboMarketOrder(legs, 1); near_expiry_put = [x for x in puts if x.expiry == near_expiry][0]
far_expiry_put = [x for x in puts if x.expiry == far_expiry][0]
legs = [
Leg.create(near_expiry_put.symbol, 1),
Leg.create(far_expiry_put.symbol, -1)
]
self.combo_market_order(legs, 1)
Strategy Payoff
The short put calendar spread is a limited-reward-limited-risk strategy. The payoff is taken at the shorter-term expiration. The payoff is
$$ \begin{array}{rcll} P^{\textrm{short-term}}_T & = & (K - S_T)^{+}\\ P_T & = & (P^{\textrm{short-term}}_T - P^{\textrm{long-term}}_T + P^{\textrm{long-term}}_0 - P^{\textrm{short-term}}_0)\times m - fee \end{array} $$ $$ \begin{array}{rcll} \textrm{where} & P^{\textrm{short-term}}_T & = & \textrm{Shorter term put value at time T}\\ & P^{\textrm{long-term}}_T & = & \textrm{Longer term put value at time T}\\ & S_T & = & \textrm{Underlying asset price at time T}\\ & K & = & \textrm{Strike price}\\ & P_T & = & \textrm{Payout total at time T}\\ & P^{\textrm{short-term}}_0 & = & \textrm{Shorter term put value at position opening (debit paid)}\\ & P^{\textrm{long-term}}_0 & = & \textrm{Longer term put value at position opening (credit received)}\\ & m & = & \textrm{Contract multiplier}\\ & T & = & \textrm{Time of shorter term put expiration} \end{array} $$The following chart shows the payoff at expiration:
The maximum profit is the net credit received, $P^{\textrm{long-term}}_0 - P^{\textrm{short-term}}_0$. It occurs when the underlying price moves very deep ITM or OTM so the values of both puts are close to zero.
The maximum loss is undetermined because it depends on the underlying volatility. It occurs when $S_T = S_0$ and the spread of the 2 puts are at their maximum.
If the Option is American Option, there is a risk of early assignment on the contract you sell. Additionally, if you don't close the put positions together, the naked short put will have unlimited drawdown risk after the long put expires.
Example
The following table shows the price details of the assets in the short put calendar spread algorithm:
| Asset | Price ($) | Strike ($) |
|---|---|---|
| Shorter-term put at position opening | 11.30 | 800.00 |
| Longer-term put at position opening | 19.30 | 800.00 |
| Longer-term put at shorter-term expiration | 3.50 | 800.00 |
| Underlying Equity at shorter-term expiration | 828.07 | - |
Therefore, the payoff is
$$ \begin{array}{rcll} P^{\textrm{short-term}}_T & = & (K - S_T)^{+}\\ & = & (800.00-828.07)^{+}\\ & = & 0\\ P_T & = & (-P^{\textrm{long-term}}_T + P^{\textrm{short-term}}_T - P^{\textrm{short-term}}_0 + P^{\textrm{long-term}}_0)\times m - fee\\ & = & (-3.50+0-11.30+19.30)\times100-1.00\times2\\ & = & 448\\ \end{array} $$So, the strategy gains $448.
The following algorithm implements a short put calendar spread Option strategy:
public class OptionStrategy : QCAlgorithm
{
private Symbol _equity;
private Symbol _symbol;
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetEndDate(2024, 12, 31);
SetCash(500000);
var option = AddOption("GOOG", Resolution.Minute);
_symbol = option.Symbol;
option.SetFilter(universe => universe.IncludeWeeklys().PutCalendarSpread(0, 30, 60));
}
public override void OnData(Slice slice)
{
if (Portfolio.Invested) return;
// Get the OptionChain of the symbol
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
// get at-the-money strike
var atmStrike = chain.OrderBy(x => Math.Abs(x.Strike - chain.Underlying.Price)).First().Strike;
// filter the put options from the contracts which is ATM in the option chain.
var puts = chain.Where(x => x.Strike == atmStrike && x.Right == OptionRight.Put);
if (puts.Count() == 0) return;
// sorted the optionchain by expiration date
var expiries = puts.Select(x => x.Expiry).OrderBy(x => x);
// select the farest expiry as far-leg expiry, and the nearest expiry as near-leg expiry
var nearExpiry = expiries.First();
var farExpiry = expiries.Last();
var optionStrategy = OptionStrategies.ShortPutCalendarSpread(_symbol, atmStrike, nearExpiry, farExpiry);
// We open a position with 1 unit of the option strategy
Buy(optionStrategy, 1);
}
} class PutCalendarSpreadStrategy(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2024, 9, 1)
self.set_end_date(2024, 12, 31)
self.set_cash(500000)
option = self.add_option("GOOG", Resolution.MINUTE)
self.symbol = option.symbol
option.set_filter(self.universe_func)
def universe_func(self, universe: OptionFilterUniverse) -> OptionFilterUniverse:
return universe.include_weeklys().put_calendar_spread(0, 30, 60)
def on_data(self, data) -> None:
# avoid extra orders
if self.portfolio.invested: return
# Get the OptionChain of the self.symbol
chain = data.option_chains.get(self.symbol, None)
if not chain: return
# get at-the-money strike
atm_strike = sorted(chain, key=lambda x: abs(x.strike - chain.underlying.price))[0].strike
# filter the put options from the contracts which is ATM in the option chain.
puts = [i for i in chain if i.strike == atm_strike and i.right == OptionRight.PUT]
if len(puts) == 0: return
# sorted the optionchain by expiration date
expiries = sorted([x.expiry for x in puts], key = lambda x: x)
# select the farest expiry as far-leg expiry, and the nearest expiry as near-leg expiry
near_expiry = expiries[0]
far_expiry = expiries[-1]
option_strategy = OptionStrategies.short_put_calendar_spread(self.symbol, atm_strike, near_expiry, far_expiry)
# We open a position with 1 unit of the option strategy
self.buy(option_strategy, 1)
def on_end_of_algorithm(self) -> None:
for symbol, sec in self.securities.items():
self.log(f"{symbol} :: {sec.price}")
Other Examples
For more examples, see the following algorithms: