Skip to content

Commit

Permalink
Code generated by Alternative-Datasets-Code-Generator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub authored and AlexCatarino committed Oct 3, 2024
1 parent 68c9c0b commit 4d5f889
Show file tree
Hide file tree
Showing 81 changed files with 580 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def initialize(self) -> None:
self.set_start_date(2019, 1, 1)
security = self.add_equity("AAPL")
# Set shortable provider as IB
security.set_shortable_provider(InteractiveBrokersShortableProvider())
self._symbol = security.symbol</pre>

Expand All @@ -19,6 +20,7 @@
{
SetStartDate(2019, 1, 1);
var security = AddEquity("AAPL");
// Set shortable provider as IB
security.SetShortableProvider(new InteractiveBrokersShortableProvider());
_symbol = security.Symbol;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

<div class="section-example-container">
<pre class="csharp">var shortableProvider = Securities[_symbol].ShortableProvider;
// Get the shortable quantity of the selected symbol at the selected time
var shortableQuantity = shortableProvider.ShortableQuantity(_symbol, Time);

// Check if there are a certain quantity of shares available
var quantity = 100;
var isShortableQuantity = Shortable(_symbol, quantity);</pre>
<pre class="python">shortable_provider = self.securities[self._symbol].shortable_provider
# Get the shortable quantity of the selected symbol at the selected time
shortable_quantity = shortable_provider.shortable_quantity(self._symbol, self.time)

# Check if there are a certain quantity of shares available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@

<ul><li>Universe Selection</li></ul><div class="section-example-container">
<pre class="python">def initialize(self) -&gt; None:
# Universe selection
self._universe = self.add_universe(self.fundamental_filter_function)

def fundamental_filter_function(self, fundamental: List[Fundamental]):
# Sort all equities with price above $10 by dollar volume
sorted_by_dollar_volume = sorted([f for f in fundamental if f.price &gt; 10],
key=lambda f: f.dollar_volume)
# Take the top 10
return [f.symbol for f in sorted_by_dollar_volume[:10]]</pre>
<pre class="csharp">public override void Initialize()
{
// Universe selection
_universe = AddUniverseSelection(new FundamentalUniverseSelectionModel(FundamentalFilterFunction));
}

public override List&lt;Symbol&gt; FundamentalFilterFunction(List&lt;Fundamental&gt; fundamental)
{
// Sort all equities with price above $10 by dollar volume, take the top 10
return (from f in fundamental
where f.Price &gt; 10
orderby f.DollarVolume
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>
The US Equity Option Chain Master dataset by QuantConnect lists the available US Equity Options contracts and the current Implied Volatility and Greeks. The data covers 4,000 Symbols, starts in January 2012, and is delivered on a daily update frequency. To create this dataset, we use <a href='https://www.quantconnect.com/research/16977/greeks-and-iv-implementation/p1'>our implementation</a> of the forward tree pricing model, which accounts for the interest rate, dividend payments, and daily closing prices. The values in this dataset are the same values you can get from daily <a href='/docs/v2/writing-algorithms/securities/asset-classes/equity-options/greeks-and-implied-volatility/indicators'>indicators</a> with mirror Options.
</p>

<p>This dataset depends on the <a href="/datasets/quantconnect-us-equity-security-master">US Equity Security Master</a> dataset because the US Equity Security Master dataset contains information on splits, dividends, and symbol changes of the underlying security.</p>

<p>This dataset <b>does not</b> contain market data. For market data, see <a href="/datasets/algoseek-us-equity-options">US Equity Options by AlgoSeek</a>.</p>

<p>For more information about the US Equity Option Universe dataset, including CLI commands and pricing, see the <a href="/datasets/quantconnect-us-equity-option-universe">dataset listing</a>.<p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>The following snippet demonstrates how to request data from the US Equity Options dataset:</p>

<div class="section-example-container">
<pre class="python">option = self.add_option("GOOG")
self.option_symbol = option.symbol
option.set_filter(lambda universe: universe.delta(0.4, 0.6))</pre>
<pre><code class="csharp">var option = AddOption("GOOG");
_optionSymbol = option.Symbol;
option.SetFilter(universe => universe.delta(0.4m, 0.6m));</code></pre>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p>The following table describes the dataset properties:</p>

<table class="table qc-table"><thead><tr><th>Property</th>
<th>Value</th>
</tr></thead><tbody><tr><td>Start Date</td>
<td>January 2012</td>
</tr><tr><td>Asset Coverage</td>
<td>4,000 Symbols</td>
</tr><tr><td>Data Density</td>
<td>Dense</td>
</tr><tr><td>Resolution</td>
<td>Daily</td>
</tr><tr><td>Timezone</td>
<td>New York</td>
</tr></tbody></table
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
The US Equity Options dataset enables you to accurately design Option strategies. Examples include the following strategies:
</p>
<ul><li>Buying put Options to hedge against downward price movement in positive Equity positions</li>
<li>Exploiting arbitrage opportunities that arise when the price of Option contracts deviate from their theoretical value</li>
</ul>
<div class='python'><div class='qc-embed-frame' style='display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;'><div class='qc-embed-dummy' style='padding-top: 56.25%;'></div><div class='qc-embed-element' style='position: absolute; top: 0; bottom: 0; left: 0; right: 0;'><iframe class='qc-embed-backtest' src='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_467152d2f04391913b704e21767f1682.html' style='max-width: calc(100vw - 30px); max-height: 100vw; overflow: hidden;' scrolling='no' width='100%' height='100%'></iframe></div></div></div>
<div class='csharp'><div class='qc-embed-frame' style='display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;'><div class='qc-embed-dummy' style='padding-top: 56.25%;'></div><div class='qc-embed-element' style='position: absolute; top: 0; bottom: 0; left: 0; right: 0;'><iframe class='qc-embed-backtest' src='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_ac6db075b8e9c9abc7c9d48c55db3871.html' style='max-width: calc(100vw - 30px); max-height: 100vw; overflow: hidden;' scrolling='no' width='100%' height='100%'></iframe></div></div></div><p>For more example algorithms, see <a href='/datasets/algoseek-us-equity-options/examples'>Examples</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>The US Equity Options dataset provides <b>OptionUniverse</b> object.</p>

<h4>OptionUniverse Attributes</h4>
<p><b>OptionUniverse</b> objects have the following attributes:</p>
<div data-tree="QuantConnect.Data.UniverseSelection.OptionUniverse"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>To view the supported assets in the US Equity Options dataset, see the <a href="/datasets/algoseek-us-equity-options/explorer">Data Explorer</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<p>To add US Equity Options data to your algorithm, call the <b class="csharp">AddOption</b><b class="python">add_option</b> method. Save a reference to the Equity Option <b>Symbol</b> so you can access the data later in your algorithm.</p>

<p>To set a contract filter, call the <b class="csharp">SetFilter</b><b class="python">set_filter</b> method of the Option object.</p>

<div class="section-example-container">
<pre><code class="python">class USEquityOptionsDataAlgorithm(QCAlgorithm):

def initialize(self) -&gt; None:
self.set_start_date(2020, 6, 1)
self.set_end_date(2021, 6, 1)
self.set_cash(100000)
self.universe_settings.asynchronous = True
option = self.add_option("GOOG")
self.option_symbol = option.symbol
# Set our strike/expiry filter for this option chain
option.set_filter(self._option_filter)

def _option_filter(self, universe: OptionFilterUniverse) -> OptionFilterUniverse:
# Contracts can be filtered by greeks, implied volatility, open interest:
return universe \
.delta(0.5, 1.5) \
.gamma(0.0001, 0.0006) \
.vega(0.01, 1.5) \
.theta(-2.0, -0.5) \
.rho(0.5, 3.0) \
.implied_volatility(1, 3) \
.open_interest(100,500)
</code></pre>
<pre class="csharp">namespace QuantConnect
{
public class USEquityOptionsDataAlgorithm : QCAlgorithm
{
private Symbol _optionSymbol;

public override void Initialize()
{
SetStartDate(2020, 6, 1);
SetEndDate(2021, 6, 1);
SetCash(100000);
UniverseSettings.Asynchronous = True;
// Requesting data
var option = AddOption("GOOG");
_optionSymbol = option.Symbol;
// Set our strike/expiry filter for this option chain
option.SetFilter(OptionFilter);
}

private virtual OptionFilterUniverse OptionFilter(OptionFilterUniverse universe)
{
// Contracts can be filtered by greeks, implied volatility, open interest:
return universe
.Delta(0.5m, 1.5m)
.Gamma(0.0001m, 0.0006m)
.Vega(0.01m, 1.5m)
.Theta(-2.0m, -0.5m)
.Rho(0.5m, 3.0m)
.ImpliedVolatility(1.0m, 3.0m)
.OpenInterest(100m, 500m);
}
}
}</pre>
</div>

<p>The Equity resolution must be less than or equal to the Equity Option resolution. For example, if you set the Equity resolution to minute, then you must set the Equity Option resolution to minute, hour, or daily.</p>

<p>For more information about creating US Equity Option subscriptions, see <a href="/docs/v2/writing-algorithms/securities/asset-classes/equity-options/requesting-data">Requesting Data</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>For information about accessing US Equity Options data, see <a href="/docs/v2/writing-algorithms/securities/asset-classes/equity-options/handling-data">Handling Data</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<p>You can get historical US Index Options data in an algorithm and the Research Environment.</p>

<h4>Historical Data In Algorithms</h4>

<p>To get historical US Index Options data in an algorithm, call the <b class="csharp">History</b><b class="python">history</b> method with the Index Option chain <b>Symbol</b>. If there is no data in the period you request, the history result is empty.</p>

<div class="section-example-container">
<pre class="python"># DataFrame
history_df = self.history(self.option_symbol, 3, Resolution.MINUTE)</pre>

<pre><code class="csharp">// TradeBar objects
var history = History<OptionUniverse>(option, 3, Resolution.Daily).ToList();</code></pre>
</div>

<p>For more information about historical data in algorithms, see <a href="/docs/v2/writing-algorithms/historical-data/history-requests">History Requests</a>.</p>

<h4>Historical Data In Research</h4>

<p>To get historical US Index Options data in the Research Environment for an entire Option chain, call the <b class="csharp">OptionHistory</b><b class="python">option_history</b> method with the canonical Option <b>Symbol</b>.</p>

<div class="section-example-container">
<pre class="python">qb = QuantBook()
index_symbol = qb.add_index('VIX').symbol
option = qb.add_index_option(index_symbol) # or qb.add_index_option(index_symbol, "VIXW")
option.set_filter(-2, 2, 0, 90)
history = qb.option_history(option.symbol, datetime(2020, 6, 1), datetime(2020, 6, 5))

all_history = history.get_all_data()
expiries = history.get_expiry_dates()
strikes = history.get_strikes()</pre>


<pre class="csharp">var qb = new QuantBook();
var indexSymbol = qb.AddIndex("VIX").Symbol;
var option = qb.AddIndexOption(indexSymbol); // or qb.AddIndexOption(indexSymbol, "VIXW");
option.SetFilter(-2, 2, 0, 90);
var history = qb.OptionHistory(option.Symbol, new DateTime(2020, 6, 1), new DateTime(2020, 6, 5));

var contracts = history.SelectMany(x =&gt; x.OptionChains.SelectMany(y =&gt; y.Value.Contracts.Keys)).Distinct().ToList();
var expiries = contracts.Select(x =&gt; x.ID.Date).Distinct().ToList();
var strikes = contracts.Select(x =&gt; x.ID.StrikePrice).Distinct().ToList();</pre>
</div>

<p>To get historical data for a single US Index Option contract, call the <b class="csharp">History</b><b class="python">history</b> method like you would in an algorithm but on the <b>QuantBook</b> object. For more information about historical data in the Research Environment, see <a href="/docs/v2/research-environment/datasets/index-options">Index Options</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<p>
The US Equity Options dataset enables you to accurately design Option strategies. Examples include the following strategies:
</p>
<ul><li>Buying put Options to hedge against downward price movement in positive Equity positions</li>
<li>Exploiting arbitrage opportunities that arise when the price of Option contracts deviate from their theoretical value</li>
</ul>
<div class='python'><div class='qc-embed-frame' style='display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;'><div class='qc-embed-dummy' style='padding-top: 56.25%;'></div><div class='qc-embed-element' style='position: absolute; top: 0; bottom: 0; left: 0; right: 0;'><iframe class='qc-embed-backtest' src='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_467152d2f04391913b704e21767f1682.html' style='max-width: calc(100vw - 30px); max-height: 100vw; overflow: hidden;' scrolling='no' width='100%' height='100%'></iframe></div></div></div>
<div class='csharp'><div class='qc-embed-frame' style='display: inline-block; position: relative; width: 100%; min-height: 100px; min-width: 300px;'><div class='qc-embed-dummy' style='padding-top: 56.25%;'></div><div class='qc-embed-element' style='position: absolute; top: 0; bottom: 0; left: 0; right: 0;'><iframe class='qc-embed-backtest' src='https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_ac6db075b8e9c9abc7c9d48c55db3871.html' style='max-width: calc(100vw - 30px); max-height: 100vw; overflow: hidden;' scrolling='no' width='100%' height='100%'></iframe></div></div></div><p>For more example algorithms, see <a href='/datasets/algoseek-us-equity-options/examples'>Examples</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "US Equity Option Universe dataset from QuantConnect.",
"keywords": "data, financial data, alternative dataset",
"og:description": "US Equity Option Universe dataset from QuantConnect.",
"og:title": "US Equity Option Universe - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "US Equity Option Universe - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/datasets/quantconnect/us-equity-option-universe.png"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
# Check if any splits for the symbol
if slice.splits.contains_key(self._symbol):
# If so, get the mapped split object
split = slice.splits[self._symbol]
split_type = {0: "Warning", 1: "SplitOccurred"}.get(split.type)
self.log(f"Split: {split.symbol}\t{split.split_factor}\t{split.reference_price}\t{split_type}")</pre>
<pre class="csharp">public override void OnData(Slice slice)
{
// Check if any splits for the symbol
if (slice.Splits.ContainsKey(_symbol))
{
// If so, get the mapped split object
var split = slice.Splits[_symbol];
Log($"Split: {split.Symbol}\t{split.SplitFactor}\t{split.ReferencePrice}\t{split.Type}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
# Check if any dividend for the symbol
if slice.dividends.contains_key(self._symbol):
# If so, get the mapped dividend object
dividend = slice.dividends[self._symbol]
self.log(f'Dividend: {dividend.symbol}\t{dividend.distribution}\t{dividend.reference_price}')</pre>
<pre class="csharp">public override void OnData(Slice slice)
{
// Check if any dividend for the symbol
if (slice.Dividends.ContainsKey(_symbol))
{
// If so, get the mapped dividend object
var dividend = slice.Dividends[_symbol];
Log($"Dividend: {dividend.Symbol}\t{dividend.Distribution}\t{dividend.ReferencePrice}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
# Check if any delisting for the symbol
if slice.delistings.contains_key(self._symbol):
# If so, get the mapped delisting object
delisting = slice.delistings[self._symbol]
delisting_type = {0: "Warning", 1: "Delisted"}.get(delisting.type)
self.log(f'Delistings: {delisting_type}')</pre>
<pre class="csharp">public override void OnData(Slice slice)
{
// Check if any delisting for the symbol
if (slice.Delistings.ContainsKey(_symbol))
{
// If so, get the mapped delisting object
var delisting = slice.Delistings[_symbol];
Log($"Delistings: {delisting.Type}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<p>To get the current Symbol change events, index the <b class="csharp">SymbolChangedEvents</b><b class="python">symbol_changed_events</b> property of the current <b>Slice</b> with the Equity <b>Symbol</b>. Slice objects deliver unique events to your algorithm as they happen, but the <b>Slice</b> may not contain data for your security at every time step. To avoid issues, check if the <b>Slice</b> contains the data you want before you index it.</p>
<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
# Check if any symbol change event for the symbol
if slice.symbol_changed_events.contains_key(self._symbol):
# If so, get the mapped SymbolChangeEvent object
symbol_changed_event = slice.symbol_changed_events[self._symbol]
self.log(f"Symbol changed: {symbol_changed_event.old_symbol} -&gt; {symbol_changed_event.new_symbol}")
</pre>
<pre class="csharp">
public override void OnData(Slice slice){
// Check if any symbol change event for the symbol
if (slice.SymbolChangedEvents.ContainsKey(_symbol))
{
// If so, get the mapped SymbolChangeEvent object
var symbolChangedEvent = slice.SymbolChangedEvents[_symbol];
Log($"Symbol changed: {symbolChangedEvent.OldSymbol} -&gt; {symbolChangedEvent.NewSymbol}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "US Equity Security Master dataset from QuantConnect.",
"keywords": "data, financial data, alternative dataset",
"og:description": "US Equity Security Master dataset from QuantConnect.",
"og:title": "US Equity Security Master - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "US Equity Security Master - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/datasets/quantconnect/us-equity-security-master.png"
}
}

This file was deleted.

Loading

0 comments on commit 4d5f889

Please sign in to comment.