Skip to content

Commit

Permalink
match nit style option strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisSzeto committed Jun 3, 2024
1 parent fab6f57 commit 1be43e3
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select the call Option contracts with the furthest expiry
var expiry = chain.OrderByDescending(x => x.Expiry).First().Expiry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
if (!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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
if (!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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
if (!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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
if (!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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_symbol, null);
if (chain == null || chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Separate the call and put contracts
var calls = chain.Where(x => x.Right == OptionRight.Call);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ol>
<li>In the <code class="csharp">Initialize</code><code class="python">initialize</code> method, set the start date, set the end date, <a href='/docs/v2/writing-algorithms/securities/asset-classes/us-equity/requesting-data#02-Create-Subscriptions'>subscribe to the underlying Equity</a>, and create an <a href="/docs/v2/writing-algorithms/universes/equity-options">Option universe</a>.</li>
<div class="section-example-container">
<pre class="csharp">private Symbol _equitySymbol, _optionSymbol;
<pre class="csharp">private Symbol _equitySymbol, _symbol;

public override void Initialize()
{
Expand All @@ -13,7 +13,7 @@
UniverseSettings.Asynchronous = true;
_equitySymbol = AddEquity("GOOG").Symbol;
var option = AddOption("GOOG", Resolution.Minute);
_optionSymbol = option.Symbol;
_symbol = option.Symbol;
option.SetFilter(-10, 10, 0, 30);
}</pre>
<pre class="python">def Initialize(self) -&gt; None:
Expand All @@ -23,7 +23,7 @@
self.UniverseSettings.Asynchronous = True
self.equity_symbol = self.AddEquity("GOOG").Symbol
option = self.AddOption("GOOG", Resolution.Minute)
self.option_symbol = option.Symbol
self._symbol = option.Symbol
option.SetFilter(-10, 10, 0, 30)<br></pre>
</div>

Expand All @@ -34,8 +34,10 @@
if (Portfolio.Invested) return;

// Get the OptionChain
var chain = slice.OptionChains.get(_optionSymbol, null);
if (chain == null || chain.Count() == 0) return;
if (!slice.OptionChains.TryGetValue(_symbol, out var chain))
{
return;
}

// Select an expiry date
var expiry = chain.OrderBy(x =&gt; x.Expiry).Last().Expiry;
Expand Down

0 comments on commit 1be43e3

Please sign in to comment.