Skip to content

Commit

Permalink
New Organization of Futures > Requesting Data
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatarino committed Aug 21, 2024
1 parent 081c643 commit 1981b85
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="sub-heading-content">
<div class="sub-heading-landing">
<div class="internal-content">
<p>
<p>Request Futures data in your algorithm to receive a feed of contract prices in the <code class="csharp">OnData</code><code class="python">on_data</code> method. For more information about the specific dataset we use for backtests, see the <a href="/datasets/algoseek-us-futures">US Futures dataset listing</a>. To trade Futures live, you can use the <a href='/docs/v2/cloud-platform/datasets/quantconnect/futures'>QuantConnect data provider</a> or one of the <a href='/docs/v2/cloud-platform/datasets'>brokerage data providers</a>.</p>
</p>
<p>To request Futures data, call one of the following methods:</p>
<ul>
<li><code class='csharp'>AddFuture</code><code class='python'>self.add_future</code> to add a basket of contracts for a single Future</li>
<li><code class='csharp'>AddFutureContract</code><code class='python'>self.add_future_contract</code> to add individual contracts for an underlying Future</li>
</ul>
</div>
<div class="docs-landing-links">
<div class="col-md-6 col-sm-12 docs-landing-link-wrap">
<div class="content clickable" onclick="window.location.href = '/docs/v2/writing-algorithms/securities/asset-classes/futures/requesting-data/universes'">
<div class="docs-internal-link">
<h4>
Request and Filter All Contracts
</h4>
</div>
<code class='csharp'>AddFuture</code><code class='python'>self.add_future</code>
</div>
</div>
<div class="col-md-6 col-sm-12 docs-landing-link-wrap">
<div class="content clickable" onclick="window.location.href = '/docs/v2/writing-algorithms/securities/asset-classes/futures/requesting-data/individual-contracts'">
<div class="docs-internal-link">
<h4>
Select Individual Contracts
</h4>
</div>
<code class='csharp'>AddFutureContract</code><code class='python'>self.add_future_contract</code>
</div>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>
The <code class="csharp">AddFuture</code><code class="python">add_future</code> method enables you to select a basket of Future contracts for an underlying Future.
To form your universe of contracts, you can filter them down by their expiry.
If you want to subscribe to individual contracts one-by-one instead of a set of contracts, see <a href='/docs/v2/writing-algorithms/securities/asset-classes/futures/requesting-data/individual-contracts'>Individual Contracts</a>.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<p>To add a universe of Future contracts, in the <code class="csharp">Initialize</code><code class="python">initialize</code> method, call the <code class="csharp">AddFuture</code><code class="python">add_future</code> method. This method returns an <code>Future</code> object, which has a <code class="csharp">SetFilter</code><code class="python">set_filter</code> method you can call to filter the set of tradable contract down to just the contracts you want.</p>

<div class="section-example-container">
<pre class="csharp">public class BasicFutureAlgorithm : QCAlgorithm
{
public override void Initialize()
{
var future = AddFuture(Futures.Indices.SP500EMini);
future.SetFilter(0, 182);
}

public override void OnData(Slice data)
{
foreach (var (continuousSymbol, chain) in data.FuturesChains)
{
foreach (var (symbol, contract) in chain.Contracts)
{
var expiry = contract.Expiry;
}
}
}
}</pre>
<pre class="python">class BasicFutureAlgorithm(QCAlgorithm):
def initialize(self):
future = self.add_future(Futures.Indices.SP500E_MINI)
option.set_filter(0, 182)

def on_data(self, data):
for continuous_symbol, chain in data.future_chains.items():
for symbol, contract in chain.contracts.items():
contract.strike</pre>
</div>

<p>For more information about the <code class="csharp">AddFuture</code><code class="python">add_future</code> method, see <a href='/docs/v2/writing-algorithms/universes/futures#11-Create-Universes'>Create Universes</a>.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "metadata",
"values": {
"description": "Request Futures data in your algorithm to receive a feed of contract prices in the OnData method.",
"keywords": "Futures, security subscriptions, Extended Market Hours, fill forward, margin, leverage",
"og:description": "Request Futures data in your algorithm to receive a feed of contract prices in the OnData method.",
"og:title": "Universes - Documentation QuantConnect.com",
"og:type": "website",
"og:site_name": "Universes - QuantConnect.com",
"og:image": "https://cdn.quantconnect.com/docs/i/writing-algorithms/securities/asset-classes/futures/requesting-data/universes.png"
}
}

0 comments on commit 1981b85

Please sign in to comment.