Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<pre class="csharp">RemoveSecurity(_symbol);</pre>
</div>

<p>The<code class="csharp">RemoveSecurity</code><code class="python">remove_security</code> method cancels your open orders for the security and liquidates your holdings in the <a href="/docs/v2/writing-algorithms/securities/asset-classes/crypto/holdings#03-Virtual-Pairs">virtual pair</a>.</p>
<p>The <code class="csharp">RemoveSecurity</code><code class="python">remove_security</code> method cancels your open orders for the security and liquidates your holdings in the <a href="/docs/v2/writing-algorithms/securities/asset-classes/crypto/holdings#03-Virtual-Pairs">virtual pair</a>.</p>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h4>Classic Algorithm Example</h4>
self.set_cash(1000)
# Seed the security price as the last known price, such that the price data is immediately available at initial rebalance
self.settings.seed_initial_prices = True
self.add_security_initializer(self._custom_security_initializer)

self.equity = self.add_equity("GME")

Expand Down Expand Up @@ -115,7 +114,6 @@ <h4>Framework Algorithm Example</h4>
self.set_cash(1000)
# Seed the security price as the last known price, such that the price data is immediately available at initial rebalance
self.settings.seed_initial_prices = True
self.add_security_initializer(self._custom_security_initializer)

self.set_universe_selection(ManualUniverseSelectionModel(
[Symbol.create("GME", SecurityType.EQUITY, Market.USA)]))
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct:
https://www.quantconnect.com/datasets/algoseek-us-equity-options

minor mistake on example:

  • we should check if assigned in on_order_event rather than every slice, lmk if I can make the fix
...
    def on_data(self, slice: Slice) -> None:
        # If the Option contract is exercised, close the underlying position.
        if self.portfolio[self.underlying].invested:
            self.liquidate(self.underlying)
...

Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ <h4>Framework Algorithm Example</h4>
# Daily update with the select_option_chain_symbols function
super().__init__(timedelta(1), self.select_option_chain_symbols)

def select_option_chain_symbols(self, utcTime: datetime) -&gt; List[Symbol]:
def select_option_chain_symbols(self, utc_time: datetime) -&gt; List[Symbol]:
# Always select only GOOG options as our focus
return [ Symbol.create("GOOG", SecurityType.OPTION, Market.USA) ]

Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct -- 252 trading days for the history request, fixes warning + performs the same
https://www.quantconnect.com/datasets/brain-ml-stock-ranking
updated .cs and .py

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4>Classic Algorithm Example</h4>
dataset_symbol = self.add_data(BrainStockRanking2Day, equity).symbol
self.equity_by_dataset_symbol[dataset_symbol] = equity
# Request historical ranking data to inspect subscription coverage.
history = self.history(dataset_symbol, 365, Resolution.DAILY)
history = self.history(dataset_symbol, 252, Resolution.DAILY)
self.debug(f"We got {len(history)} items from our history request for {equity}")

def on_data(self, data: Slice) -&gt; None:
Expand Down Expand Up @@ -156,7 +156,7 @@ <h4>Framework Algorithm Example</h4>
# Request data for the two-day estimated relative ranking.
security.brain_stock_ranking_2_day = algorithm.add_data(BrainStockRanking2Day, security, Resolution.DAILY)
# Historical data.
history = algorithm.history(security.brain_stock_ranking_2_day, 365, Resolution.DAILY)
history = algorithm.history(security.brain_stock_ranking_2_day, 252, Resolution.DAILY)
algorithm.debug(f"We got {len(history)} items from our history request for {security.brain_stock_ranking_2_day.symbol}")
for security in changes.removed_securities:
# Unsubscribe from the Brain ML Ranking feed for this security to release resources.
Expand Down Expand Up @@ -231,7 +231,7 @@ <h4>Framework Algorithm Example</h4>
var brainStockRanking2Day = algorithm.AddData&lt;BrainStockRanking2Day&gt;(security.Symbol, Resolution.Daily);
security.Set("BrainStockRanking2Day", brainStockRanking2Day);
// Historical data.
var history = algorithm.History&lt;BrainStockRanking2Day&gt;(brainStockRanking2Day.Symbol, 365, Resolution.Daily);
var history = algorithm.History&lt;BrainStockRanking2Day&gt;(brainStockRanking2Day.Symbol, 252, Resolution.Daily);
algorithm.Debug($"We got {history.Count()} items from our history request for {brainStockRanking2Day}");
}
foreach (var security in changes.RemovedSecurities)
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

