chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:02:50 +08:00
commit 0fc60fdcb1
5008 changed files with 910633 additions and 0 deletions
@@ -0,0 +1,45 @@
/*
* 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.
*/
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <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
/// over a long period of time to establish a baseline.
/// </remarks>
public class BasicTemplateBenchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2000, 01, 01);
SetEndDate(2022, 01, 01);
SetBenchmark(dt => 1m);
AddEquity("SPY");
}
public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
SetHoldings("SPY", 1);
Debug("Purchased Stock");
}
}
}
}
@@ -0,0 +1,102 @@
/*
* 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.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Fundamental;
using QuantConnect.Data.Market;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class CoarseFineUniverseSelectionBenchmark : QCAlgorithm
{
private const int NumberOfSymbolsCoarse = 150;
private const int NumberOfSymbolsFine = 40;
private SecurityChanges _changes = SecurityChanges.None;
public override void Initialize()
{
UniverseSettings.Resolution = Resolution.Minute;
SetStartDate(2017, 11, 01);
SetEndDate(2018, 3, 01);
SetCash(50000);
AddUniverse(CoarseSelectionFunction, FineSelectionFunction);
}
// sort the data by daily dollar volume and take the top 'NumberOfSymbolsCoarse'
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// select only symbols with fundamental data and sort descending by daily dollar volume
var sortedByDollarVolume = coarse
.Where(x => x.HasFundamentalData)
.OrderByDescending(x => x.DollarVolume);
// take the top entries from our sorted collection
var top5 = sortedByDollarVolume.Take(NumberOfSymbolsCoarse);
// we need to return only the symbol objects
return top5.Select(x => x.Symbol);
}
// sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
{
// sort descending by P/E ratio
var sortedByPeRatio = fine.OrderByDescending(x => x.ValuationRatios.PERatio);
// take the top entries from our sorted collection
var topFine = sortedByPeRatio.Take(NumberOfSymbolsFine);
// we need to return only the symbol objects
return topFine.Select(x => x.Symbol);
}
//Data Event Handler: New data arrives here.
public override void OnData(Slice slice)
{
// if we have no changes, do nothing
if (_changes == SecurityChanges.None) return;
// liquidate removed securities
foreach (var security in _changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol);
}
}
// we want allocation in each security in our universe
foreach (var security in _changes.AddedSecurities)
{
SetHoldings(security.Symbol, 0.02m);
}
_changes = SecurityChanges.None;
}
// this event fires whenever we have changes to our universe
public override void OnSecuritiesChanged(SecurityChanges changes)
{
_changes = changes;
}
}
}
@@ -0,0 +1,87 @@
/*
* 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.
*/
using System;
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <summary>
/// Benchmark Algorithm: Loading and synchronization of 500 equity minute symbols and their options.
/// </summary>
public class EmptyEquityAndOptions400Benchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2022, 5, 11);
SetEndDate(2022, 5, 12);
var equity_symbols = new[] {
"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"
};
SetWarmUp(TimeSpan.FromDays(1));
foreach(var ticker in equity_symbols)
{
var option = AddOption(ticker);
option.SetFilter(1, 7, 0, 90);
}
AddEquity("SPY");
}
public override void OnData(Slice slice)
{
if (IsWarmingUp)
{
return;
}
Quit("The end!");
}
}
}
@@ -0,0 +1,405 @@
/*
* 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.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <summary>
/// Benchmark Algorithm: Loading and synchronization of 400 equity minute symbols.
/// </summary>
/// <remarks>
/// Testing the parsing; synchronizing and injection of data into LEAN event handlers. This directly adds the symbols to avoid universe
/// selection overhead. Later tests will include universe selection. The data sources are sparse.
/// </remarks>
public class EmptyMinute400EquityBenchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2015, 9, 1);
SetEndDate(2015, 12, 1);
foreach (var symbol in Symbols.Equity.All.Take(400))
{
AddSecurity(SecurityType.Equity, symbol);
}
}
public override void OnData(Slice slice)
{
}
}
public static class Symbols
{
public static class Equity
{
#region All
public static readonly HashSet<string> All = new HashSet<string>
{
"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"
};
#endregion
}
}
}
@@ -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.
*/
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <summary>
/// Benchmark Algorithm that adds SPX option chain but does not trade it.
/// This is an interesting benchmark because SPX option chains are large
/// </summary>
public class EmptySPXOptionChainBenchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2018, 1, 1);
SetEndDate(2020, 6, 1);
var index = AddIndex("SPX");
var option = AddOption(index);
option.SetFilter(x => x.IncludeWeeklys().Strikes(-30, 30).Expiration(0, 7));
}
}
}
@@ -0,0 +1,39 @@
/*
* 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.
*/
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <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>
public class EmptySingleSecuritySecondEquityBenchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2008, 01, 01);
SetEndDate(2008, 06, 01);
SetBenchmark(dt => 1m);
AddEquity("SPY", Resolution.Second);
}
public override void OnData(Slice slice)
{
}
}
}
@@ -0,0 +1,41 @@
/*
* 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.
*/
using System.Linq;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class HistoryRequestBenchmark : QCAlgorithm
{
private Symbol _symbol;
public override void Initialize()
{
SetStartDate(2010, 01, 01);
SetEndDate(2022, 01, 01);
SetCash(10000);
_symbol = AddEquity("SPY").Symbol;
}
public override void OnEndOfDay(Symbol symbol)
{
var minuteHistory = History(symbol, 60, Resolution.Minute);
var lastHourHigh = minuteHistory.Select(minuteBar => minuteBar.High).DefaultIfEmpty(0).Max();
var dailyHistory = History(symbol, 1, Resolution.Daily).First();
var dailyHigh = dailyHistory.High;
var dailyLow = dailyHistory.Low;
var dailyOpen = dailyHistory.Open;
}
}
}
@@ -0,0 +1,72 @@
/*
* 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.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
/// <summary>
/// Constructs a displaced moving average ribbon
/// </summary>
public class IndicatorRibbonBenchmark : QCAlgorithm
{
private Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
private IndicatorBase<IndicatorDataPoint>[] _ribbon;
public override void Initialize()
{
SetStartDate(2010, 01, 01);
SetEndDate(2022, 01, 01);
AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);
const int count = 50;
const int offset = 5;
const int period = 15;
// define our sma as the base of the ribbon
var sma = new SimpleMovingAverage(period);
_ribbon = Enumerable.Range(0, count).Select(x =>
{
// define our offset to the zero sma, these various offsets will create our 'displaced' ribbon
var delay = new Delay(offset * (x + 1));
// define an indicator that takes the output of the sma and pipes it into our delay indicator
var delayedSma = delay.Of(sma);
// register our new 'delayedSma' for automatic updates on a daily resolution
RegisterIndicator(_spy, delayedSma, Resolution.Daily, data => data.Value);
return delayedSma;
}).ToArray();
}
public override void OnData(Slice slice)
{
// wait for our entire ribbon to be ready
if (!_ribbon.All(x => x.IsReady)) return;
foreach (var indicator in _ribbon)
{
var value = indicator.Current.Value;
}
}
}
}
@@ -0,0 +1,40 @@
/*
/*
* 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.
*/
using System.Linq;
using QuantConnect.Data;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class ScheduledEventsBenchmark : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2011, 1, 1);
SetEndDate(2022, 1, 1);
SetCash(100000);
AddEquity("SPY");
foreach (int period in Enumerable.Range(0, 300))
{
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", period), Rebalance);
Schedule.On(DateRules.EveryDay("SPY"), TimeRules.BeforeMarketClose("SPY", period), Rebalance);
}
}
public override void OnData(Slice slice) { }
private void Rebalance() { }
}
}
@@ -0,0 +1,85 @@
/*
* 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.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class StatefulCoarseUniverseSelectionBenchmark : QCAlgorithm
{
private const int NumberOfSymbolsCoarse = 250;
private readonly List<Symbol> _blackList = new List<Symbol>();
public override void Initialize()
{
UniverseSettings.Resolution = Resolution.Daily;
SetStartDate(2017, 1, 01);
SetEndDate(2019, 1, 01);
SetCash(50000);
AddUniverse(CoarseSelectionFunction);
}
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// select only symbols with fundamental data and sort descending by daily dollar volume
var sortedByDollarVolume = coarse
.Where(x => x.HasFundamentalData)
.OrderByDescending(x => x.DollarVolume);
var top = sortedByDollarVolume
.Where(fundamental => !_blackList.Contains(fundamental.Symbol))
.Take(NumberOfSymbolsCoarse);
// we need to return only the symbol objects
return top.Select(x => x.Symbol);
}
public override void OnData(Slice slice)
{
if (slice.HasData)
{
var symbol = slice.Keys.FirstOrDefault();
if (symbol != null)
{
if (_blackList.Count > 50)
{
_blackList.RemoveAt(0);
}
_blackList.Add(symbol);
}
}
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var security in changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol);
}
}
foreach (var security in changes.AddedSecurities)
{
SetHoldings(security.Symbol, 0.001m);
}
}
}
}
@@ -0,0 +1,67 @@
/*
* 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.
*/
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Data.UniverseSelection;
namespace QuantConnect.Algorithm.CSharp.Benchmarks
{
public class StatelessCoarseUniverseSelectionBenchmark : QCAlgorithm
{
private const int NumberOfSymbolsCoarse = 250;
public override void Initialize()
{
UniverseSettings.Resolution = Resolution.Daily;
SetStartDate(2017, 1, 01);
SetEndDate(2019, 1, 01);
SetCash(50000);
AddUniverse(CoarseSelectionFunction);
}
// sort the data by daily dollar volume and take the top 250
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
{
// select only symbols with fundamental data and sort descending by daily dollar volume
var sortedByDollarVolume = coarse
.Where(x => x.HasFundamentalData)
.OrderByDescending(x => x.DollarVolume);
// take the top entries from our sorted collection
var top = sortedByDollarVolume.Take(NumberOfSymbolsCoarse);
// we need to return only the symbol objects
return top.Select(x => x.Symbol);
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
foreach (var security in changes.RemovedSecurities)
{
if (security.Invested)
{
Liquidate(security.Symbol);
}
}
foreach (var security in changes.AddedSecurities)
{
SetHoldings(security.Symbol, 0.001m);
}
}
}
}