Skip to content

Commit

Permalink
Merge pull request QuantConnect#3736 from gsalaz98/feature-add-histor…
Browse files Browse the repository at this point in the history
…y-requests-to-demo-altdata-algorithms

Implement History request in demo AltData algorithms
  • Loading branch information
jaredbroad authored Oct 16, 2019
2 parents 70875a3 + 0aadd2b commit 7ac11ae
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Algorithm.CSharp/AltData/PsychSignalSentimentAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public override void Initialize()
SetCash(100000);

AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));

// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add news data for the underlying IBM asset
var psy = AddData<PsychSignalSentiment>(ibm).Symbol;
// Request 120 minutes of history with the PsychSignal IBM Custom Data Symbol.
var history = History<PsychSignalSentiment>(psy, 120, Resolution.Minute);

// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}

/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.CSharp/AltData/SECReport8KAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public override void Initialize()

UniverseSettings.Resolution = Resolution.Minute;
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));

// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add SEC report 10-Q data for the underlying IBM asset
var earningsFiling = AddData<SECReport10Q>(ibm).Symbol;
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);

// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}

public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.CSharp/AltData/SmartInsiderTransactionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public override void Initialize()
SetCash(1000000);

AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));

// Request underlying equity data.
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add Smart Insider stock buyback transaction data for the underlying IBM asset
var si = AddData<SmartInsiderTransaction>(ibm).Symbol;
// Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol.
var history = History<SmartInsiderTransaction>(si, 60, Resolution.Daily);

// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}

public IEnumerable<Symbol> CoarseUniverse(IEnumerable<CoarseFundamental> coarse)
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.CSharp/AltData/TiingoNewsAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public override void Initialize()

var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
_tiingoSymbol = AddData<TiingoNews>(aapl).Symbol;

// Request underlying equity data
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
// Add news data for the underlying IBM asset
var news = AddData<TiingoNews>(ibm).Symbol;
// Request 60 days of history with the TiingoNews IBM Custom Data Symbol.
var history = History<TiingoNews>(news, 60, Resolution.Daily);

// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}

public override void OnData(Slice data)
Expand Down
8 changes: 8 additions & 0 deletions Algorithm.CSharp/AltData/TradingEconomicsAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Custom.TradingEconomics;

Expand All @@ -35,6 +36,13 @@ public override void Initialize()
AddEquity("SPY", Resolution.Hour);

_interestRate = AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol;

// Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
// We should expect no historical data because 2013-11-01 is before the absolute first point of data
var history = History<TradingEconomicsCalendar>(_interestRate, 365, Resolution.Daily);

// Count the number of items we get from our history request (should be zero)
Debug($"We got {history.Count()} items from our history request");
}

public override void OnData(Slice data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public override void Initialize()
SetCash(100000);

_spy = AddEquity("SPY", Resolution.Hour).Symbol;
_yieldCurve = AddData<USTreasuryYieldCurveRate>("YIELDCURVE").Symbol;
_yieldCurve = AddData<USTreasuryYieldCurveRate>("USTYCR").Symbol;

// Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
var history = History<USTreasuryYieldCurveRate>(_yieldCurve, 60, Resolution.Daily);

// Count the number of items we get from our history request
Debug($"We got {history.Count()} items from our history request");
}

public override void OnData(Slice data)
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.Python/AltData/PsychSignalSentimentAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def Initialize(self):
self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseUniverse))
self.timeEntered = datetime(1, 1, 1)

# Request underlying equity data.
ibm = self.AddEquity("IBM", Resolution.Minute).Symbol
# Add sentiment data for the underlying IBM asset
psy = self.AddData(PsychSignalSentiment, ibm).Symbol
# Request 120 minutes of history with the PsychSignal IBM Custom Data Symbol
history = self.History(PsychSignalSentiment, psy, 120, Resolution.Minute)

# Count the number of items we get from our history request
self.Debug(f"We got {len(history)} items from our history request")

