From 507205d7c66413d8275aa50356f173fc6e269d66 Mon Sep 17 00:00:00 2001 From: Alexandre Catarino Date: Wed, 26 Jul 2023 22:45:59 +0100 Subject: [PATCH] Adds Short Strangle Strategy --- .../25 Short Strangle/01 Introduction.html | 2 + .../25 Short Strangle/02 Implementation.php | 103 ++++++++++++++++++ .../25 Short Strangle/03 Strategy Payoff.html | 34 ++++++ .../25 Short Strangle/99 Example.php | 52 +++++++++ .../25 Short Strangle/metadata.json | 12 ++ 5 files changed, 203 insertions(+) create mode 100644 03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/01 Introduction.html create mode 100644 03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/02 Implementation.php create mode 100644 03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/03 Strategy Payoff.html create mode 100644 03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/99 Example.php create mode 100644 03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/metadata.json diff --git a/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/01 Introduction.html b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/01 Introduction.html new file mode 100644 index 0000000000..502af3a7af --- /dev/null +++ b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/01 Introduction.html @@ -0,0 +1,2 @@ +

Short Strangle is an Options trading strategy that consists of simultaneously selling an OTM put and an OTM call, where both contracts have the same underlying asset and expiration date. By doing so, the trader is essentially betting that the underlying asset will remain relatively stable and not experience significant price movements before the Options' expiration.

+

Compared to a short straddle, the net debit of a short strangle is lower since OTM Options are cheaper. Additionally, the winning range of a short straddle is wider and the strike spread is wider.

diff --git a/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/02 Implementation.php b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/02 Implementation.php new file mode 100644 index 0000000000..b219060273 --- /dev/null +++ b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/02 Implementation.php @@ -0,0 +1,103 @@ +

Follow these steps to implement the short strangle strategy:

+ +
    +
  1. In the Initialize method, set the start date, end date, cash, and Option universe.
  2. +
    +
    private Symbol _symbol;
    +
    +public override void Initialize()
    +{
    +    SetStartDate(2017, 4, 1);
    +    SetEndDate(2017, 4, 30);
    +    SetCash(100000);
    +
    +    var option = AddOption("GOOG");
    +    _symbol = option.Symbol;
    +    option.SetFilter(-5, 5, 0, 30);
    +}
    +
    def Initialize(self) -> None:
    +    self.SetStartDate(2017, 4, 1)
    +    self.SetEndDate(2017, 4, 30)
    +    self.SetCash(100000)
    +        
    +    option = self.AddOption("GOOG")
    +    self.symbol = option.Symbol
    +    option.SetFilter(-5, 5, 0, 30)
    +
    + +
  3. In the OnData method, select the expiration date and strike prices of the contracts in the strategy legs.
  4. +
    +
    public override void OnData(Slice slice)
    +{
    +    if (Portfolio.Invested ||
    +        !slice.OptionChains.TryGetValue(_symbol, out var chain))
    +    { 
    +        return;
    +    }
    +
    +    // Find options with the farthest expiry
    +    var expiry = chain.Max(contract => contract.Expiry);
    +    var contracts = chain.Where(contract => contract.Expiry == expiry).ToList();
    +
    +    // Order the OTM calls by strike to find the nearest to ATM
    +    var callContracts = contracts
    +        .Where(contract => contract.Right == OptionRight.Call &&
    +            contract.Strike > chain.Underlying.Price)
    +        .OrderBy(contract => contract.Strike).ToArray();
    +    if (callContracts.Length == 0) return;
    +
    +    // Order the OTM puts by strike to find the nearest to ATM
    +    var putContracts = contracts
    +        .Where(contract => contract.Right == OptionRight.Put &&
    +            contract.Strike < chain.Underlying.Price)
    +        .OrderByDescending(contract => contract.Strike).ToArray();
    +    if (putContracts.Length == 0) return;
    +
    +    var callStrike = callContracts[0].Strike;
    +    var putStrike = putContracts[0].Strike;
    +}
    +
    def OnData(self, slice: Slice) -> None:
    +    if self.Portfolio.Invested:
    +        return
    +
    +    chain = slice.OptionChains.get(self.symbol)
    +    if not chain:
    +        return
    +
    +    # Find options with the farthest expiry
    +    expiry = max([x.Expiry for x in chain])
    +    contracts = [contract for contract in chain if contract.Expiry == expiry]
    +     
    +    # Order the OTM calls by strike to find the nearest to ATM
    +    call_contracts = sorted([contract for contract in contracts
    +        if contract.Right == OptionRight.Call and
    +            contract.Strike > chain.Underlying.Price],
    +        key=lambda x: x.Strike)
    +    if not call_contracts:
    +        return
    +        
    +    # Order the OTM puts by strike to find the nearest to ATM
    +    put_contracts = sorted([contract for contract in contracts
    +        if contract.Right == OptionRight.Put and
    +           contract.Strike < chain.Underlying.Price],
    +        key=lambda x: x.Strike, reverse=True)
    +    if not put_contracts:
    +        return
    +
    +    call_strike = call_contracts[0].Strike
    +    put_strike = put_contracts[0].Strike
    +
    + +
  5. In the OnData method, call the OptionStrategies.Strangle method and then submit the order.
  6. +
    +
    var shortStrangle = OptionStrategies.ShortStrangle(_symbol, callStrike, putStrike, expiry);
    +Buy(shortStrangle, 1);
    +
    short_strangle = OptionStrategies.ShortStrangle(self.symbol, call_strike, put_strike, expiry)
    +self.Buy(short_strangle, 1)
    +
    + + +
