-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
162 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rategies/24 Strangle/01 Introduction.html → ...ies/24 Long Strangle/01 Introduction.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<p><span class="new-term">Long Strangle</span> is an Options trading strategy that consists of simultaneously buying an OTM put and an OTM call, where both contracts have the same underlying asset and expiration date. This strategy aims to profit from volatile movements in the underlying stock, either positive or negative.</p> | ||
<p>Compared to a <a href='/docs/v2/writing-algorithms/trading-and-orders/option-strategies/straddle'>long straddle</a>, the net debit of a long strangle is lower since OTM Options are cheaper. Additionally, the losing range of a long straddle is wider and the strike spread is wider.</p> | ||
<p>Compared to a <a href='/docs/v2/writing-algorithms/trading-and-orders/option-strategies/long-straddle'>long straddle</a>, the net debit of a long strangle is lower since OTM Options are cheaper. Additionally, the losing range of a long straddle is wider and the strike spread is wider.</p> |
103 changes: 103 additions & 0 deletions
103
...orithms/22 Trading and Orders/07 Option Strategies/24 Long Strangle/02 Implementation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<p>Follow these steps to implement the long strangle strategy:</p> | ||
|
||
<ol> | ||
<li>In the <code>Initialize</code> method, set the start date, end date, cash, and <a href="/docs/v2/writing-algorithms/universes/equity-options">Option universe</a>.</li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">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); | ||
}</pre> | ||
<pre class="python">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)</pre> | ||
</div> | ||
|
||
<li>In the <code>OnData</code> method, select the expiration date and strike prices of the contracts in the strategy legs.</li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">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; | ||
}</pre> | ||
<pre class="python">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</pre> | ||
</div> | ||
|
||
<li>In the <code>OnData</code> method, call the <code>OptionStrategies.Strangle</code> method and then submit the order.</li> | ||
<div class="section-example-container"> | ||
<pre class="csharp">var longStrangle = OptionStrategies.Strangle(_symbol, callStrike, putStrike, expiry); | ||
Buy(longStrangle, 1);</pre> | ||
<pre class="python">long_strangle = OptionStrategies.Strangle(self.symbol, call_strike, put_strike, expiry) | ||
self.Buy(long_strangle, 1)</pre> | ||
</div> | ||
|
||
<? | ||
$methodNames = array("Buy"); | ||
include(DOCS_RESOURCES."/trading-and-orders/option-strategy-extra-args.php"); | ||
?> | ||
</ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ing Algorithms/22 Trading and Orders/07 Option Strategies/24 Long Strangle/99 Example.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<script type="text/x-mathjax-config"> | ||
MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}}); | ||
</script> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> | ||
</script> | ||
|
||
<p>The following table shows the price details of the assets in the algorithm at Option expiration (2017-04-22):</p> | ||
|
||
<table class="table qc-table" id="payoff-table"> | ||
<thead> | ||
<tr><th>Asset</th><th>Price ($)</th><th>Strike ($)</th></tr> | ||
</thead> | ||
<tbody> | ||
<tr><td>Call</td><td>8.80</td><td>835.00</td></tr> | ||
<tr><td>Put</td><td>9.50</td><td>832.50</td></tr> | ||
<tr><td>Underlying Equity at expiration</td><td>843.19</td><td>-</td></tr> | ||
</tbody> | ||
</table> | ||
|
||
<style> | ||
#payoff-table td:nth-child(2), | ||
#payoff-table th:nth-child(2), | ||
#payoff-table td:nth-child(3), | ||
#payoff-table th:nth-child(3) { | ||
text-align: right; | ||
} | ||
</style> | ||
|
||
<p>Therefore, the payoff is</p> | ||
|
||
$$ | ||
\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.80-9.50)\times100-2.00\times2\\ | ||
& = & -1013 | ||
\end{array} | ||
$$<br> | ||
|
||
<p>So, the strategy losses $1,013.</p> | ||
|
||
<? | ||
$optionStrategyName = "a long straddle"; | ||
$pythonBacktestHash = "2803b574abb88853879060ba5224b026" ; | ||
$csharpBacktestHash = "126b5aeb4be7a8bc2e15e10f54ee4894" ; | ||
include(DOCS_RESOURCES."/trading-and-orders/option-strategy-embedded-backtest.php"); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 0 additions & 98 deletions
98
...g Algorithms/22 Trading and Orders/07 Option Strategies/24 Strangle/02 Implementation.php
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
03 Writing Algorithms/22 Trading and Orders/07 Option Strategies/24 Strangle/04 Example.html
This file was deleted.
Oops, something went wrong.