# You can use custom data with a universe of assets.
def CoarseUniverse(self, coarse):
if (self.Time - self.timeEntered) <= timedelta(days=10):
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.Python/AltData/SECReport8KAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def Initialize(self):
self.UniverseSettings.Resolution = Resolution.Minute
self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseSelector))

# Request underlying equity data.
ibm = self.AddEquity("IBM", Resolution.Minute).Symbol
# Add news data for the underlying IBM asset
earningsFiling = self.AddData(SECReport10Q, ibm).Symbol
# Request 120 days of history with the SECReport10Q IBM custom data Symbol
history = self.History(SECReport10Q, earningsFiling, 120, Resolution.Daily)

# Count the number of items we get from our history request
self.Debug(f"We got {len(history)} items from our history request")

def CoarseSelector(self, coarse):
# Add SEC data from the filtered coarse selection
symbols = [i.Symbol for i in coarse if i.HasFundamentalData and i.DollarVolume > 50000000][:10]
Expand Down
10 changes: 10 additions & 0 deletions Algorithm.Python/AltData/SmartInsiderTransactionAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ def Initialize(self):

self.AddUniverseSelection(CoarseFundamentalUniverseSelectionModel(self.CoarseUniverse))

# Request underlying equity data.
ibm = self.AddEquity("IBM", Resolution.Minute).Symbol
# Add Smart Insider stock buyback transaction data for the underlying IBM asset
si = self.AddData(SmartInsiderTransaction, ibm).Symbol
# Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol
history = self.History(SmartInsiderTransaction, si, 60, Resolution.Daily)

# Count the number of items we get from our history request
self.Debug(f"We got {len(history)} items from our history request")

def CoarseUniverse(self, coarse):
symbols = [i.Symbol for i in coarse if i.HasFundamentalData and i.DollarVolume > 50000000][:10]

Expand Down
10 changes: 10 additions & 0 deletions Algorithm.Python/AltData/TiingoNewsAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def Initialize(self):
aapl = self.AddEquity("AAPL", Resolution.Hour).Symbol
self.aaplCustom = self.AddData(TiingoNews, aapl).Symbol

# Request underlying equity data.
ibm = self.AddEquity("IBM", Resolution.Minute).Symbol
# Add news data for the underlying IBM asset
news = self.AddData(TiingoNews, ibm).Symbol
# Request 60 days of history with the TiingoNews IBM Custom Data Symbol
history = self.History(TiingoNews, news, 60, Resolution.Daily)

# Count the number of items we get from our history request
self.Debug(f"We got {len(history)} items from our history request")

def OnData(self, data):
# Confirm that the data is in the collection
if not data.ContainsKey(self.aaplCustom):
Expand Down
7 changes: 7 additions & 0 deletions Algorithm.Python/AltData/TradingEconomicsAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def Initialize(self):
self.AddEquity("SPY", Resolution.Hour)
self.interestRate = self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol

# Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
# We should expect no historical data because 2013-11-01 is before the absolute first point of data
history = self.History(TradingEconomicsCalendar, self.interestRate, 365, Resolution.Daily)

# Count the amount of items we get from our history request (should be zero)
self.Debug(f"We got {len(history)} items from our history request")

def OnData(self, data):
# Make sure we have an interest rate calendar event
if not data.ContainsKey(self.interestRate):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def Initialize(self):
self.SetCash(100000)

self.spy = self.AddEquity("SPY", Resolution.Hour).Symbol
self.yieldCurve = self.AddData(USTreasuryYieldCurveRate, "YIELDCURVE").Symbol
self.yieldCurve = self.AddData(USTreasuryYieldCurveRate, "USTYCR").Symbol
self.lastInversion = datetime(1, 1, 1)

# Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
history = self.History(USTreasuryYieldCurveRate, self.yieldCurve, 60, Resolution.Daily)

# Count the number of items we get from our history request
self.Debug(f"We got {len(history)} items from our history request")

def OnData(self, data):

if not data.ContainsKey(self.yieldCurve):
Expand Down

0 comments on commit 7ac11ae

Please sign in to comment.