def universe_selection(self, alt_coarse: List[BrainSentimentIndicatorUniverse]) -&gt; List[Symbol]:
return [d.symbol for d in alt_coarse \
if d.total_article_mentions7_days &gt; 0 \
and d.sentiment7_days]</pre>
if d.total_article_mentions_7_days &gt; 0 \
and d.sentiment_7_days]</pre>
<pre class="csharp">private Universe _universe;
public override void Initialize()
{
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h4>Historical Universe Data in Algorithms</h4>
universe_history = self.history(self._universe, 30, Resolution.DAILY)
for (_, time), sentiments in universe_history.items():
for sentiment in sentiments:
self.log(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment7_days}")</pre>
self.log(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment_7_days}")</pre>
</div>

<h4>Historical Universe Data in Research</h4>
Expand All @@ -41,7 +41,7 @@ <h4>Historical Universe Data in Research</h4>
universe_history = qb.universe_history(universe, qb.time-timedelta(30), qb.time)
for (_, time), sentiments in universe_history.items():
for sentiment in sentiments:
print(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment7_days}")</pre>
print(f"{sentiment.symbol} 7-day sentiment at {sentiment.end_time}: {sentiment.sentiment_7_days}")</pre>
</div>

<p>You can call the <code class="csharp">History</code><code class="python">history</code> method in Research.</p>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct
https://www.quantconnect.com/datasets/brain-sentiment-indicator
both insight duration and history request as 252 for .cs .py

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4>Classic Algorithm Example</h4>
# Request the processed longer term sentiment score data for sentiment trading.
self.aapl = self.add_equity("AAPL", Resolution.DAILY)
self.dataset_symbol = self.add_data(BrainSentimentIndicator30Day, self.aapl).symbol
history = self.history(self.dataset_symbol, 100, Resolution.DAILY)
history = self.history(self.dataset_symbol, 252, Resolution.DAILY)
self.debug(f"We got {len(history)} items from our history request for {self.dataset_symbol}")
if history.empty:
return
Expand Down Expand Up @@ -65,7 +65,7 @@ <h4>Classic Algorithm Example</h4>
// Request the processed longer term sentiment score data for sentiment trading.
_aapl = AddEquity("AAPL", Resolution.Daily);
_datasetSymbol = AddData&lt;BrainSentimentIndicator30Day&gt;(_aapl.Symbol).Symbol;
var history = History&lt;BrainSentimentIndicator30Day&gt;(_datasetSymbol, 100, Resolution.Daily);
var history = History&lt;BrainSentimentIndicator30Day&gt;(_datasetSymbol, 252, Resolution.Daily);
Debug($"We got {history.Count()} items from our history request for {_datasetSymbol}");
// Warm up historical sentiment values so the signal is immediately tradable.
var previousSentimentValues = history.Select(x =&gt; x.Sentiment);
Expand Down Expand Up @@ -147,7 +147,7 @@ <h4>Framework Algorithm Example</h4>
security.latest_sentiment_value = data_point.sentiment
# Buy if sentiment increase, liquidate otherwise to ride on the popularity of the equity
if security.price and target_direction == InsightDirection.UP and not security.invested:
insights.append(Insight.price(security, timedelta(100), target_direction))
insights.append(Insight.price(security, timedelta(252), target_direction))
return insights

def on_securities_changed(self, algorithm: QCAlgorithm, changes: SecurityChanges) -&gt; None:
Expand All @@ -157,7 +157,7 @@ <h4>Framework Algorithm Example</h4>
security.brain_sentiment_data = dataset.symbol
security.latest_sentiment_value = None
# Historical data
history = algorithm.history(dataset, 100, Resolution.DAILY)
history = algorithm.history(dataset, 252, Resolution.DAILY)
if not history.empty:
# Warm up historical sentiment values, cache for comparing last sentiment score to trade
previous_sentiment_values = history.loc[security.brain_sentiment_data].sentiment.values
Expand Down Expand Up @@ -216,7 +216,7 @@ <h4>Framework Algorithm Example</h4>
// Buy if sentiment increase, liquidate otherwise to ride on the popularity of the equity
if (security.Price != 0 &amp;&amp; targetDirection == InsightDirection.Up &amp;&amp; !security.Holdings.Invested)
{
insights.Add(Insight.Price(security.Symbol, TimeSpan.FromDays(100), targetDirection));
insights.Add(Insight.Price(security.Symbol, TimeSpan.FromDays(252), targetDirection));
}
}
return insights;
Expand All @@ -231,7 +231,7 @@ <h4>Framework Algorithm Example</h4>
security.Set("BrainSentimentData", dataset.Symbol);
security.Set("LatestSentimentValue", null);
// Historical data
var history = algorithm.History&lt;BrainSentimentIndicator30Day&gt;(dataset.Symbol, 100, Resolution.Daily).ToList();
var history = algorithm.History&lt;BrainSentimentIndicator30Day&gt;(dataset.Symbol, 252, Resolution.Daily).ToList();
if (history.Count() != 0)
{
// Warm up historical sentiment values, cache for comparing last sentiment score to trade
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct
https://www.quantconnect.com/datasets/brain-wikipedia-page-views
matches the framework example below / also all other brain datasets have algorithm in the class name

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<p> To add Brain Wikipedia Page Views Indicator data to your algorithm, call the <code class="csharp">AddData</code><code class="python">add_data</code> method. Save a reference to the dataset <code>Symbol</code> so you can access the data later in your algorithm.
<div class="section-example-container"><pre class="python">class BrainWikipediaPageViews(QCAlgorithm):
<div class="section-example-container"><pre class="python">class BrainWikipediaPageViewsAlgorithm(QCAlgorithm):
def initialize(self) -&gt; None:
self.set_start_date(2021, 1, 1)
self.set_end_date(2021, 7, 8)
self.set_cash(100000)
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
self.dataset_symbol = self.add_data(BrainWikipediaPageViews, self.aapl).symbol</pre>

<pre class="csharp">public class BrainWikipediaPageViews: QCAlgorithm
<pre class="csharp">public class BrainWikipediaPageViewsAlgorithm: QCAlgorithm
{
private Symbol _symbol;
public override void Initialize()
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct
https://www.quantconnect.com/datasets/brain-wikipedia-page-views
daily bar history request also updated to 252

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
if slice.contains_key(self.dataset_symbol):
data_point = slice[self.dataset_symbol]
self.log(f"{self.dataset_symbol} sentiments at {slice.time}: {data_point.NumberViews1}, {data_point.Buzz1}"</pre>
self.log(f"{self.dataset_symbol} sentiments at {slice.time}: {data_point.number_views_1}, {data_point.buzz_1}")</pre>

<pre class="csharp">public override void OnData(Slice slice)
{
Expand All @@ -18,7 +18,7 @@
<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
for dataset_symbol, data_point in slice.get(BrainWikipediaPageViews).items():
self.log(f"{dataset_symbol} metric at {slice.time}: {data_point.NumberViews1} , {data_point.Buzz1}")</pre>
self.log(f"{dataset_symbol} metric at {slice.time}: {data_point.number_views_1} , {data_point.buzz_1}")</pre>

<pre class="csharp">public override void OnData(Slice slice)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p> To get historical Brain Wikipedia Page Views data, call the <code class="csharp">History</code><code class="python">history</code> method with the dataset <code>Symbol</code>. If there is no data in the period you request, the history result is empty.</p>
<div class="section-example-container">
<pre class="python">history_df = self.history(self.dataset_symbol, 100, Resolution.DAILY) </pre>
<pre class="csharp">var history = History&lt;BrainWikipediaPageViews&gt;(_datasetSymbol, 100, Resolution.Daily); </pre>
<pre class="python">history_df = self.history(self.dataset_symbol, 252, Resolution.DAILY) </pre>
<pre class="csharp">var history = History&lt;BrainWikipediaPageViews&gt;(_datasetSymbol, 252, Resolution.Daily); </pre>
</div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also correct https://www.quantconnect.com/datasets/brain-wikipedia-page-views

changed wrapped in timedelta() to 252 instead for .py .cs

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h4>Classic Algorithm Example</h4>
equity.dataset_symbol = self.add_data(BrainWikipediaPageViews, equity.symbol).symbol

# Historical data
history = self.history(equity.dataset_symbol, 365, Resolution.DAILY)
history = self.history(equity.dataset_symbol, 252, Resolution.DAILY)
self.debug(f"We got {len(history)} items from our history request for {equity.symbol}")

def on_data(self, slice: Slice) -&gt; None:
Expand All @@ -40,10 +40,10 @@ <h4>Classic Algorithm Example</h4>

scores = {}

for point in points.Values:
for point in points.values():
# Example composite signal:
number_of_views = point.NumberViews1 if point.NumberViews1 else 0
buzz1day = point.Buzz1 if point.Buzz1 else 0
number_of_views = point.number_views_1 if point.number_views_1 else 0
buzz1day = point.buzz_1 if point.buzz_1 else 0

symbol = point.symbol.underlying
scores[symbol] = buzz1day * math.sqrt(number_of_views)
Expand Down Expand Up @@ -85,7 +85,7 @@ <h4>Classic Algorithm Example</h4>
var datasetSymbol = AddData&lt;BrainWikipediaPageViews&gt;(symbol).Symbol;

// Historical data (request dataset symbol)
var history = History(datasetSymbol, 365, Resolution.Daily);
var history = History(datasetSymbol, 252, Resolution.Daily);
Debug($"We got {history.Count()} items from our history request for {symbol}");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>To get historical BLS data, call the <code>History</code> method with the dataset <code>Symbol</code>. If there is no data in the period you request, the history result is empty.</p>
<p>To get historical BLS data, call the <code class="csharp">History</code><code class="python">history</code> method with the dataset <code>Symbol</code>. 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
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code is correct
https://www.quantconnect.com/datasets/us-bureau-of-labor-statistics

but Data Point Attributes (about) table is broken!

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>To remove your subscription to BLS data, call the <code>RemoveSecurity</code> method.</p>
<p>To remove your subscription to BLS data, call the <code class="csharp">RemoveSecurity</code><code class="python">remove_security</code> method.</p>

<div class="section-example-container">
<pre class="python">self.remove_security(self._cpi)</pre>
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct
https://www.quantconnect.com/datasets/eodhd-macro-indicators
both .cs .py updated

I think Supported Assets table is missing <div data-tree= formatting

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h4>Classic Algorithm Example</h4>
class EODHDMacroIndicatorsAlgorithm(QCAlgorithm):

def initialize(self):
self.set_start_date(2024, 9, 1)
self.set_start_date(2024, 1, 1)
self.set_end_date(2024, 12, 31)
self.equity_symbol = self.add_equity("SPY", Resolution.DAILY).symbol

ticker = EODHD.MacroIndicators.UnitedStates.GDP_GROWTH_ANNUAL
self.dataset_symbol = self.add_data(EODHDMacroIndicators, ticker).symbol

Expand All @@ -34,7 +34,7 @@ <h4>Classic Algorithm Example</h4>

public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetStartDate(2024, 1, 1);
SetEndDate(2024, 12, 31);
_equitySymbol = AddEquity("SPY", Resolution.Daily).Symbol;
var ticker = EODHD.MacroIndicators.UnitedStates.GdpGrowthAnnual;
Expand All @@ -61,7 +61,7 @@ <h4>Framework Algorithm Example</h4>
class EODHDMacroIndicatorsAlgorithm(QCAlgorithm):

def initialize(self) -&gt; None:
self.set_start_date(2024, 9, 1)
self.set_start_date(2024, 1, 1)
self.set_end_date(2024, 12, 31)
# Use market ETF as a vehicle to trade.
symbol = Symbol.create("SPY", SecurityType.EQUITY, Market.USA)
Expand Down Expand Up @@ -98,7 +98,7 @@ <h4>Framework Algorithm Example</h4>
{
public override void Initialize()
{
SetStartDate(2024, 9, 1);
SetStartDate(2024, 1, 1);
SetEndDate(2024, 12, 31);
// Use market ETF as a vehicle to trade.
var symbol = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<p>You can get historical universe data in an algorithm and in the Research Environment.</p>

<h4>Historical Universe Data in Algorithms</h4>
<p>To get historical universe data in an algorithm, call the <code class="csharp">History</code><code class="python">history</code> method with the <code>Universe</code> object and the lookback period. If there is no data in the period you request, the history result is empty.</p>

<div class="section-example-container">
<pre class="csharp">var universeHistory = History(_universe, 30, Resolution.Daily);
foreach (var dividends in universeHistory)
{
foreach (EODHDUpcomingDividends dividend in dividends)
{
Log($"{dividend.Symbol} dividend on {dividend.DividendDate}: {dividend.dividend}");
}
}</pre>
<pre class="python"># DataFrame example where the columns are the EODHDUpcomingDividends attributes:
history_df = self.history(self._universe, 30, Resolution.DAILY, flatten=True)

# Series example where the values are lists of EODHDUpcomingDividends objects:
universe_history = self.history(self._universe, 30, Resolution.DAILY)
for (_, time), dividends in universe_history.items():
for dividend in dividends:
self.log(f"{dividend.symbol} dividend on {dividend.dividend_date}: {dividend.dividend}")</pre>
</div>

<h4>Historical Universe Data in Research</h4>
<p>To get historical universe data in research, call the <code class="csharp">History</code><code class="python">history</code> method with the <code>Universe</code> object, a start date, and an end date. This method returns the filtered universe. If there is no data in the period you request, the history result is empty.</p>

<div class="section-example-container">
<pre class="csharp">var universeHistory = qb.History(universe, qb.Time.AddDays(-30), qb.Time);
foreach (var dividends in universeHistory)
{
foreach (EODHDUpcomingDividends dividend in dividends)
{
Console.WriteLine($"{dividend.Symbol} dividend on {dividend.DividendDate}: {dividend.dividend}");
}
}</pre>
<pre class="python"># DataFrame example where the columns are the EODHDUpcomingDividends attributes:
history = qb.history(universe, qb.time-timedelta(30), qb.time, flatten=True)</pre>
</div>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct
https://www.quantconnect.com/datasets/eodhd-upcoming-earnings

in Accessing Data (Documentation) page:
if (upcomingEarnings.TryGetValue(_symbol, out var upcomingEarningsDataPoint))

I am not sure if we should use TryGetValue

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<div class="section-example-container">
<pre class="python">def on_data(self, slice: Slice) -&gt; None:
upcomings_earnings_for_symbol = slice.get(EODHDUpcomingEarnings).get(self._symbol)
if upcomings_earnings_for_symbol:
self.log(f"{self._symbol} will report earnings at {upcomings_earnings_for_symbol.report_date} {upcomings_earnings_for_symbol.report_time} with estimated EPS {upcomings_earnings_for_symbol.estimate}")</pre>
if upcomings_earnings_for_symbol:
self.log(f"{self._symbol} will report earnings at {upcomings_earnings_for_symbol.report_date} {upcomings_earnings_for_symbol.report_time} with estimated EPS {upcomings_earnings_for_symbol.estimate}")</pre>
<pre class="csharp">public override void OnData(Slice slice)
{
var upcomingEarnings = slice.Get&lt;EODHDUpcomingEarnings&gt;();
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is correct: self.history[EODHDUpcomingEarnings](timedelta(100), Resolution.DAILY).loc[self._symbol]
https://www.quantconnect.com/datasets/eodhd-upcoming-earnings

fixed this too: <b>EODHDUpcomingEarning</b> -> <b>EODHDUpcomingEarnings</b>.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>To get historical Upcoming Earnings for the universe, call the <code class="csharp">History</code><code class="python">history</code> method with the type <code>EODHDUpcomingEarning</code>.</p>
<p>To get historical Upcoming Earnings for the universe, call the <code class="csharp">History</code><code class="python">history</code> method with the type <code>EODHDUpcomingEarnings</code>.</p>

<div class="section-example-container">
<pre class="python">history = self.history(EODHDUpcomingEarnings, timedelta(100), Resolution.DAILY)</pre>
Expand Down
Loading