Regression algos updated and python algorithms moved to DataSource repos
This commit is contained in:
@@ -1,91 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.Benzinga import *
|
||||
|
||||
### <summary>
|
||||
### Benzinga is a provider of news data. Their news is made in-house
|
||||
### and covers stock related news such as corporate events.
|
||||
### </summary>
|
||||
class BenzingaNewsAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.words = {
|
||||
"bad": -0.5, "good": 0.5,
|
||||
"negative": -0.5, "great": 0.5,
|
||||
"growth": 0.5, "fail": -0.5,
|
||||
"failed": -0.5, "success": 0.5,
|
||||
"nailed": 0.5, "beat": 0.5,
|
||||
"missed": -0.5
|
||||
}
|
||||
|
||||
self.lastTrade = datetime(1, 1, 1)
|
||||
|
||||
self.SetStartDate(2018, 6, 5)
|
||||
self.SetEndDate(2018, 8, 4)
|
||||
self.SetCash(100000)
|
||||
|
||||
aapl = self.AddEquity("AAPL", Resolution.Hour).Symbol
|
||||
ibm = self.AddEquity("IBM", Resolution.Hour).Symbol
|
||||
|
||||
self.AddData(BenzingaNews, aapl)
|
||||
self.AddData(BenzingaNews, ibm)
|
||||
|
||||
def OnData(self, data):
|
||||
if (self.Time - self.lastTrade) < timedelta(days=5):
|
||||
return
|
||||
|
||||
# Get rid of our holdings after 5 days, and start fresh
|
||||
self.Liquidate()
|
||||
|
||||
# Get all Benzinga data and loop over it
|
||||
for article in data.Get(BenzingaNews).Values:
|
||||
selectedSymbol = None
|
||||
|
||||
# Use loop instead of list comprehension for clarity purposes
|
||||
|
||||
# Select the same Symbol we're getting a data point for
|
||||
# from the articles list so that we can get the sentiment of the article
|
||||
# We use the underlying Symbol because the Symbols included in the `Symbols` property
|
||||
# are equity Symbols.
|
||||
for symbol in article.Symbols:
|
||||
if symbol == article.Symbol.Underlying:
|
||||
selectedSymbol = symbol
|
||||
break
|
||||
|
||||
if selectedSymbol is None:
|
||||
raise Exception(f"Could not find current Symbol {article.Symbol.Underlying} even though it should exist")
|
||||
|
||||
# The intersection of the article contents and the pre-defined words are the words that are included in both collections
|
||||
intersection = set(article.Contents.lower().split(" ")).intersection(list(self.words.keys()))
|
||||
# Get the words, then get the aggregate sentiment
|
||||
sentimentSum = sum([self.words[i] for i in intersection])
|
||||
|
||||
if sentimentSum >= 0.5:
|
||||
self.Log(f"Longing {article.Symbol.Underlying} with sentiment score of {sentimentSum}")
|
||||
self.SetHoldings(article.Symbol.Underlying, sentimentSum / 5)
|
||||
|
||||
self.lastTrade = self.Time
|
||||
|
||||
if sentimentSum <= -0.5:
|
||||
self.Log(f"Shorting {article.Symbol.Underlying} with sentiment score of {sentimentSum}")
|
||||
self.SetHoldings(article.Symbol.Underlying, sentimentSum / 5)
|
||||
|
||||
self.lastTrade = self.Time
|
||||
|
||||
def OnSecuritiesChanged(self, changes):
|
||||
for r in changes.RemovedSecurities:
|
||||
# If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
self.Liquidate(r.Symbol)
|
||||
self.RemoveSecurity(Symbol.CreateBase(BenzingaNews, r.Symbol, Market.USA))
|
||||
@@ -1,47 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.CBOE import *
|
||||
from QuantConnect.Data.Custom.Fred import *
|
||||
from QuantConnect.Data.Custom.USEnergy import *
|
||||
|
||||
class CachedAlternativeDataAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2003, 1, 1)
|
||||
self.SetEndDate(2019, 10, 11)
|
||||
self.SetCash(100000)
|
||||
|
||||
# QuantConnect caches a small subset of alternative data for easy consumption for the community.
|
||||
# You can use this in your algorithm as demonstrated below:
|
||||
|
||||
self.cboeVix = self.AddData(CBOE, "VIX", Resolution.Daily).Symbol
|
||||
# United States EIA data: https://eia.gov/
|
||||
self.usEnergy = self.AddData(USEnergy, USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries, Resolution.Daily).Symbol
|
||||
# FRED data
|
||||
self.fredPeakToTrough = self.AddData(Fred, Fred.OECDRecessionIndicators.UnitedStatesFromPeakThroughTheTrough, Resolution.Daily).Symbol
|
||||
|
||||
def OnData(self, data):
|
||||
if data.ContainsKey(self.cboeVix):
|
||||
vix = data.Get(CBOE, self.cboeVix)
|
||||
self.Log(f"VIX: {vix}")
|
||||
|
||||
if data.ContainsKey(self.usEnergy):
|
||||
inputIntoRefineries = data.Get(USEnergy, self.usEnergy)
|
||||
self.Log(f"U.S. Input Into Refineries: {inputIntoRefineries}")
|
||||
|
||||
if data.ContainsKey(self.fredPeakToTrough):
|
||||
peakToTrough = data.Get(Fred, self.fredPeakToTrough)
|
||||
self.Log(f"OECD based Recession Indicator for the United States from the Peak through the Trough: {peakToTrough}")
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.Quiver import *
|
||||
|
||||
### <summary>
|
||||
### Quiver Quantitative is a provider of alternative data.
|
||||
### This algorithm shows how to consume the 'QuiverWallStreetBets'
|
||||
### </summary>
|
||||
class QuiverWallStreetBetsDataAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2019, 1, 1)
|
||||
self.SetEndDate(2020, 6, 1)
|
||||
self.SetCash(100000)
|
||||
|
||||
aapl = self.AddEquity("AAPL", Resolution.Daily).Symbol
|
||||
quiverWSBSymbol = self.AddData(QuiverWallStreetBets, aapl).Symbol
|
||||
history = self.History(QuiverWallStreetBets, quiverWSBSymbol, 60, Resolution.Daily)
|
||||
|
||||
self.Debug(f"We got {len(history)} items from our history request")
|
||||
|
||||
def OnData(self, data):
|
||||
points = data.Get(QuiverWallStreetBets)
|
||||
for point in points.Values:
|
||||
# Go long in the stock if it was mentioned more than 5 times in the WallStreetBets daily discussion
|
||||
if point.Mentions > 5:
|
||||
self.SetHoldings(point.Symbol.Underlying, 1)
|
||||
|
||||
# Go short in the stock if it was mentioned less than 5 times in the WallStreetBets daily discussion
|
||||
if point.Mentions < 5:
|
||||
self.SetHoldings(point.Symbol.Underlying, -1)
|
||||
@@ -1,66 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
|
||||
class SECReport8KAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2019, 1, 1)
|
||||
self.SetEndDate(2019, 8, 21)
|
||||
self.SetCash(100000)
|
||||
|
||||
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, Resolution.Daily).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]
|
||||
|
||||
for symbol in symbols:
|
||||
self.AddData(SECReport8K, symbol)
|
||||
|
||||
return symbols
|
||||
|
||||
def OnData(self, data):
|
||||
# Store the symbols we want to long in a list
|
||||
# so that we can have an equal-weighted portfolio
|
||||
longEquitySymbols = []
|
||||
|
||||
# Get all SEC data and loop over it
|
||||
for report in data.Get(SECReport8K).Values:
|
||||
# Get the length of all contents contained within the report
|
||||
reportTextLength = sum([len(i.Text) for i in report.Report.Documents])
|
||||
|
||||
if reportTextLength > 20000:
|
||||
longEquitySymbols.append(report.Symbol.Underlying)
|
||||
|
||||
for equitySymbol in longEquitySymbols:
|
||||
self.SetHoldings(equitySymbol, 1.0 / len(longEquitySymbols))
|
||||
|
||||
def OnSecuritiesChanged(self, changes):
|
||||
for r in changes.RemovedSecurities:
|
||||
# If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
self.Liquidate(r.Symbol)
|
||||
self.RemoveSecurity(Symbol.CreateBase(SECReport8K, r.Symbol, Market.USA))
|
||||
@@ -1,62 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SmartInsider import *
|
||||
|
||||
class SmartInsiderTransactionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2019, 3, 1)
|
||||
self.SetEndDate(2019, 7, 4)
|
||||
self.SetCash(1000000)
|
||||
|
||||
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]
|
||||
|
||||
for symbol in symbols:
|
||||
self.AddData(SmartInsiderTransaction, symbol)
|
||||
|
||||
return symbols
|
||||
|
||||
def OnData(self, data):
|
||||
|
||||
# Get all SmartInsider data available
|
||||
transactions = data.Get(SmartInsiderTransaction)
|
||||
|
||||
# Loop over all the insider transactions
|
||||
for transaction in transactions.Values:
|
||||
if transaction.VolumePercentage is None or transaction.EventType is None:
|
||||
continue
|
||||
|
||||
# Using the SmartInsider transaction information, buy when company does a stock buyback
|
||||
if transaction.EventType == SmartInsiderEventType.Transaction and transaction.VolumePercentage > 5:
|
||||
self.SetHoldings(transaction.Symbol.Underlying, transaction.VolumePercentage / 100)
|
||||
|
||||
def OnSecuritiesChanged(self, changes):
|
||||
for r in changes.RemovedSecurities:
|
||||
# If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
self.Liquidate(r.Symbol)
|
||||
self.RemoveSecurity(Symbol.CreateBase(SmartInsiderTransaction, r.Symbol, Market.USA))
|
||||
@@ -1,70 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.Tiingo import *
|
||||
|
||||
### <summary>
|
||||
### Look for positive and negative words in the news article description
|
||||
### and trade based on the sum of the sentiment
|
||||
### </summary>
|
||||
class TiingoNewsAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
# Predefine a dictionary of words with scores to scan for in the description
|
||||
# of the Tiingo news article
|
||||
self.words = {
|
||||
"bad": -0.5, "good": 0.5,
|
||||
"negative": -0.5, "great": 0.5,
|
||||
"growth": 0.5, "fail": -0.5,
|
||||
"failed": -0.5, "success": 0.5, "nailed": 0.5,
|
||||
"beat": 0.5, "missed": -0.5,
|
||||
}
|
||||
|
||||
self.SetStartDate(2019, 6, 10)
|
||||
self.SetEndDate(2019, 10, 3)
|
||||
self.SetCash(100000)
|
||||
|
||||
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):
|
||||
return
|
||||
|
||||
# Gets the data from the slice
|
||||
article = data[self.aaplCustom]
|
||||
|
||||
# Article descriptions come in all caps. Lower and split by word
|
||||
descriptionWords = article.Description.lower().split(" ")
|
||||
|
||||
# Take the intersection of predefined words and the words in the
|
||||
# description to get a list of matching words
|
||||
intersection = set(self.words.keys()).intersection(descriptionWords)
|
||||
|
||||
# Get the sum of the article's sentiment, and go long or short
|
||||
# depending if it's a positive or negative description
|
||||
sentiment = sum([self.words[i] for i in intersection])
|
||||
|
||||
self.SetHoldings(article.Symbol.Underlying, sentiment)
|
||||
@@ -1,57 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.TradingEconomics import *
|
||||
|
||||
### <summary>
|
||||
### Trades on interest rate announcements from data provided by Trading Economics
|
||||
### </summary>
|
||||
class TradingEconomicsAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2013, 11, 1)
|
||||
self.SetEndDate(2019, 10, 3)
|
||||
self.SetCash(100000)
|
||||
|
||||
self.AddEquity("AGG", Resolution.Hour)
|
||||
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):
|
||||
return
|
||||
|
||||
announcement = data[self.interestRate]
|
||||
|
||||
# Confirm its a FED Rate Decision
|
||||
if announcement.Event != TradingEconomics.Event.UnitedStates.FedInterestRateDecision:
|
||||
return
|
||||
|
||||
# In the event of a rate increase, rebalance 50% to Bonds.
|
||||
interestRateDecreased = announcement.Actual <= announcement.Previous
|
||||
|
||||
if interestRateDecreased:
|
||||
self.SetHoldings("SPY", 1)
|
||||
self.SetHoldings("AGG", 0)
|
||||
else:
|
||||
self.SetHoldings("SPY", 0.5)
|
||||
self.SetHoldings("AGG", 0.5)
|
||||
@@ -1,63 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.USTreasury import *
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
class USTreasuryYieldCurveRateAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
|
||||
self.SetStartDate(2000, 3, 1)
|
||||
self.SetEndDate(2019, 9, 15)
|
||||
self.SetCash(100000)
|
||||
|
||||
self.spy = self.AddEquity("SPY", Resolution.Hour).Symbol
|
||||
self.yieldCurve = self.AddData(USTreasuryYieldCurveRate, "USTYCR", Resolution.Daily).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):
|
||||
return
|
||||
|
||||
rates = data[self.yieldCurve]
|
||||
|
||||
# Check for None before using the values
|
||||
if rates.TenYear is None or rates.TwoYear is None:
|
||||
return
|
||||
|
||||
# Only advance if a year has gone by
|
||||
if (self.Time - self.lastInversion) < timedelta(days=365):
|
||||
return
|
||||
|
||||
# if there is a yield curve inversion after not having one for a year, short SPY for two years
|
||||
if not self.Portfolio.Invested and rates.TwoYear > rates.TenYear:
|
||||
self.Debug(f"{self.Time} - Yield curve inversion! Shorting the market for two years")
|
||||
self.SetHoldings(self.spy, -0.5)
|
||||
|
||||
self.lastInversion = self.Time
|
||||
|
||||
return
|
||||
|
||||
# If two years have passed, liquidate our position in SPY
|
||||
if self.Time - self.lastInversion >= timedelta(days=365 * 2):
|
||||
self.Liquidate(self.spy)
|
||||
@@ -1,38 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
|
||||
class SECReportBenchmarkAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
self.SetStartDate(2018, 1, 1)
|
||||
self.SetEndDate(2019, 1, 1)
|
||||
|
||||
tickers = {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ", "IWM", "BAC", "BNO", "AIG", "UW", "WM" }
|
||||
self.securities = []
|
||||
for ticker in tickers:
|
||||
security = self.AddEquity(ticker)
|
||||
self.securities.append(security)
|
||||
self.AddData(SECReport10K, security.Symbol, Resolution.Daily)
|
||||
self.AddData(SECReport8K, security.Symbol, Resolution.Daily)
|
||||
|
||||
def OnData(self, slice):
|
||||
for security in self.securities:
|
||||
report8K = security.Data.Get(SECReport8K)
|
||||
report10K = security.Data.Get(SECReport10K)
|
||||
|
||||
if not security.HoldStock and report8K != None and report10K != None:
|
||||
self.SetHoldings(security.Symbol, 1 / len(self.securities))
|
||||
@@ -1,51 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SmartInsider import *
|
||||
|
||||
class SmartInsiderEventBenchmarkAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
self.SetStartDate(2010, 1, 1)
|
||||
self.SetEndDate(2019, 1, 1)
|
||||
|
||||
tickers = {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ", "IWM", "BAC", "BNO", "AIG", "UW", "WM" }
|
||||
self.securities = []
|
||||
self.customSymbols = []
|
||||
for ticker in tickers:
|
||||
security = self.AddEquity(ticker, Resolution.Hour)
|
||||
self.securities.append(security)
|
||||
|
||||
intetion = self.AddData(SmartInsiderIntention, security.Symbol, Resolution.Daily)
|
||||
transaction = self.AddData(SmartInsiderTransaction, security.Symbol, Resolution.Daily)
|
||||
self.customSymbols.append(intetion.Symbol)
|
||||
self.customSymbols.append(transaction.Symbol)
|
||||
|
||||
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(16, 0), self.DailyRebalance)
|
||||
|
||||
def OnData(self, slice):
|
||||
intentions = slice.Get(SmartInsiderIntention)
|
||||
transactions = slice.Get(SmartInsiderTransaction)
|
||||
|
||||
def DailyRebalance(self):
|
||||
history = self.History(self.customSymbols, timedelta(5))
|
||||
historySymbolCount = len(history.index)
|
||||
|
||||
for security in self.securities:
|
||||
intention = security.Data.Get(SmartInsiderIntention)
|
||||
transaction = security.Data.Get(SmartInsiderTransaction)
|
||||
|
||||
if not security.HoldStock and intention != None and transaction != None:
|
||||
self.SetHoldings(security.Symbol, 1 / len(self.securities))
|
||||
@@ -1,68 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.Tiingo import *
|
||||
|
||||
### <summary>
|
||||
### Example algorithm of a custom universe selection using coarse data and adding TiingoNews
|
||||
### If conditions are met will add the underlying and trade it
|
||||
### </summary>
|
||||
class CoarseTiingoNewsUniverseSelectionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
|
||||
|
||||
self.SetStartDate(2014,3,24)
|
||||
self.SetEndDate(2014,4,7)
|
||||
|
||||
self.UniverseSettings.FillForward = False
|
||||
|
||||
self.__numberOfSymbols = 3
|
||||
|
||||
self.AddUniverse(CustomDataCoarseFundamentalUniverse(self.UniverseSettings, self.CoarseSelectionFunction))
|
||||
|
||||
self._symbols = []
|
||||
|
||||
# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
def CoarseSelectionFunction(self, coarse):
|
||||
# sort descending by daily dollar volume
|
||||
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
|
||||
|
||||
# return the symbol objects of the top entries from our sorted collection
|
||||
return [ Symbol.CreateBase(TiingoNews, x.Symbol, x.Symbol.ID.Market) for x in sortedByDollarVolume[:self.__numberOfSymbols] ]
|
||||
|
||||
def OnData(self, data):
|
||||
articles = data.Get(TiingoNews)
|
||||
|
||||
for kvp in articles:
|
||||
news = kvp.Value
|
||||
if "stocks drop" in news.Title.lower():
|
||||
if not self.Securities.ContainsKey(kvp.Key.Underlying):
|
||||
# add underlying we want to trade
|
||||
self.AddSecurity(kvp.Key.Underlying)
|
||||
self._symbols.append(kvp.Key.Underlying)
|
||||
|
||||
for symbol in self._symbols:
|
||||
if self.Securities[symbol].HasData:
|
||||
self.SetHoldings(symbol, 1.0 / len(self._symbols))
|
||||
|
||||
def OnSecuritiesChanged(self, changes):
|
||||
changes.FilterCustomSecurities = False
|
||||
self.Log(f"{self.Time} {changes}")
|
||||
|
||||
class CustomDataCoarseFundamentalUniverse(CoarseFundamentalUniverse):
|
||||
def GetSubscriptionRequests(self, security, currentTimeUtc, maximumEndTimeUtc, subscriptionService):
|
||||
us = self.UniverseSettings
|
||||
config = subscriptionService.Add(TiingoNews, security.Symbol, us.Resolution, us.FillForward, us.ExtendedMarketHours, True, False, False, us.DataNormalizationMode)
|
||||
return [ SubscriptionRequest(False, self, security, config, currentTimeUtc, maximumEndTimeUtc) ]
|
||||
+13
-14
@@ -12,14 +12,13 @@
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
from QuantConnect.Data.Custom.USTreasury import *
|
||||
from QuantConnect.Data.Custom.IconicTypes import *
|
||||
|
||||
### <summary>
|
||||
### Regression algorithm checks that adding data via AddData
|
||||
### works as expected
|
||||
### </summary>
|
||||
class CustomDataAddDataRegressionAlgorithm(QCAlgorithm):
|
||||
class CustomDataIconicTypesAddDataRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2013, 10, 7)
|
||||
@@ -32,28 +31,28 @@ class CustomDataAddDataRegressionAlgorithm(QCAlgorithm):
|
||||
self.googlEquity = self.AddEquity("GOOGL", Resolution.Daily).Symbol
|
||||
customGooglSymbol = self.AddData(SECReport10K, "GOOGL", Resolution.Daily).Symbol
|
||||
|
||||
usTreasury = self.AddData(USTreasuryYieldCurveRate, "GOOGL", Resolution.Daily).Symbol
|
||||
usTreasuryUnderlyingEquity = Symbol.Create("MSFT", SecurityType.Equity, Market.USA)
|
||||
usTreasuryUnderlying = self.AddData(USTreasuryYieldCurveRate, usTreasuryUnderlyingEquity, Resolution.Daily).Symbol
|
||||
unlinkedDataSymbol = self.AddData(UnlinkedData, "GOOGL", Resolution.Daily).Symbol
|
||||
unlinkedDataSymbolUnderlyingEquity = Symbol.Create("MSFT", SecurityType.Equity, Market.USA)
|
||||
unlinkedDataSymbolUnderlying = self.AddData(UnlinkedData, unlinkedDataSymbolUnderlyingEquity, Resolution.Daily).Symbol
|
||||
|
||||
optionSymbol = self.AddOption("TWX", Resolution.Minute).Symbol
|
||||
customOptionSymbol = self.AddData(SECReport10K, optionSymbol, Resolution.Daily).Symbol
|
||||
customOptionSymbol = self.AddData(LinkedData, optionSymbol, Resolution.Daily).Symbol
|
||||
|
||||
if customTwxSymbol.Underlying != twxEquity:
|
||||
raise Exception(f"Underlying symbol for {customTwxSymbol} is not equal to TWX equity. Expected {twxEquity} got {customTwxSymbol.Underlying}")
|
||||
if customGooglSymbol.Underlying != self.googlEquity:
|
||||
raise Exception(f"Underlying symbol for {customGooglSymbol} is not equal to GOOGL equity. Expected {self.googlEquity} got {customGooglSymbol.Underlying}")
|
||||
if usTreasury.HasUnderlying:
|
||||
raise Exception(f"US Treasury yield curve (no underlying) has underlying when it shouldn't. Found {usTreasury.Underlying}")
|
||||
if not usTreasuryUnderlying.HasUnderlying:
|
||||
raise Exception("US Treasury yield curve (with underlying) has no underlying Symbol even though we added with Symbol")
|
||||
if usTreasuryUnderlying.Underlying != usTreasuryUnderlyingEquity:
|
||||
raise Exception(f"US Treasury yield curve underlying does not equal equity Symbol added. Expected {usTreasuryUnderlyingEquity} got {usTreasuryUnderlying.Underlying}")
|
||||
if unlinkedDataSymbol.HasUnderlying:
|
||||
raise Exception(f"Unlinked data type (no underlying) has underlying when it shouldn't. Found {unlinkedDataSymbol.Underlying}")
|
||||
if not unlinkedDataSymbolUnderlying.HasUnderlying:
|
||||
raise Exception("Unlinked data type (with underlying) has no underlying Symbol even though we added with Symbol")
|
||||
if unlinkedDataSymbolUnderlying.Underlying != unlinkedDataSymbolUnderlyingEquity:
|
||||
raise Exception(f"Unlinked data type underlying does not equal equity Symbol added. Expected {unlinkedDataSymbolUnderlyingEquity} got {unlinkedDataSymbolUnderlying.Underlying}")
|
||||
if customOptionSymbol.Underlying != optionSymbol:
|
||||
raise Exception("Option symbol not equal to custom underlying symbol. Expected {optionSymbol} got {customOptionSymbol.Underlying}")
|
||||
|
||||
try:
|
||||
customDataNoCache = self.AddData(SECReport10Q, "AAPL", Resolution.Daily)
|
||||
customDataNoCache = self.AddData(LinkedData, "AAPL", Resolution.Daily)
|
||||
raise Exception("AAPL was found in the SymbolCache, though it should be missing")
|
||||
except InvalidOperationException as e:
|
||||
return
|
||||
+3
-3
@@ -12,9 +12,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
from QuantConnect.Data.Custom.IconicTypes import *
|
||||
|
||||
class CustomDataAddDataCoarseSelectionRegressionAlgorithm(QCAlgorithm):
|
||||
class CustomDataLinkedIconicTypeAddDataCoarseSelectionRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2014, 3, 24)
|
||||
@@ -38,7 +38,7 @@ class CustomDataAddDataCoarseSelectionRegressionAlgorithm(QCAlgorithm):
|
||||
self.customSymbols = []
|
||||
|
||||
for symbol in symbols:
|
||||
self.customSymbols.append(self.AddData(SECReport8K, symbol, Resolution.Daily).Symbol)
|
||||
self.customSymbols.append(self.AddData(LinkedData, symbol, Resolution.Daily).Symbol)
|
||||
|
||||
return symbols
|
||||
|
||||
+3
-3
@@ -12,9 +12,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
from QuantConnect.Data.Custom.IconicTypes import *
|
||||
|
||||
class CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm(QCAlgorithm):
|
||||
class CustomDataLinkedIconicTypeAddDataOnSecuritiesChangedRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2014, 3, 24)
|
||||
@@ -52,4 +52,4 @@ class CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm(QCAlgorithm):
|
||||
self.customSymbols = []
|
||||
iterated = True
|
||||
|
||||
self.customSymbols.append(self.AddData(SECReport8K, added.Symbol, Resolution.Daily).Symbol)
|
||||
self.customSymbols.append(self.AddData(LinkedData, added.Symbol, Resolution.Daily).Symbol)
|
||||
@@ -1,56 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
|
||||
### <summary>
|
||||
### Provides an example algorithm showcasing the Security.Data features
|
||||
### </summary>
|
||||
class DynamicSecurityDataAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.Ticker = "GOOGL"
|
||||
|
||||
self.SetStartDate(2015, 10, 22)
|
||||
self.SetEndDate(2015, 10, 30)
|
||||
|
||||
self.GOOGL = self.AddEquity(self.Ticker, Resolution.Daily)
|
||||
|
||||
self.AddData(SECReport8K, self.Ticker, Resolution.Daily)
|
||||
self.AddData(SECReport10K, self.Ticker, Resolution.Daily)
|
||||
self.AddData(SECReport10Q, self.Ticker, Resolution.Daily)
|
||||
|
||||
def OnData(self, data):
|
||||
|
||||
# The Security object's Data property provides convenient access
|
||||
# to the various types of data related to that security. You can
|
||||
# access not only the security's price data, but also any custom
|
||||
# data that is mapped to the security, such as our SEC reports.
|
||||
|
||||
# 1. Get the most recent data point of a particular type:
|
||||
# 1.a Using the generic method, Get(T): => T
|
||||
googlSec8kReport = self.GOOGL.Data.Get(SECReport8K)
|
||||
googlSec10kReport = self.GOOGL.Data.Get(SECReport10K)
|
||||
self.Log("{}: 8K: {}".format(self.Time, googlSec8kReport))
|
||||
self.Log("{}: 10K: {}".format(self.Time, googlSec10kReport))
|
||||
|
||||
# 2. Get the list of data points of a particular type for the most recent time step:
|
||||
# 2.a Using the generic method, GetAll(T): => IReadOnlyList<T>
|
||||
googlSec8kReports = self.GOOGL.Data.GetAll(SECReport8K)
|
||||
googlSec10kReports = self.GOOGL.Data.GetAll(SECReport10K)
|
||||
self.Log("{}: 8K: {}".format(self.Time, len(googlSec8kReports)))
|
||||
self.Log("{}: 10K: {}".format(self.Time, len(googlSec10kReports)))
|
||||
|
||||
if not self.Portfolio.Invested:
|
||||
self.Buy(self.GOOGL.Symbol, 10)
|
||||
@@ -65,14 +65,6 @@
|
||||
<Content Include="Alphas\ShareClassMeanReversionAlpha.py" />
|
||||
<Content Include="Alphas\TripleLeverageETFPairVolatilityDecayAlpha.py" />
|
||||
<Content Include="Alphas\VIXDualThrustAlpha.py" />
|
||||
<Content Include="AltData\CachedAlternativeDataAlgorithm.py" />
|
||||
<Content Include="AltData\BenzingaNewsAlgorithm.py" />
|
||||
<Content Include="AltData\QuiverWallStreetBetsDataAlgorithm.py" />
|
||||
<Content Include="AltData\SECReport8KAlgorithm.py" />
|
||||
<Content Include="AltData\SmartInsiderTransactionAlgorithm.py" />
|
||||
<Content Include="AltData\USTreasuryYieldCurveRateAlgorithm.py" />
|
||||
<Content Include="AltData\TradingEconomicsAlgorithm.py" />
|
||||
<Content Include="AltData\TiingoNewsAlgorithm.py" />
|
||||
<Content Include="BasicCSharpIntegrationTemplateAlgorithm.py" />
|
||||
<Content Include="BasicSetAccountCurrencyAlgorithm.py" />
|
||||
<None Include="..\LICENSE">
|
||||
@@ -80,27 +72,21 @@
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
<None Include="InceptionDateSelectionRegressionAlgorithm.py" />
|
||||
<None Include="USTreasuryYieldCurveDataAlgorithm.py" />
|
||||
<None Include="SmartInsiderDataAlgorithm.py" />
|
||||
<None Include="PandasDataFrameHistoryAlgorithm.py" />
|
||||
<None Include="CustomDataAddDataRegressionAlgorithm.py" />
|
||||
<None Include="CustomDataIconicTypesAddDataRegressionAlgorithm.py" />
|
||||
<None Include="TrainingExampleAlgorithm.py" />
|
||||
<None Include="LongOnlyAlphaStreamAlgorithm.py" />
|
||||
<None Include="CustomPartialFillModelAlgorithm.py" />
|
||||
<Content Include="BasicTemplateConstituentUniverseAlgorithm.py" />
|
||||
<Content Include="BasicTemplateOptionsConsolidationAlgorithm.py" />
|
||||
<None Include="BasicTemplateOptionsPriceModel.py" />
|
||||
<Content Include="Benchmarks\SECReportBenchmarkAlgorithm.py" />
|
||||
<Content Include="Benchmarks\SmartInsiderEventBenchmarkAlgorithm.py" />
|
||||
<Content Include="CoarseFineOptionUniverseChainRegressionAlgorithm.py" />
|
||||
<Content Include="CoarseTiingoNewsUniverseSelectionAlgorithm.py" />
|
||||
<Content Include="ConsolidateRegressionAlgorithm.py" />
|
||||
<Content Include="CustomConsolidatorRegressionAlgorithm.py" />
|
||||
<Content Include="CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm.py" />
|
||||
<Content Include="CustomDataAddDataCoarseSelectionRegressionAlgorithm.py" />
|
||||
<Content Include="CustomDataLinkedIconicTypeAddDataOnSecuritiesChangedRegressionAlgorithm.py" />
|
||||
<Content Include="CustomDataLinkedIconicTypeAddDataCoarseSelectionRegressionAlgorithm.py" />
|
||||
<None Include="CustomBuyingPowerModelAlgorithm.py" />
|
||||
<Content Include="CustomDataPropertiesRegressionAlgorithm.py" />
|
||||
<Content Include="DynamicSecurityDataAlgorithm.py" />
|
||||
<Content Include="ConfidenceWeightedFrameworkAlgorithm.py" />
|
||||
<Content Include="ExtendedMarketTradingRegressionAlgorithm.py" />
|
||||
<Content Include="FilterUniverseRegressionAlgorithm.py" />
|
||||
@@ -131,12 +117,9 @@
|
||||
<Content Include="SliceGetByTypeRegressionAlgorithm.py" />
|
||||
<Content Include="StringToSymbolImplicitConversionRegressionAlgorithm.py" />
|
||||
<Content Include="TalibIndicatorsAlgorithm.py" />
|
||||
<Content Include="TradingEconomicsCalendarIndicatorAlgorithm.py" />
|
||||
<Content Include="OnEndOfDayRegressionAlgorithm.py" />
|
||||
<Content Include="SECReportDataAlgorithm.py" />
|
||||
<None Include="TrainingInitializeRegressionAlgorithm.py" />
|
||||
<Content Include="UniverseUnchangedRegressionAlgorithm.py" />
|
||||
<Content Include="USEnergyInformationAdministrationAlgorithm.py" />
|
||||
<None Include="NLTKSentimentTradingAlgorithm.py" />
|
||||
<None Include="PytorchNeuralNetworkAlgorithm.py" />
|
||||
<None Include="RawPricesUniverseRegressionAlgorithm.py" />
|
||||
|
||||
@@ -47,9 +47,9 @@
|
||||
<Compile Include="ConstituentsUniverseRegressionAlgorithm.py" />
|
||||
<Compile Include="ConvertToFrameworkAlgorithm.py" />
|
||||
<Compile Include="CustomBuyingPowerModelAlgorithm.py" />
|
||||
<Compile Include="CustomDataAddDataCoarseSelectionRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataAddDataRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataLinkedIconicTypeAddDataCoarseSelectionRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataLinkedIconicTypeAddDataOnSecuritiesChangedRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataIconicTypesAddDataRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomDataIndicatorExtensionsAlgorithm.py" />
|
||||
<Compile Include="CustomDataUsingMapFileRegressionAlgorithm.py" />
|
||||
<Compile Include="CustomIndicatorAlgorithm.py" />
|
||||
@@ -88,7 +88,6 @@
|
||||
<Compile Include="DropboxBaseDataUniverseSelectionAlgorithm.py" />
|
||||
<Compile Include="DropboxCoarseFineAlgorithm.py" />
|
||||
<Compile Include="DropboxUniverseSelectionAlgorithm.py" />
|
||||
<Compile Include="DynamicSecurityDataAlgorithm.py" />
|
||||
<Compile Include="EmaCrossFuturesFrontMonthAlgorithm.py" />
|
||||
<Compile Include="EmaCrossUniverseSelectionAlgorithm.py" />
|
||||
<Compile Include="EmaCrossUniverseSelectionFrameworkAlgorithm.py" />
|
||||
@@ -149,18 +148,15 @@
|
||||
<Compile Include="ScheduledEventsAlgorithm.py" />
|
||||
<Compile Include="ScheduledUniverseSelectionModelRegressionAlgorithm.py" />
|
||||
<Compile Include="ScikitLearnLinearRegressionAlgorithm.py" />
|
||||
<Compile Include="SECReportDataAlgorithm.py" />
|
||||
<Compile Include="SectorExposureRiskFrameworkAlgorithm.py" />
|
||||
<Compile Include="SectorWeightingFrameworkAlgorithm.py" />
|
||||
<Compile Include="SetHoldingsMultipleTargetsRegressionAlgorithm.py" />
|
||||
<Compile Include="SmaCrossUniverseSelectionAlgorithm.py" />
|
||||
<Compile Include="SmartInsiderDataAlgorithm.py" />
|
||||
<Compile Include="StandardDeviationExecutionModelRegressionAlgorithm.py" />
|
||||
<Compile Include="TalibIndicatorsAlgorithm.py" />
|
||||
<Compile Include="TensorFlowNeuralNetworkAlgorithm.py" />
|
||||
<Compile Include="TiingoPriceAlgorithm.py" />
|
||||
<Compile Include="TimeInForceAlgorithm.py" />
|
||||
<Compile Include="TradingEconomicsCalendarIndicatorAlgorithm.py" />
|
||||
<Compile Include="TrailingStopRiskFrameworkAlgorithm.py" />
|
||||
<Compile Include="TrainingExampleAlgorithm.py" />
|
||||
<Compile Include="TrainingInitializeRegressionAlgorithm.py" />
|
||||
@@ -169,9 +165,7 @@
|
||||
<Compile Include="UniverseSelectionRegressionAlgorithm.py" />
|
||||
<Compile Include="UniverseUnchangedRegressionAlgorithm.py" />
|
||||
<Compile Include="UpdateOrderRegressionAlgorithm.py" />
|
||||
<Compile Include="USEnergyInformationAdministrationAlgorithm.py" />
|
||||
<Compile Include="UserDefinedUniverseAlgorithm.py" />
|
||||
<Compile Include="USTreasuryYieldCurveDataAlgorithm.py" />
|
||||
<Compile Include="VolumeWeightedAveragePriceExecutionModelRegressionAlgorithm.py" />
|
||||
<Compile Include="WarmupAlgorithm.py" />
|
||||
<Compile Include="WarmupHistoryAlgorithm.py" />
|
||||
@@ -186,4 +180,4 @@
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.SEC import *
|
||||
|
||||
### <summary>
|
||||
### Demonstration algorithm showing how to use and access SEC data
|
||||
### </summary>
|
||||
### <meta name="tag" content="fundamental" />
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="SEC" />
|
||||
class SECReportDataAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
self.SetStartDate(2019, 1, 1)
|
||||
self.SetEndDate(2019, 1, 31)
|
||||
self.SetCash(100000)
|
||||
|
||||
self.ticker = "AAPL"
|
||||
self.symbol = self.AddData(SECReport10Q, self.ticker, Resolution.Daily).Symbol
|
||||
self.AddData(SECReport8K, self.ticker, Resolution.Daily)
|
||||
|
||||
def OnData(self, slice):
|
||||
# OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
data = slice[self.ticker]
|
||||
report = data.Report
|
||||
|
||||
self.Log(f"Form Type {report.FormType}")
|
||||
self.Log(f"Filing Date: {str(report.FilingDate)}")
|
||||
|
||||
for filer in report.Filers:
|
||||
self.Log(f"Filing company name: {filer.CompanyData.ConformedName}")
|
||||
self.Log(f"Filing company CIK: {filer.CompanyData.Cik}")
|
||||
self.Log(f"Filing company EIN: {filer.CompanyData.IrsNumber}")
|
||||
|
||||
for formerCompany in filer.FormerCompanies:
|
||||
self.Log(f"Former company name of {filer.CompanyData.ConformedName}: {formerCompany.FormerConformedName}")
|
||||
self.Log(f"Date of company name change: {str(formerCompany.Changed)}")
|
||||
|
||||
|
||||
# SEC documents can come in multiple documents.
|
||||
# For multi-document reports, sometimes the document contents after the first document
|
||||
# are files that have a binary format, such as JPG and PDF files
|
||||
for document in report.Documents:
|
||||
self.Log(f"Filename: {document.Filename}")
|
||||
self.Log(f"Document description: {document.Description}")
|
||||
|
||||
# Print sample of contents contained within the document
|
||||
self.Log(document.Text[:100])
|
||||
self.Log("=================")
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
|
||||
### <summary>
|
||||
### Example algorithm demonstrating usage of SmartInsider data
|
||||
### </summary>
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="smart insider" />
|
||||
### <meta name="tag" content="form 4" />
|
||||
### <meta name="tag" content="insider trading" />
|
||||
class SmartInsiderDataAlgoritm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
|
||||
|
||||
self.SetStartDate(2019, 7, 25)
|
||||
self.SetEndDate(2019, 8, 2)
|
||||
self.SetCash(100000)
|
||||
|
||||
self.symbol = self.AddEquity("KO", Resolution.Daily).Symbol
|
||||
self.AddData(SmartInsiderTransaction, "KO")
|
||||
self.AddData(SmartInsiderIntention, "KO")
|
||||
|
||||
def OnData(self, data):
|
||||
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
|
||||
if not data.ContainsKey(self.symbol.Value):
|
||||
return
|
||||
|
||||
has_open_orders = len(self.Transactions.GetOpenOrders()) != 0
|
||||
ko_data = data[self.symbol.Value]
|
||||
|
||||
if isinstance(ko_data, SmartInsiderTransaction):
|
||||
if not self.Portfolio.Invested and not has_open_orders:
|
||||
if ko_data.BuybackPercentage > 0.0001 and ko_data.VolumePercentage > 0.001:
|
||||
self.Log(f"Buying {self.symbol.Value} due to stock transaction")
|
||||
self.SetHoldings(self.symbol, 0.50)
|
||||
|
||||
elif isinstance(ko_data, SmartInsiderIntention):
|
||||
if not self.Portfolio.Invested and not has_open_orders:
|
||||
if ko_data.Percentage > 0.0001:
|
||||
self.Log(f"Buying {self.symbol.Value} due to intention to purchase stock")
|
||||
self.SetHoldings(self.symbol, 0.50)
|
||||
|
||||
elif self.Portfolio.Invested and not has_open_orders:
|
||||
if ko_data.Percentage < 0.0:
|
||||
self.Log(f"Liquidating {self.symbol.Value}")
|
||||
self.Liquidate(self.symbol)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.TradingEconomics import *
|
||||
|
||||
### <summary>
|
||||
### This example algorithm shows how to import and use Trading Economics data.
|
||||
### </summary>
|
||||
### <meta name="tag" content="strategy example" />
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="tradingeconomics" />
|
||||
class TradingEconomicsCalendarIndicatorAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
|
||||
self.SetStartDate(2018, 1, 1)
|
||||
self.SetEndDate(2019, 1, 1)
|
||||
|
||||
self.calendar = self.AddData(TradingEconomicsCalendar, TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol
|
||||
self.indicator = self.AddData(TradingEconomicsIndicator, TradingEconomics.Indicator.UnitedStates.InterestRate).Symbol
|
||||
|
||||
|
||||
def OnData(self, slice):
|
||||
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
|
||||
if slice.ContainsKey(self.calendar):
|
||||
self.Log(f"{self.Time} - {slice[self.calendar]}")
|
||||
if slice.ContainsKey(self.indicator):
|
||||
self.Log(f"{self.Time} - {slice[self.indicator]}")
|
||||
@@ -1,66 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.USEnergy import USEnergyAPI
|
||||
from QuantConnect.Data.Custom.Tiingo import *
|
||||
|
||||
### <summary>
|
||||
### This example algorithm shows how to import and use Tiingo daily prices data.
|
||||
### </summary>
|
||||
### <meta name="tag" content="strategy example" />
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="tiingo" />
|
||||
class USEnergyInformationAdministrationAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
self.SetStartDate(2017, 1, 1)
|
||||
self.SetEndDate(2017, 12, 31)
|
||||
self.SetCash(100000)
|
||||
|
||||
# Set your Tiingo API Token here
|
||||
Tiingo.SetAuthCode("my-tiingo-api-token")
|
||||
# Set your US Energy Information Administration (EIA) API Token here
|
||||
USEnergyAPI.SetAuthCode("my-us-energy-information-api-token")
|
||||
|
||||
|
||||
self.tiingoTicker = "AAPL"
|
||||
self.energyTicker = "NUC_STATUS.OUT.US.D"
|
||||
self.tiingoSymbol = self.AddData(TiingoDailyData, self.tiingoTicker, Resolution.Daily).Symbol
|
||||
self.energySymbol = self.AddData(USEnergyAPI, self.energyTicker, Resolution.Hour).Symbol
|
||||
|
||||
|
||||
self.emaFast = self.EMA(self.tiingoSymbol, 5)
|
||||
self.emaSlow = self.EMA(self.tiingoSymbol, 10)
|
||||
|
||||
|
||||
def OnData(self, slice):
|
||||
# OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
|
||||
if (not slice.ContainsKey(self.tiingoTicker)) or (not slice.ContainsKey(self.energyTicker)): return
|
||||
|
||||
# Extract Tiingo data from the slice
|
||||
tiingoRow = slice[self.tiingoTicker]
|
||||
energyRow = slice[self.energyTicker]
|
||||
|
||||
self.Log(f"{self.Time} - {tiingoRow.Symbol.Value} - {tiingoRow.Close} {tiingoRow.Value} {tiingoRow.Price} - EmaFast:{self.emaFast} - EmaSlow:{self.emaSlow}")
|
||||
self.Log(f"{self.Time} - {energyRow.Symbol.Value} - {energyRow.Value}")
|
||||
|
||||
# Simple EMA cross
|
||||
if not self.Portfolio.Invested and self.emaFast > self.emaSlow:
|
||||
self.SetHoldings(self.tiingoSymbol, 1)
|
||||
|
||||
elif self.Portfolio.Invested and self.emaFast < self.emaSlow:
|
||||
self.Liquidate(self.tiingoSymbol)
|
||||
@@ -1,39 +0,0 @@
|
||||
# QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
# Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from AlgorithmImports import *
|
||||
from QuantConnect.Data.Custom.USTreasury import *
|
||||
|
||||
### <summary>
|
||||
### Demonstration algorithm showing how to use and access U.S. Treasury yield curve data
|
||||
### </summary>
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="yield curve" />
|
||||
class USTreasuryYieldCurveDataAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2017, 1, 1)
|
||||
self.SetEndDate(2019, 6, 30)
|
||||
self.SetCash(100000)
|
||||
|
||||
# Define the symbol and "type" of our generic data:
|
||||
self.symbol = self.AddData(USTreasuryYieldCurveRate, "USTYC", Resolution.Daily).Symbol
|
||||
|
||||
def OnData(self, slice):
|
||||
if not slice.ContainsKey(self.symbol):
|
||||
return
|
||||
|
||||
curve = slice[self.symbol]
|
||||
self.Log(f"{self.Time} - 1M: {curve.OneMonth}, 2M: {curve.TwoMonth}, 3M: {curve.ThreeMonth}, 6M: {curve.SixMonth}, 1Y: {curve.OneYear}, 2Y: {curve.TwoYear}, 3Y: {curve.ThreeYear}, 5Y: {curve.FiveYear}, 10Y: {curve.TenYear}, 20Y: {curve.TwentyYear}, 30Y: {curve.ThirtyYear}")
|
||||
|
||||
Reference in New Issue
Block a user