Skip to content

Commit

Permalink
Adds Naked Put Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Jul 25, 2023
1 parent 1a5622a commit a8a5356
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>A <span class="new-term">Naked Put</span>, also known as an <span class="new-term">uncovered put</span>, involves the sale of put Options without having a corresponding short position in the underlying security. It is called "naked" because the seller does not have any cover or protection in the form of a short position in the underlying asset, which exposes them to potentially unlimited risk. Naked puts aim to profit from the Option premium by selling puts. At any time for American Options or at expiration for European Options, if the stock moves above the strike price, you keep the premium. If the underlying price moves below the strike, the Option buyer can <a href='/docs/v2/writing-algorithms/trading-and-orders/order-types/option-exercise-orders'>exercise the Options contract</a>, which means you need sell the underlying at market price to fulfill your obligation to buy it at the strike price and keep the premium.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<p>Follow these steps to implement the naked put strategy:</p>

<ol>
<li>In the <code>Initialize</code> method, set the start date, end date, starting cash, and <a href="/docs/v2/writing-algorithms/universes/equity-options">Options universe</a>.</li>
<div class="section-example-container">
<pre class="csharp">private Symbol _put, _symbol;

public override void Initialize()
{
SetStartDate(2014, 1, 1);
SetEndDate(2014, 3, 1);
SetCash(100000);

var option = AddOption("IBM");
_symbol = option.Symbol;
option.SetFilter(-3, 3, 0, 31);
}</pre>
<pre class="python">def Initialize(self) -&gt; None:
self.SetStartDate(2014, 1, 1)
self.SetEndDate(2014, 3, 1)
self.SetCash(100000)

option = self.AddOption("IBM")
self.symbol = option.Symbol
self.put = None

option.SetFilter(-3, 3, 0, 31)</pre>
</div>

<li>In the <code>OnData</code> method, select the Option contract.</li>
<div class="section-example-container">
<pre class="csharp">public override void OnData(Slice slice)
{
if (_put != null &amp;&amp; Portfolio[_put].Invested) return;

if (!slice.OptionChains.TryGetValue(_symbol, out var chain)) return;

// Find ATM put with the farthest expiry
var expiry = chain.Max(x =&gt; x.Expiry);
var atmCall = chain
.Where(x =&gt; x.Right == OptionRight.Call &amp;&amp; x.Expiry == expiry)
.OrderBy(x =&gt; Math.Abs(x.Strike - chain.Underlying.Price))
.FirstOrDefault();</pre>
<pre class="python">def OnData(self, slice: Slice) -&gt; None:
if self.put and self.Portfolio[self.put].Invested:
return

chain = slice.OptionChains.get(self.symbol)
if not chain:
return

# Find ATM put with the farthest expiry
expiry = max([x.Expiry for x in chain])
put_contracts = sorted([x for x in chain
if x.Right == OptionRight.Call and x.Expiry == expiry],
key=lambda x: abs(chain.Underlying.Price - x.Strike))

if not put_contracts:
return

atm_put = put_contracts[0]</pre>
</div>

<li>In the <code>OnData</code> method, call the <code>OptionStrategies.NakedPut</code> method and then submit the order.</li>
<div class="section-example-container">
<pre class="csharp">var nakedCall = OptionStrategies.NakedPut(_symbol, atmCall.Strike, expiry);
Buy(nakedCall, 1);

_put = atmCall.Symbol;</pre>
<pre class="python">naked_put = OptionStrategies.NakedPut(self.symbol, atm_put.Strike, expiry)
self.Buy(naked_put, 1)

self.put = atm_put.Symbol</pre>
</div>

<?
$methodNames = array("Buy");
include(DOCS_RESOURCES."/trading-and-orders/option-strategy-extra-args.php");
?>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<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 payoff of the strategy is</p>
$$
\begin{array}{rcll}
P^{K}_T &amp; = &amp; (K - S_T)^{+}\\
P_T &amp; = &amp; (P^{K}_0 - P^{K}_T)\times m - fee
\end{array}
$$
$$
\begin{array}{rcll}
\textrm{where} &amp; P^{K}_T &amp; = &amp; \textrm{Put value at time T}\\
&amp; S_T &amp; = &amp; \textrm{Underlying asset price at time T}\\
&amp; K &amp; = &amp; \textrm{Put strike price}\\
&amp; P_T &amp; = &amp; \textrm{Payout total at time T}\\
&amp; P^{K}_0 &amp; = &amp; \textrm{Put price when the trade opened (credit received)}\\
&amp; m &amp; = &amp; \textrm{Contract multiplier}\\
&amp; T &amp; = &amp; \textrm{Time of expiration}
\end{array}
$$
<br>
<p>The following chart shows the payoff at expiration:</p>
<!--img class="docs-image" src="https://cdn.quantconnect.com/tutorials/i/Tutorial01-naked-put.png" alt="naked put strategy payoff"-->
<p>The maximum profit is $P^{K}_0$, which occurs when the underlying price is at or above the strike price of the put at expiration.</p>
<p>The maximum loss is $K - P^{K}_0$ which ocurrs when the underlying price drops to zero.</p>
<p>If the Option is American Option, there is risk of early assignment on the sold contract.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<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:</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>Put</td><td>1.37</td><td>185.00</td></tr>
<tr><td>Underlying Equity at expiration</td><td>190.01</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}
P^{K}_T &amp; = &amp; (K - S_T)^{+}\\
&amp; = &amp; (185 - 190.01)^{+}\\
&amp; = &amp; 0.0\\
P_T &amp; = &amp; (P^{K}_0 - P^{K}_T)\times m - fee\\
&amp; = &amp; (1.37 - 0.0)\times m - fee\\
&amp; = &amp; 1.37 \times 100 - 1\\
&amp; = &amp; 136
\end{array}
$$
<br>
<p>So, the strategy gains $136.</p>

<?
$optionStrategyName = "a naked put";
$pythonBacktestHash = "f81ecd25b7db05a4174cfdea6277a46b" ;
$csharpBacktestHash = "e3654011cfc55607efdb6cabba7bb2ef" ;
include(DOCS_RESOURCES."/trading-and-orders/option-strategy-embedded-backtest.php");
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "A Naked Put, also known as an uncovered put, involves the sale of put Options without having a corresponding short position in the underlying security.",
"keywords": "naked put, profit from the Option premium, Strategy Payoff, risk of early assignment, option strategy",
"og:description": "A Naked Put, also known as an uncovered put, involves the sale of put Options without having a corresponding short position in the underlying security.",
"og:title": "Naked Put - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "Naked Put - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/trading-and-orders/option-strategies/naked-put.png"
}
}

0 comments on commit a8a5356

Please sign in to comment.