\ No newline at end of file diff --git a/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/03 Strategy Payoff.html b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/03 Strategy Payoff.html new file mode 100644 index 0000000000..ef29cac722 --- /dev/null +++ b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/03 Strategy Payoff.html @@ -0,0 +1,34 @@ + + + +

The payoff of the strategy is

+$$ +\begin{array}{rcll} +C^{OTM}_T & = & (S_T - K^{C})^{+}\\ +P^{OTM}_T & = & (K^{P} - S_T)^{+}\\ +P_T & = & (-C^{OTM}_T - P^{OTM}_T + C^{OTM}_0 + P^{OTM}_0)\times m - fee +\end{array} +$$ +$$ +\begin{array}{rcll} +\textrm{where} & C^{OTM}_T & = & \textrm{OTM call value at time T}\\ +& P^{OTM}_T & = & \textrm{OTM put value at time T}\\ +& S_T & = & \textrm{Underlying asset price at time T}\\ +& K^{C} & = & \textrm{OTM call strike price}\\ +& K^{P} & = & \textrm{OTM put strike price}\\ +& P_T & = & \textrm{Payout total at time T}\\ +& C^{OTM}_0 & = & \textrm{OTM call value at position opening (debit paid)}\\ +& P^{OTM}_0 & = & \textrm{OTM put value at position opening (debit paid)}\\ +& m & = & \textrm{Contract multiplier}\\ +& T & = & \textrm{Time of expiration} +\end{array} +$$ +
+

The following chart shows the payoff at expiration:

+ + +

The maximum profit $C^{OTM}_0 + P^{OTM}_0$. It occurs when the underlying price at expiration remains within the range of the strike prices. In this case, both Options expire worthless.

+

The maximum loss is unlimited if the underlying price rises to infinity or substantial, $C^{OTM}_0 + P^{OTM}_0 - K^{P}$, if it drops to zero at expiration.

\ No newline at end of file diff --git a/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/99 Example.php b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/99 Example.php new file mode 100644 index 0000000000..28b733d9c9 --- /dev/null +++ b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/99 Example.php @@ -0,0 +1,52 @@ + + + +

The following table shows the price details of the assets in the algorithm at Option expiration (2017-04-22):

+ + + + + + + + + + +
AssetPrice ($)Strike ($)
Call8.00835.00
Put7.40832.50
Underlying Equity at expiration843.19-
+ + + +

Therefore, the payoff is

+ +$$ +\begin{array}{rcll} +C^{OTM}_T & = & (S_T - K^{C})^{+}\\ +& = & (843.19-835.00)^{+}\\ +& = & 8.19\\ +P^{OTM}_T & = & (K^{P} - S_T)^{+}\\ +& = & (832.50-843.19)^{+}\\ +& = & 0\\ +P_T & = & (-C^{OTM}_T - P^{OTM}_T + C^{OTM}_0 + P^{OTM}_0)\times m - fee\\ +& = & (-8.19-0+8.00+7.40)\times100-2.00\times2\\ +& = & 719 +\end{array} +$$
+ +

So, the strategy gains $719.

+ + \ No newline at end of file diff --git a/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/metadata.json b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/metadata.json new file mode 100644 index 0000000000..23b25fb32d --- /dev/null +++ b/03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/25 Short Strangle/metadata.json @@ -0,0 +1,12 @@ +{ + "type": "metadata", + "values": { + "description": "A Short Strangle is an Options trading strategy that consists of simultaneously selling an OTM put and an OTM call, where both contracts have the same underlying asset and expiration date.", + "keywords": "Short Strangle Options trading strategy, out-the-money call, out-the-money put, profit from stable and not experience significant movements in the underlying stock, short straddle, contracts in the strategy legs, Strategy Payoff, maximum loss is unlimited", + "og:description": "A Short Strangle is an Options trading strategy that consists of simultaneously selling an OTM put and an OTM call, where both contracts have the same underlying asset and expiration date.", + "og:title": "Short Strangle - Documentation QuantConnect.com", + "og:type": "website", + "og:site_name": "Short Strangle - QuantConnect.com", + "og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/trading-and-orders/option-strategies/short-strangle.png" + } +} \ No newline at end of file