chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
# 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>
|
||||
### Benchmark Algorithm: The minimalist basic template algorithm benchmark strategy.
|
||||
### </summary>
|
||||
### <remarks>
|
||||
### All new projects in the cloud are created with the basic template algorithm. It uses a minute algorithm
|
||||
### </remarks>
|
||||
class BasicTemplateBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2000, 1, 1)
|
||||
self.set_end_date(2022, 1, 1)
|
||||
self.set_benchmark(lambda x: 1)
|
||||
self.add_equity("SPY")
|
||||
|
||||
def on_data(self, data):
|
||||
if not self.portfolio.invested:
|
||||
self.set_holdings("SPY", 1)
|
||||
self.debug("Purchased Stock")
|
||||
@@ -0,0 +1,63 @@
|
||||
# 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 *
|
||||
|
||||
class CoarseFineUniverseSelectionBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
|
||||
self.set_start_date(2017, 11, 1)
|
||||
self.set_end_date(2018, 3, 1)
|
||||
self.set_cash(50000)
|
||||
|
||||
self.universe_settings.resolution = Resolution.MINUTE
|
||||
|
||||
self.add_universe(self.coarse_selection_function, self.fine_selection_function)
|
||||
|
||||
self.number_of_symbols = 150
|
||||
self.number_of_symbols_fine = 40
|
||||
self._changes = None
|
||||
|
||||
# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
def coarse_selection_function(self, coarse):
|
||||
|
||||
selected = [x for x in coarse if (x.has_fundamental_data)]
|
||||
# sort descending by daily dollar volume
|
||||
sorted_by_dollar_volume = sorted(selected, key=lambda x: x.dollar_volume, reverse=True)
|
||||
|
||||
# return the symbol objects of the top entries from our sorted collection
|
||||
return [ x.symbol for x in sorted_by_dollar_volume[:self.number_of_symbols] ]
|
||||
|
||||
# sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
|
||||
def fine_selection_function(self, fine):
|
||||
# sort descending by P/E ratio
|
||||
sorted_by_pe_ratio = sorted(fine, key=lambda x: x.valuation_ratios.pe_ratio, reverse=True)
|
||||
# take the top entries from our sorted collection
|
||||
return [ x.symbol for x in sorted_by_pe_ratio[:self.number_of_symbols_fine] ]
|
||||
|
||||
def on_data(self, data):
|
||||
# if we have no changes, do nothing
|
||||
if self._changes is None: return
|
||||
|
||||
# liquidate removed securities
|
||||
for security in self._changes.removed_securities:
|
||||
if security.invested:
|
||||
self.liquidate(security.symbol)
|
||||
|
||||
for security in self._changes.added_securities:
|
||||
self.set_holdings(security.symbol, 0.02)
|
||||
self._changes = None
|
||||
|
||||
def on_securities_changed(self, changes):
|
||||
self._changes = changes
|
||||
@@ -0,0 +1,70 @@
|
||||
# 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>
|
||||
### Benchmark Algorithm: Loading and synchronization of 500 equity minute symbols and their options.
|
||||
### </summary>
|
||||
class EmptyEquityAndOptions400Benchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2022, 5, 11)
|
||||
self.set_end_date(2022, 5, 12)
|
||||
self.equity_symbols = [
|
||||
|
||||
"MARK", "TSN", "DT", "RDW", "CVE", "NXPI", "FIVN", "CLX", "SPXL", "BKSY", "NUGT", "CF", "NEGG",
|
||||
"RH", "SIRI", "ITUB", "CSX", "AUR", "LIDR", "CMPS", "DHI", "GLW", "NTES", "CIFR", "S", "HSBC",
|
||||
"HIPO", "WTRH", "AMRN", "BIIB", "RIO", "EDIT", "TEAM", "CNK", "BUD", "MILE", "AEHR", "DOCN",
|
||||
"CLSK", "BROS", "MLCO", "SBLK", "ICLN", "OPK", "CNC", "SKX", "SESN", "VRM", "ASML", "BBAI",
|
||||
"HON", "MRIN", "BLMN", "NTNX", "POWW", "FOUR", "HOG", "GOGO", "MGNI", "GENI", "XPDI",
|
||||
"DG", "PSX", "RRC", "CORT", "MET", "UMC", "INMD", "RBAC", "ISRG", "BOX", "DVAX", "CRVS", "HLT",
|
||||
"BKNG", "BENE", "CLVS", "ESSC", "PTRA", "BE", "FPAC", "YETI", "DOCS", "DB", "EBON", "RDS.B",
|
||||
"ERIC", "BSIG", "INTU", "MNTS", "BCTX", "BLU", "FIS", "MAC", "WMB", "TTWO", "ARDX", "SWBI",
|
||||
"ELY", "INDA", "REAL", "ACI", "APRN", "BHP", "CPB", "SLQT", "ARKF", "TSP", "OKE", "NVTA", "META",
|
||||
"CSTM", "KMX", "IBB", "AGEN", "WOOF", "MJ", "HYZN", "RSI", "JCI", "EXC", "HPE", "SI", "WPM",
|
||||
"PRTY", "BBD", "FVRR", "CANO", "INDI", "MDLZ", "KOLD", "AMBA", "SOXS", "RSX", "ZEN", "PUBM",
|
||||
"VLDR", "CI", "ISEE", "GEO", "BKR", "DHR", "GRPN", "NRXP", "ACN", "MAT", "BODY", "ENDP",
|
||||
"SHPW", "AVIR", "GPN", "BILL", "BZ", "CERN", "ARVL", "DNMR", "NTR", "FSM", "BMBL", "PAAS",
|
||||
"INVZ", "ANF", "CL", "XP", "CS", "KD", "WW", "AHT", "GRTX", "XLC", "BLDP", "HTA", "APT", "BYSI",
|
||||
"ENB", "TRIT", "VTNR", "AVCT", "SLI", "CP", "CAH", "ALLY", "FIGS", "PXD", "TPX", "ZI", "BKLN", "SKIN",
|
||||
"LNG", "NU", "CX", "GSM", "NXE", "REI", "MNDT", "IP", "BLOK", "IAA", "TIP", "MCHP", "EVTL", "BIGC",
|
||||
"IGV", "LOTZ", "EWC", "DRI", "PSTG", "APLS", "KIND", "BBIO", "APPH", "FIVE", "LSPD", "SHAK",
|
||||
"COMM", "NAT", "VFC", "AMT", "VRTX", "RGS", "DD", "GBIL", "LICY", "ACHR", "FLR", "HGEN", "TECL",
|
||||
"SEAC", "NVS", "NTAP", "ML", "SBSW", "XRX", "UA", "NNOX", "SFT", "FE", "APP", "KEY", "CDEV",
|
||||
"DPZ", "BARK", "SPR", "CNQ", "XL", "AXSM", "ECH", "RNG", "AMLP", "ENG", "BTI", "REKR",
|
||||
"STZ", "BK", "HEAR", "LEV", "SKT", "HBI", "ALB", "CAG", "MNKD", "NMM", "BIRD", "CIEN", "SILJ",
|
||||
"STNG", "GUSH", "GIS", "PRPL", "SDOW", "GNRC", "ERX", "GES", "CPE", "FBRX", "WM", "ESTC",
|
||||
"GOED", "STLD", "LILM", "JNK", "BOIL", "ALZN", "IRBT", "KOPN", "AU", "TPR", "RWLK", "TROX",
|
||||
"TMO", "AVDL", "XSPA", "JKS", "PACB", "LOGI", "BLK", "REGN", "CFVI", "EGHT", "ATNF", "PRU",
|
||||
"URBN", "KMB", "SIX", "CME", "ENVX", "NVTS", "CELH", "CSIQ", "GSL", "PAA", "WU", "MOMO",
|
||||
"TOL", "WEN", "GTE", "EXAS", "GDRX", "PVH", "BFLY", "SRTY", "UDOW", "NCR", "ALTO", "CRTD",
|
||||
"GOCO", "ALK", "TTM", "DFS", "VFF", "ANTM", "FREY", "WY", "ACWI", "PNC", "SYY", "SNY", "CRK",
|
||||
"SO", "XXII", "PBF", "AER", "RKLY", "SOL", "CND", "MPLX", "JNPR", "FTCV", "CLR", "XHB", "YY",
|
||||
"POSH", "HIMS", "LIFE", "XENE", "ADM", "ROST", "MIR", "NRG", "AAP", "SSYS", "KBH", "KKR", "PLAN",
|
||||
"DUK", "WIMI", "DBRG", "WSM", "LTHM", "OVV", "CFLT", "EWT", "UNFI", "TX", "EMR", "IMGN", "K",
|
||||
"ONON", "UNIT", "LEVI", "ADTX", "UPWK", "DBA", "VOO", "FATH", "URI", "MPW", "JNUG", "RDFN",
|
||||
"OSCR", "WOLF", "SYF", "GOGL", "HES", "PHM", "CWEB", "ALDX", "BTWN", "AFL", "PPL", "CIM"
|
||||
|
||||
]
|
||||
|
||||
self.set_warm_up(TimeSpan.from_days(1))
|
||||
for ticker in self.equity_symbols:
|
||||
option = self.add_option(ticker)
|
||||
option.set_filter(1, 7, timedelta(0), timedelta(90))
|
||||
|
||||
self.add_equity("SPY")
|
||||
|
||||
def on_data(self, slice):
|
||||
if self.is_warming_up: return
|
||||
self.quit("The end!")
|
||||
@@ -0,0 +1,383 @@
|
||||
# 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 *
|
||||
|
||||
class EmptyMinute400EquityBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2015, 9, 1)
|
||||
self.set_end_date(2015, 12, 1)
|
||||
|
||||
for symbol in Symbols().equity.all()[:400]:
|
||||
self.add_security(SecurityType.EQUITY, symbol)
|
||||
|
||||
def on_data(self, data):
|
||||
pass
|
||||
|
||||
class Symbols(object):
|
||||
|
||||
def __init__(self):
|
||||
self.equity = self.Equity()
|
||||
|
||||
class Equity(object):
|
||||
def all(self):
|
||||
return [
|
||||
"SPY",
|
||||
"AAPL",
|
||||
"FB",
|
||||
"VXX",
|
||||
"VRX",
|
||||
"NFLX",
|
||||
"UVXY",
|
||||
"QQQ",
|
||||
"IWM",
|
||||
"BABA",
|
||||
"GILD",
|
||||
"XIV",
|
||||
"XOM",
|
||||
"CVX",
|
||||
"MSFT",
|
||||
"GE",
|
||||
"SLB",
|
||||
"JPM",
|
||||
"XLE",
|
||||
"DIS",
|
||||
"AMZN",
|
||||
"TWTR",
|
||||
"PFE",
|
||||
"C",
|
||||
"BAC",
|
||||
"ABBV",
|
||||
"JNJ",
|
||||
"HAL",
|
||||
"XLV",
|
||||
"INTC",
|
||||
"WFC",
|
||||
"V",
|
||||
"YHOO",
|
||||
"COP",
|
||||
"MYL",
|
||||
"AGN",
|
||||
"WMT",
|
||||
"KMI",
|
||||
"MRK",
|
||||
"TSLA",
|
||||
"GDX",
|
||||
"LLY",
|
||||
"FCX",
|
||||
"CAT",
|
||||
"CELG",
|
||||
"QCOM",
|
||||
"MCD",
|
||||
"CMCSA",
|
||||
"XOP",
|
||||
"CVS",
|
||||
"AMGN",
|
||||
"DOW",
|
||||
"AAL",
|
||||
"APC",
|
||||
"SUNE",
|
||||
"MU",
|
||||
"VLO",
|
||||
"SBUX",
|
||||
"WMB",
|
||||
"PG",
|
||||
"EOG",
|
||||
"DVN",
|
||||
"BMY",
|
||||
"APA",
|
||||
"UNH",
|
||||
"EEM",
|
||||
"IBM",
|
||||
"NKE",
|
||||
"T",
|
||||
"HD",
|
||||
"UNP",
|
||||
"DAL",
|
||||
"ENDP",
|
||||
"CSCO",
|
||||
"OXY",
|
||||
"MRO",
|
||||
"MDT",
|
||||
"TXN",
|
||||
"WLL",
|
||||
"ORCL",
|
||||
"GOOGL",
|
||||
"UAL",
|
||||
"WYNN",
|
||||
"MS",
|
||||
"HZNP",
|
||||
"BIIB",
|
||||
"VZ",
|
||||
"GM",
|
||||
"NBL",
|
||||
"TWX",
|
||||
"SWKS",
|
||||
"JD",
|
||||
"HCA",
|
||||
"AVGO",
|
||||
"YUM",
|
||||
"KO",
|
||||
"GOOG",
|
||||
"GS",
|
||||
"PEP",
|
||||
"AIG",
|
||||
"EMC",
|
||||
"BIDU",
|
||||
"CLR",
|
||||
"PYPL",
|
||||
"LVS",
|
||||
"SWN",
|
||||
"AXP",
|
||||
"ATVI",
|
||||
"RRC",
|
||||
"WBA",
|
||||
"MPC",
|
||||
"NXPI",
|
||||
"ETE",
|
||||
"NOV",
|
||||
"FOXA",
|
||||
"SNDK",
|
||||
"DIA",
|
||||
"UTX",
|
||||
"DD",
|
||||
"WDC",
|
||||
"AA",
|
||||
"M",
|
||||
"FXI",
|
||||
"RIG",
|
||||
"MA",
|
||||
"DUST",
|
||||
"TGT",
|
||||
"AET",
|
||||
"EBAY",
|
||||
"LUV",
|
||||
"EFA",
|
||||
"BRK.B",
|
||||
"BA",
|
||||
"MET",
|
||||
"LYB",
|
||||
"SVXY",
|
||||
"UWTI",
|
||||
"HON",
|
||||
"HPQ",
|
||||
"OAS",
|
||||
"ABT",
|
||||
"MO",
|
||||
"ESRX",
|
||||
"TEVA",
|
||||
"STX",
|
||||
"IBB",
|
||||
"F",
|
||||
"CBS",
|
||||
"TLT",
|
||||
"PM",
|
||||
"ESV",
|
||||
"NE",
|
||||
"PSX",
|
||||
"SCHW",
|
||||
"MON",
|
||||
"HES",
|
||||
"GPRO",
|
||||
"TVIX",
|
||||
"MNK",
|
||||
"NVDA",
|
||||
"NFX",
|
||||
"USO",
|
||||
"NUGT",
|
||||
"EWZ",
|
||||
"LOW",
|
||||
"UA",
|
||||
"TNA",
|
||||
"XLY",
|
||||
"MMM",
|
||||
"PXD",
|
||||
"VIAB",
|
||||
"MDLZ",
|
||||
"NEM",
|
||||
"USB",
|
||||
"MUR",
|
||||
"ETN",
|
||||
"FEYE",
|
||||
"PTEN",
|
||||
"OIH",
|
||||
"UPS",
|
||||
"CHK",
|
||||
"DHR",
|
||||
"RAI",
|
||||
"TQQQ",
|
||||
"CCL",
|
||||
"BRCM",
|
||||
"DG",
|
||||
"JBLU",
|
||||
"CRM",
|
||||
"ADBE",
|
||||
"COG",
|
||||
"PBR",
|
||||
"HP",
|
||||
"BHI",
|
||||
"BK",
|
||||
"TJX",
|
||||
"DE",
|
||||
"COF",
|
||||
"INCY",
|
||||
"DHI",
|
||||
"ABC",
|
||||
"XLI",
|
||||
"ZTS",
|
||||
"BP",
|
||||
"IYR",
|
||||
"PNC",
|
||||
"CNX",
|
||||
"XLF",
|
||||
"LRCX",
|
||||
"GG",
|
||||
"RDS.A",
|
||||
"WFM",
|
||||
"TSO",
|
||||
"ANTM",
|
||||
"KSS",
|
||||
"EA",
|
||||
"PRU",
|
||||
"RAD",
|
||||
"WFT",
|
||||
"XBI",
|
||||
"THC",
|
||||
"VWO",
|
||||
"CTSH",
|
||||
"ABX",
|
||||
"VMW",
|
||||
"CSX",
|
||||
"ACN",
|
||||
"EMR",
|
||||
"SE",
|
||||
"MJN",
|
||||
"SKX",
|
||||
"ACE",
|
||||
"P",
|
||||
"CMI",
|
||||
"CL",
|
||||
"CAH",
|
||||
"EXC",
|
||||
"DUK",
|
||||
"AMAT",
|
||||
"AEM",
|
||||
"FTI",
|
||||
"STT",
|
||||
"ILMN",
|
||||
"HOG",
|
||||
"KR",
|
||||
"EXPE",
|
||||
"VRTX",
|
||||
"IVV",
|
||||
"CAM",
|
||||
"GPS",
|
||||
"MCK",
|
||||
"ADSK",
|
||||
"CMCSK",
|
||||
"HTZ",
|
||||
"MGM",
|
||||
"DLTR",
|
||||
"STI",
|
||||
"CYH",
|
||||
"MOS",
|
||||
"CNQ",
|
||||
"GLW",
|
||||
"KEY",
|
||||
"KORS",
|
||||
"SIRI",
|
||||
"EPD",
|
||||
"SU",
|
||||
"DFS",
|
||||
"TMO",
|
||||
"TAP",
|
||||
"HST",
|
||||
"NBR",
|
||||
"EQT",
|
||||
"XLU",
|
||||
"BSX",
|
||||
"COST",
|
||||
"CTRP",
|
||||
"HFC",
|
||||
"VNQ",
|
||||
"TRV",
|
||||
"POT",
|
||||
"CERN",
|
||||
"LLTC",
|
||||
"DO",
|
||||
"ADI",
|
||||
"BAX",
|
||||
"AMT",
|
||||
"URI",
|
||||
"UCO",
|
||||
"ECA",
|
||||
"MAS",
|
||||
"ALL",
|
||||
"PCAR",
|
||||
"VIPS",
|
||||
"ATW",
|
||||
"SPXU",
|
||||
"LNKD",
|
||||
"X",
|
||||
"TSM",
|
||||
"SO",
|
||||
"BBT",
|
||||
"SYF",
|
||||
"VFC",
|
||||
"CXO",
|
||||
"IR",
|
||||
"PWR",
|
||||
"GLD",
|
||||
"LNG",
|
||||
"ETP",
|
||||
"JNPR",
|
||||
"MAT",
|
||||
"KLAC",
|
||||
"XLK",
|
||||
"TRIP",
|
||||
"AEP",
|
||||
"VTR",
|
||||
"ROST",
|
||||
"RDC",
|
||||
"CF",
|
||||
"FAS",
|
||||
"HCN",
|
||||
"AR",
|
||||
"SM",
|
||||
"WPX",
|
||||
"D",
|
||||
"HOT",
|
||||
"PRGO",
|
||||
"ALXN",
|
||||
"CNC",
|
||||
"VALE",
|
||||
"JCP",
|
||||
"GDXJ",
|
||||
"OKE",
|
||||
"ADM",
|
||||
"JOY",
|
||||
"TSN",
|
||||
"MAR",
|
||||
"KHC",
|
||||
"NSC",
|
||||
"CMA",
|
||||
"COH",
|
||||
"GMCR",
|
||||
"FL",
|
||||
"FITB",
|
||||
"BHP",
|
||||
"JWN",
|
||||
"DNR",
|
||||
"PBF",
|
||||
"XLNX"]
|
||||
@@ -0,0 +1,23 @@
|
||||
# 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 *
|
||||
|
||||
class EmptySPXOptionChainBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2018, 1, 1)
|
||||
self.set_end_date(2020, 6, 1)
|
||||
self._index = self.add_index("SPX")
|
||||
option = self.add_option(self._index)
|
||||
option.set_filter(lambda u: u.include_weeklys().strikes(-30, 30).expiration(0, 7))
|
||||
@@ -0,0 +1,31 @@
|
||||
# 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>
|
||||
### Benchmark Algorithm: Pure processing of 1 equity second resolution with the same benchmark.
|
||||
### </summary>
|
||||
### <remarks>
|
||||
### This should eliminate the synchronization part of LEAN and focus on measuring the performance of a single datafeed and event handling system.
|
||||
### </remarks>
|
||||
class EmptySingleSecuritySecondEquityBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2008, 1, 1)
|
||||
self.set_end_date(2008, 6, 1)
|
||||
self.set_benchmark(lambda x: 1)
|
||||
self.add_equity("SPY", Resolution.SECOND)
|
||||
|
||||
def on_data(self, data):
|
||||
pass
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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 *
|
||||
|
||||
class HistoryRequestBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.set_start_date(2010, 1, 1)
|
||||
self.set_end_date(2018, 1, 1)
|
||||
self.set_cash(10000)
|
||||
self._symbol = self.add_equity("SPY").symbol
|
||||
|
||||
def on_end_of_day(self, symbol):
|
||||
minute_history = self.history([self._symbol], 60, Resolution.MINUTE)
|
||||
last_hour_high = 0
|
||||
for index, row in minute_history.loc["SPY"].iterrows():
|
||||
if last_hour_high < row["high"]:
|
||||
last_hour_high = row["high"]
|
||||
|
||||
daily_history = self.history([self._symbol], 1, Resolution.DAILY).loc["SPY"].head()
|
||||
daily_history_high = daily_history["high"]
|
||||
daily_history_low = daily_history["low"]
|
||||
daily_history_open = daily_history["open"]
|
||||
@@ -0,0 +1,43 @@
|
||||
# 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 *
|
||||
|
||||
class IndicatorRibbonBenchmark(QCAlgorithm):
|
||||
|
||||
# Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
def initialize(self):
|
||||
self.set_start_date(2010, 1, 1) #Set Start Date
|
||||
self.set_end_date(2018, 1, 1) #Set End Date
|
||||
self._spy = self.add_equity("SPY", Resolution.MINUTE).symbol
|
||||
count = 50
|
||||
offset = 5
|
||||
period = 15
|
||||
self._ribbon = []
|
||||
# define our sma as the base of the ribbon
|
||||
self._sma = SimpleMovingAverage(period)
|
||||
|
||||
for x in range(count):
|
||||
# define our offset to the zero sma, these various offsets will create our 'displaced' ribbon
|
||||
delay = Delay(offset*(x+1))
|
||||
# define an indicator that takes the output of the sma and pipes it into our delay indicator
|
||||
delayed_sma = IndicatorExtensions.of(delay, self._sma)
|
||||
# register our new 'delayed_sma' for automatic updates on a daily resolution
|
||||
self.register_indicator(self._spy, delayed_sma, Resolution.DAILY)
|
||||
self._ribbon.append(delayed_sma)
|
||||
|
||||
def on_data(self, data):
|
||||
# wait for our entire ribbon to be ready
|
||||
if not all(x.is_ready for x in self._ribbon): return
|
||||
for x in self._ribbon:
|
||||
value = x.current.value
|
||||
@@ -0,0 +1,33 @@
|
||||
# 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 *
|
||||
|
||||
class ScheduledEventsBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
|
||||
self.set_start_date(2011, 1, 1)
|
||||
self.set_end_date(2022, 1, 1)
|
||||
self.set_cash(100000)
|
||||
self.add_equity("SPY")
|
||||
|
||||
for i in range(300):
|
||||
self.schedule.on(self.date_rules.every_day("SPY"), self.time_rules.after_market_open("SPY", i), self.rebalance)
|
||||
self.schedule.on(self.date_rules.every_day("SPY"), self.time_rules.before_market_close("SPY", i), self.rebalance)
|
||||
|
||||
def on_data(self, data):
|
||||
pass
|
||||
|
||||
def rebalance(self):
|
||||
pass
|
||||
@@ -0,0 +1,57 @@
|
||||
# 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 *
|
||||
|
||||
class StatefulCoarseUniverseSelectionBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
|
||||
self.set_start_date(2017, 1, 1)
|
||||
self.set_end_date(2019, 1, 1)
|
||||
self.set_cash(50000)
|
||||
|
||||
self.add_universe(self.coarse_selection_function)
|
||||
self.number_of_symbols = 250
|
||||
self._black_list = []
|
||||
|
||||
# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
def coarse_selection_function(self, coarse):
|
||||
|
||||
selected = [x for x in coarse if (x.has_fundamental_data)]
|
||||
# sort descending by daily dollar volume
|
||||
sorted_by_dollar_volume = sorted(selected, key=lambda x: x.dollar_volume, reverse=True)
|
||||
|
||||
# return the symbol objects of the top entries from our sorted collection
|
||||
return [ x.symbol for x in sorted_by_dollar_volume[:self.number_of_symbols] if not (x.symbol in self._black_list) ]
|
||||
|
||||
def on_data(self, slice):
|
||||
if slice.has_data:
|
||||
symbol = slice.keys()[0]
|
||||
if symbol:
|
||||
if len(self._black_list) > 50:
|
||||
self._black_list.pop(0)
|
||||
self._black_list.append(symbol)
|
||||
|
||||
def on_securities_changed(self, changes):
|
||||
# if we have no changes, do nothing
|
||||
if changes is None: return
|
||||
|
||||
# liquidate removed securities
|
||||
for security in changes.removed_securities:
|
||||
if security.invested:
|
||||
self.liquidate(security.symbol)
|
||||
|
||||
for security in changes.added_securities:
|
||||
self.set_holdings(security.symbol, 0.001)
|
||||
@@ -0,0 +1,48 @@
|
||||
# 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 *
|
||||
|
||||
class StatelessCoarseUniverseSelectionBenchmark(QCAlgorithm):
|
||||
|
||||
def initialize(self):
|
||||
self.universe_settings.resolution = Resolution.DAILY
|
||||
|
||||
self.set_start_date(2017, 1, 1)
|
||||
self.set_end_date(2019, 1, 1)
|
||||
self.set_cash(50000)
|
||||
|
||||
self.add_universe(self.coarse_selection_function)
|
||||
self.number_of_symbols = 250
|
||||
|
||||
# sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
def coarse_selection_function(self, coarse):
|
||||
|
||||
selected = [x for x in coarse if (x.has_fundamental_data)]
|
||||
# sort descending by daily dollar volume
|
||||
sorted_by_dollar_volume = sorted(selected, key=lambda x: x.dollar_volume, reverse=True)
|
||||
|
||||
# return the symbol objects of the top entries from our sorted collection
|
||||
return [ x.symbol for x in sorted_by_dollar_volume[:self.number_of_symbols] ]
|
||||
|
||||
def on_securities_changed(self, changes):
|
||||
# if we have no changes, do nothing
|
||||
if changes is None: return
|
||||
|
||||
# liquidate removed securities
|
||||
for security in changes.removed_securities:
|
||||
if security.invested:
|
||||
self.liquidate(security.symbol)
|
||||
|
||||
for security in changes.added_securities:
|
||||
self.set_holdings(security.symbol, 0.001)
|
||||
Reference in New Issue
Block a user