chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests capacity by trading SPY (beast) alongside a small cap stock ABUS (penny)
|
||||
/// </summary>
|
||||
public class BeastVsPenny : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 3, 31);
|
||||
SetCash(10000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
var penny = AddEquity("ABUS", Resolution.Hour).Symbol;
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
|
||||
{
|
||||
SetHoldings(_spy, 0.5m);
|
||||
SetHoldings(penny, 0.5m);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "70"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.51%"},
|
||||
{"Compounding Annual Return", "-89.548%"},
|
||||
{"Drawdown", "49.900%"},
|
||||
{"Expectancy", "-0.514"},
|
||||
{"Net Profit", "-42.920%"},
|
||||
{"Sharpe Ratio", "-0.797"},
|
||||
{"Probabilistic Sharpe Ratio", "9.019%"},
|
||||
{"Loss Rate", "57%"},
|
||||
{"Win Rate", "43%"},
|
||||
{"Profit-Loss Ratio", "0.13"},
|
||||
{"Alpha", "-0.24"},
|
||||
{"Beta", "1.101"},
|
||||
{"Annual Standard Deviation", "1.031"},
|
||||
{"Annual Variance", "1.063"},
|
||||
{"Information Ratio", "-0.351"},
|
||||
{"Tracking Error", "0.836"},
|
||||
{"Treynor Ratio", "-0.747"},
|
||||
{"Total Fees", "$81.45"},
|
||||
{"Estimated Strategy Capacity", "$21000.00"},
|
||||
{"Fitness Score", "0.01"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.284"},
|
||||
{"Return Over Maximum Drawdown", "-1.789"},
|
||||
{"Portfolio Turnover", "0.038"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "67c9083f604ed16fb68481e7c26878dc"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests an illiquid asset that has bursts of liquidity around 11:00 A.M. Central Time
|
||||
/// with an hourly in and out strategy.
|
||||
/// </summary>
|
||||
public class CheeseMilkHourlyRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
private Symbol _contract;
|
||||
private DateTime _lastTrade;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 2, 17);
|
||||
SetTimeZone(TimeZones.Chicago);
|
||||
SetCash(100000);
|
||||
SetWarmup(1000);
|
||||
|
||||
var dc = AddFuture("DC", Resolution.Minute, Market.CME);
|
||||
dc.SetFilter(0, 10000);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var contract = slice.FutureChains.Values.SelectMany(c => c.Contracts.Values)
|
||||
.OrderBy(c => c.Symbol.ID.Date)
|
||||
.FirstOrDefault()?
|
||||
.Symbol;
|
||||
|
||||
if (contract == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_contract != contract || (_fast == null && _slow == null))
|
||||
{
|
||||
_fast = EMA(contract, 600);
|
||||
_slow = EMA(contract, 1200);
|
||||
_contract = contract;
|
||||
}
|
||||
|
||||
if (!_fast.IsReady || !_slow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time - _lastTrade <= TimeSpan.FromHours(1) || Time.TimeOfDay <= new TimeSpan(10, 50, 0) || Time.TimeOfDay >= new TimeSpan(12, 30, 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
|
||||
{
|
||||
SetHoldings(contract, 0.5);
|
||||
_lastTrade = Time;
|
||||
}
|
||||
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(contract, -0.5);
|
||||
_lastTrade = Time;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "19"},
|
||||
{"Average Win", "39.16%"},
|
||||
{"Average Loss", "-8.81%"},
|
||||
{"Compounding Annual Return", "-99.857%"},
|
||||
{"Drawdown", "82.900%"},
|
||||
{"Expectancy", "-0.359"},
|
||||
{"Net Profit", "-57.725%"},
|
||||
{"Sharpe Ratio", "-0.555"},
|
||||
{"Probabilistic Sharpe Ratio", "10.606%"},
|
||||
{"Loss Rate", "88%"},
|
||||
{"Win Rate", "12%"},
|
||||
{"Profit-Loss Ratio", "4.45"},
|
||||
{"Alpha", "-1.188"},
|
||||
{"Beta", "0.603"},
|
||||
{"Annual Standard Deviation", "1.754"},
|
||||
{"Annual Variance", "3.075"},
|
||||
{"Information Ratio", "-0.759"},
|
||||
{"Tracking Error", "1.753"},
|
||||
{"Treynor Ratio", "-1.612"},
|
||||
{"Total Fees", "$2558.55"},
|
||||
{"Estimated Strategy Capacity", "$20000.00"},
|
||||
{"Fitness Score", "0.351"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.602"},
|
||||
{"Return Over Maximum Drawdown", "-1.415"},
|
||||
{"Portfolio Turnover", "14.226"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4f5fd2fb25e957bd0cb7cb6d275ddb97"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests a wide variety of liquid and illiquid stocks together, with bins
|
||||
/// of 20 ranging from micro-cap to mega-cap stocks.
|
||||
/// </summary>
|
||||
public class EmaPortfolioRebalance100 : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<SymbolData> _data;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 2, 5);
|
||||
SetWarmup(1000);
|
||||
SetCash(100000);
|
||||
|
||||
_data = new List<SymbolData> {
|
||||
new SymbolData(this, AddEquity("AADR", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAMC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAU", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABDC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABIO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACER", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACES", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACGLO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACH", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACHV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIU", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACNB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACRS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACSI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACTG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZYNE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZYME", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZUO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZUMZ", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZTR", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZSL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZSAN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZROZ", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZLAB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIXI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIOP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZGNX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZEUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZAGG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YYY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YRD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YRCW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YPF", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAXN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACAD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACGL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACWV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACWX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADPT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZTS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YUM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLRE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLNX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLF", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XEL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XBI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("X", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WYNN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WORK", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WMB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WELL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WEC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAPL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADBE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AGG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AMD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AMZN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BABA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BAC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BMY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("C", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CMCSA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CRM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CSCO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("DIS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("EEM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("EFA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("FB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("GDX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("GE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("SPY", Resolution.Minute).Symbol)
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var fastFactor = 0.005m;
|
||||
|
||||
foreach (var sd in _data)
|
||||
{
|
||||
if (!Portfolio.Invested && sd.Fast * (1 + fastFactor) > sd.Slow)
|
||||
{
|
||||
SetHoldings(sd.Symbol, 0.01);
|
||||
}
|
||||
else if (Portfolio.Invested && sd.Fast * (1 - fastFactor) < sd.Slow)
|
||||
{
|
||||
Liquidate(sd.Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SymbolData
|
||||
{
|
||||
public Symbol Symbol { get; set; }
|
||||
public ExponentialMovingAverage Fast { get; set; }
|
||||
public ExponentialMovingAverage Slow { get; set; }
|
||||
public bool IsCrossed => Fast > Slow;
|
||||
|
||||
public SymbolData(QCAlgorithm algorithm, Symbol symbol) {
|
||||
Symbol = symbol;
|
||||
Fast = algorithm.EMA(symbol, 20);
|
||||
Slow = algorithm.EMA(symbol, 300);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "1015"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-12.674%"},
|
||||
{"Drawdown", "1.400%"},
|
||||
{"Expectancy", "-0.761"},
|
||||
{"Net Profit", "-1.328%"},
|
||||
{"Sharpe Ratio", "-12.258"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "95%"},
|
||||
{"Win Rate", "5%"},
|
||||
{"Profit-Loss Ratio", "3.67"},
|
||||
{"Alpha", "-0.142"},
|
||||
{"Beta", "0.038"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-4.389"},
|
||||
{"Tracking Error", "0.123"},
|
||||
{"Treynor Ratio", "-3.359"},
|
||||
{"Total Fees", "$1125.52"},
|
||||
{"Estimated Strategy Capacity", "$300.00"},
|
||||
{"Fitness Score", "0.007"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-14.315"},
|
||||
{"Return Over Maximum Drawdown", "-9.589"},
|
||||
{"Portfolio Turnover", "0.406"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4c165e8d648d54a85bb7b564050a6f85"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps SPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests equity strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalping : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Minute).Symbol;
|
||||
_fast = EMA(_spy, 20);
|
||||
_slow = EMA(_spy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio[_spy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_spy, 1);
|
||||
}
|
||||
else if (Portfolio[_spy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_spy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "150"},
|
||||
{"Average Win", "0.16%"},
|
||||
{"Average Loss", "-0.11%"},
|
||||
{"Compounding Annual Return", "-19.320%"},
|
||||
{"Drawdown", "3.900%"},
|
||||
{"Expectancy", "-0.193"},
|
||||
{"Net Profit", "-1.730%"},
|
||||
{"Sharpe Ratio", "-1.606"},
|
||||
{"Probabilistic Sharpe Ratio", "21.397%"},
|
||||
{"Loss Rate", "67%"},
|
||||
{"Win Rate", "33%"},
|
||||
{"Profit-Loss Ratio", "1.45"},
|
||||
{"Alpha", "-0.357"},
|
||||
{"Beta", "0.635"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "-4.249"},
|
||||
{"Tracking Error", "0.106"},
|
||||
{"Treynor Ratio", "-0.302"},
|
||||
{"Total Fees", "$449.14"},
|
||||
{"Estimated Strategy Capacity", "$27000000.00"},
|
||||
{"Fitness Score", "0.088"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-3.259"},
|
||||
{"Return Over Maximum Drawdown", "-7.992"},
|
||||
{"Portfolio Turnover", "14.605"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f5a0e9547f7455004fa6c3eb136534e9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps BTCETH using an EMA cross strategy at minute resolution.
|
||||
/// This tests crypto strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This also tests
|
||||
/// that currency conversions are handled properly in the strategy capacity
|
||||
/// calculation class.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingBTCETH : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _ethbtc;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
var ethbtc = AddCrypto("ETHBTC", Resolution.Minute, Market.GDAX);
|
||||
ethbtc.BuyingPowerModel = new BuyingPowerModel();
|
||||
_ethbtc = ethbtc.Symbol;
|
||||
|
||||
_fast = EMA(_ethbtc, 20);
|
||||
_slow = EMA(_ethbtc, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio[_ethbtc].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_ethbtc, 1);
|
||||
}
|
||||
else if (Portfolio[_ethbtc].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_ethbtc, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "1005"},
|
||||
{"Average Win", "0.96%"},
|
||||
{"Average Loss", "-0.33%"},
|
||||
{"Compounding Annual Return", "76.267%"},
|
||||
{"Drawdown", "77.100%"},
|
||||
{"Expectancy", "-0.012"},
|
||||
{"Net Profit", "4.768%"},
|
||||
{"Sharpe Ratio", "1.01909630017278E+24"},
|
||||
{"Probabilistic Sharpe Ratio", "93.814%"},
|
||||
{"Loss Rate", "75%"},
|
||||
{"Win Rate", "25%"},
|
||||
{"Profit-Loss Ratio", "2.95"},
|
||||
{"Alpha", "1.3466330963256E+25"},
|
||||
{"Beta", "25.59"},
|
||||
{"Annual Standard Deviation", "13.214"},
|
||||
{"Annual Variance", "174.61"},
|
||||
{"Information Ratio", "1.02164274756513E+24"},
|
||||
{"Tracking Error", "13.181"},
|
||||
{"Treynor Ratio", "5.2622435344112E+23"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$1300000.00"},
|
||||
{"Fitness Score", "0.38"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.239"},
|
||||
{"Return Over Maximum Drawdown", "-1.385"},
|
||||
{"Portfolio Turnover", "81.433"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6a779e7a8d12b4808845c75b88d43b3a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps EURUSD using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingEURUSD : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _eurusd;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_eurusd = AddForex("EURUSD", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_eurusd, 20);
|
||||
_slow = EMA(_eurusd, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio[_eurusd].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_eurusd, 1);
|
||||
}
|
||||
else if (Portfolio[_eurusd].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_eurusd, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "671"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.04%"},
|
||||
{"Compounding Annual Return", "-80.820%"},
|
||||
{"Drawdown", "12.200%"},
|
||||
{"Expectancy", "-0.447"},
|
||||
{"Net Profit", "-12.180%"},
|
||||
{"Sharpe Ratio", "-13.121"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "79%"},
|
||||
{"Win Rate", "21%"},
|
||||
{"Profit-Loss Ratio", "1.61"},
|
||||
{"Alpha", "-0.746"},
|
||||
{"Beta", "-0.02"},
|
||||
{"Annual Standard Deviation", "0.057"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-4.046"},
|
||||
{"Tracking Error", "0.161"},
|
||||
{"Treynor Ratio", "37.346"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$44000000.00"},
|
||||
{"Fitness Score", "0.025"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-16.609"},
|
||||
{"Return Over Maximum Drawdown", "-7.115"},
|
||||
{"Portfolio Turnover", "52.476"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "74ee44736b9300c0262dc75c0cd140e1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps ES futures contracts (E-mini SP500) using an EMA cross strategy at minute resolution.
|
||||
/// This tests futures strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The insanely high capacity estimate of this strategy is realistic.
|
||||
/// ES notional contract value traded is around $600 Billion USD per day (!!!), which
|
||||
/// is what the capacity is set to.
|
||||
/// </remarks>
|
||||
public class IntradayMinuteScalpingFuturesES : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
private Symbol _contract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
SetWarmup(1000);
|
||||
|
||||
var a = AddFuture("ES", Resolution.Minute, Market.CME);
|
||||
a.SetFilter(0, 10000);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var contract = slice.FutureChains.Values.SelectMany(c => c.Contracts.Values)
|
||||
.OrderBy(c => c.Symbol.ID.Date)
|
||||
.FirstOrDefault()?
|
||||
.Symbol;
|
||||
|
||||
if (contract == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_contract != contract || (_fast == null && _slow == null))
|
||||
{
|
||||
_fast = EMA(contract, 10);
|
||||
_slow = EMA(contract, 20);
|
||||
_contract = contract;
|
||||
}
|
||||
|
||||
if (!_fast.IsReady || !_slow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
|
||||
{
|
||||
SetHoldings(contract, 1);
|
||||
}
|
||||
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(contract, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "1217"},
|
||||
{"Average Win", "2.69%"},
|
||||
{"Average Loss", "-0.93%"},
|
||||
{"Compounding Annual Return", "-99.756%"},
|
||||
{"Drawdown", "77.200%"},
|
||||
{"Expectancy", "-0.047"},
|
||||
{"Net Profit", "-40.013%"},
|
||||
{"Sharpe Ratio", "-0.52"},
|
||||
{"Probabilistic Sharpe Ratio", "19.865%"},
|
||||
{"Loss Rate", "75%"},
|
||||
{"Win Rate", "25%"},
|
||||
{"Profit-Loss Ratio", "2.88"},
|
||||
{"Alpha", "-1.279"},
|
||||
{"Beta", "-3.686"},
|
||||
{"Annual Standard Deviation", "1.85"},
|
||||
{"Annual Variance", "3.422"},
|
||||
{"Information Ratio", "-0.463"},
|
||||
{"Tracking Error", "1.895"},
|
||||
{"Treynor Ratio", "0.261"},
|
||||
{"Total Fees", "$19843.10"},
|
||||
{"Estimated Strategy Capacity", "$560000000.00"},
|
||||
{"Fitness Score", "0.334"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.837"},
|
||||
{"Return Over Maximum Drawdown", "-1.402"},
|
||||
{"Portfolio Turnover", "1174.125"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f353843132df7b0604eff3a37b134ca2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps GBPJPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This test also
|
||||
/// tests that currency conversion rates are applied and calculated correctly.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingGBPJPY : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _gbpjpy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_gbpjpy = AddForex("GBPJPY", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_gbpjpy, 20);
|
||||
_slow = EMA(_gbpjpy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio[_gbpjpy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_gbpjpy, 1);
|
||||
}
|
||||
else if (Portfolio[_gbpjpy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_gbpjpy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "735"},
|
||||
{"Average Win", "0.08%"},
|
||||
{"Average Loss", "-0.05%"},
|
||||
{"Compounding Annual Return", "-93.946%"},
|
||||
{"Drawdown", "19.900%"},
|
||||
{"Expectancy", "-0.592"},
|
||||
{"Net Profit", "-19.794%"},
|
||||
{"Sharpe Ratio", "-10.054"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "84%"},
|
||||
{"Win Rate", "16%"},
|
||||
{"Profit-Loss Ratio", "1.56"},
|
||||
{"Alpha", "-0.895"},
|
||||
{"Beta", "0.068"},
|
||||
{"Annual Standard Deviation", "0.09"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "-4.929"},
|
||||
{"Tracking Error", "0.164"},
|
||||
{"Treynor Ratio", "-13.276"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$49000000.00"},
|
||||
{"Fitness Score", "0.049"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-10.846"},
|
||||
{"Return Over Maximum Drawdown", "-4.904"},
|
||||
{"Portfolio Turnover", "58.921"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "66f04c9622ab242993c8ce951418e6d9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps TRYJPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This tests that
|
||||
/// currency conversions are applied properly to the capacity estimate calculation.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingTRYJPY : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _tryjpy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_tryjpy = AddForex("TRYJPY", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_tryjpy, 20);
|
||||
_slow = EMA(_tryjpy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio[_tryjpy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_tryjpy, 1);
|
||||
}
|
||||
else if (Portfolio[_tryjpy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_tryjpy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "603"},
|
||||
{"Average Win", "0.20%"},
|
||||
{"Average Loss", "-0.26%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "73.200%"},
|
||||
{"Expectancy", "-0.849"},
|
||||
{"Net Profit", "-73.118%"},
|
||||
{"Sharpe Ratio", "-2.046"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "91%"},
|
||||
{"Win Rate", "9%"},
|
||||
{"Profit-Loss Ratio", "0.75"},
|
||||
{"Alpha", "-0.95"},
|
||||
{"Beta", "0.541"},
|
||||
{"Annual Standard Deviation", "0.489"},
|
||||
{"Annual Variance", "0.239"},
|
||||
{"Information Ratio", "-1.863"},
|
||||
{"Tracking Error", "0.487"},
|
||||
{"Treynor Ratio", "-1.849"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$4400000.00"},
|
||||
{"Fitness Score", "0.259"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.135"},
|
||||
{"Return Over Maximum Drawdown", "-1.389"},
|
||||
{"Portfolio Turnover", "49.501"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4eb4d703a9f200b6bb3d8b0ebbc9db7f"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances ultra-liquid stocks monthly, testing
|
||||
/// bursts of orders centered around the start of the month at Daily resolution
|
||||
/// </summary>
|
||||
public class MonthlyRebalanceDaily : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 12, 31);
|
||||
SetEndDate(2020, 4, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var spy = AddEquity("SPY", Resolution.Daily).Symbol;
|
||||
AddEquity("GE", Resolution.Daily);
|
||||
AddEquity("FB", Resolution.Daily);
|
||||
AddEquity("DIS", Resolution.Daily);
|
||||
AddEquity("CSCO", Resolution.Daily);
|
||||
AddEquity("CRM", Resolution.Daily);
|
||||
AddEquity("C", Resolution.Daily);
|
||||
AddEquity("BAC", Resolution.Daily);
|
||||
AddEquity("BABA", Resolution.Daily);
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
|
||||
{
|
||||
foreach (var symbol in Securities.Keys)
|
||||
{
|
||||
SetHoldings(symbol, 0.10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "35"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.07%"},
|
||||
{"Compounding Annual Return", "-68.407%"},
|
||||
{"Drawdown", "32.400%"},
|
||||
{"Expectancy", "-0.309"},
|
||||
{"Net Profit", "-25.901%"},
|
||||
{"Sharpe Ratio", "-1.503"},
|
||||
{"Probabilistic Sharpe Ratio", "2.878%"},
|
||||
{"Loss Rate", "64%"},
|
||||
{"Win Rate", "36%"},
|
||||
{"Profit-Loss Ratio", "0.90"},
|
||||
{"Alpha", "-0.7"},
|
||||
{"Beta", "-0.238"},
|
||||
{"Annual Standard Deviation", "0.386"},
|
||||
{"Annual Variance", "0.149"},
|
||||
{"Information Ratio", "-0.11"},
|
||||
{"Tracking Error", "0.712"},
|
||||
{"Treynor Ratio", "2.442"},
|
||||
{"Total Fees", "$38.99"},
|
||||
{"Estimated Strategy Capacity", "$19000000.00"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.021"},
|
||||
{"Return Over Maximum Drawdown", "-2.113"},
|
||||
{"Portfolio Turnover", "0.014"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "76d8164a3c0d4a7d45e94367c4ba5be1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances ultra-liquid stocks monthly, testing
|
||||
/// bursts of orders centered around the start of the month at Hourly resolution
|
||||
/// </summary>
|
||||
public class MonthlyRebalanceHourly : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 12, 31);
|
||||
SetEndDate(2020, 4, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
AddEquity("GE", Resolution.Hour);
|
||||
AddEquity("FB", Resolution.Hour);
|
||||
AddEquity("DIS", Resolution.Hour);
|
||||
AddEquity("CSCO", Resolution.Hour);
|
||||
AddEquity("CRM", Resolution.Hour);
|
||||
AddEquity("C", Resolution.Hour);
|
||||
AddEquity("BAC", Resolution.Hour);
|
||||
AddEquity("BABA", Resolution.Hour);
|
||||
AddEquity("AAPL", Resolution.Hour);
|
||||
|
||||
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
|
||||
{
|
||||
foreach (var symbol in Securities.Keys)
|
||||
{
|
||||
SetHoldings(symbol, 0.10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "35"},
|
||||
{"Average Win", "0.05%"},
|
||||
{"Average Loss", "-0.10%"},
|
||||
{"Compounding Annual Return", "-72.444%"},
|
||||
{"Drawdown", "36.500%"},
|
||||
{"Expectancy", "-0.449"},
|
||||
{"Net Profit", "-28.406%"},
|
||||
{"Sharpe Ratio", "-1.369"},
|
||||
{"Probabilistic Sharpe Ratio", "4.398%"},
|
||||
{"Loss Rate", "64%"},
|
||||
{"Win Rate", "36%"},
|
||||
{"Profit-Loss Ratio", "0.51"},
|
||||
{"Alpha", "-0.175"},
|
||||
{"Beta", "0.892"},
|
||||
{"Annual Standard Deviation", "0.503"},
|
||||
{"Annual Variance", "0.253"},
|
||||
{"Information Ratio", "-0.822"},
|
||||
{"Tracking Error", "0.138"},
|
||||
{"Treynor Ratio", "-0.772"},
|
||||
{"Total Fees", "$38.83"},
|
||||
{"Estimated Strategy Capacity", "$6000000.00"},
|
||||
{"Fitness Score", "0.004"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.033"},
|
||||
{"Return Over Maximum Drawdown", "-2.079"},
|
||||
{"Portfolio Turnover", "0.018"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1de9bcf6cda0945af6ba1f74c4dcb22c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that splits do not cause the algorithm to report capacity estimates
|
||||
/// above or below the actual capacity due to splits. The stock HTGM is illiquid,
|
||||
/// trading only $1.2 Million per day on average with sparse trade frequencies.
|
||||
/// </summary>
|
||||
public class SplitTestingStrategy : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _htgm;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 11, 1);
|
||||
SetEndDate(2020, 12, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var htgm = AddEquity("HTGM", Resolution.Hour);
|
||||
htgm.SetDataNormalizationMode(DataNormalizationMode.Raw);
|
||||
_htgm = htgm.Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_htgm, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetHoldings(_htgm, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "162"},
|
||||
{"Average Win", "0.10%"},
|
||||
{"Average Loss", "-0.35%"},
|
||||
{"Compounding Annual Return", "-94.432%"},
|
||||
{"Drawdown", "30.400%"},
|
||||
{"Expectancy", "-0.564"},
|
||||
{"Net Profit", "-23.412%"},
|
||||
{"Sharpe Ratio", "-1.041"},
|
||||
{"Probabilistic Sharpe Ratio", "12.971%"},
|
||||
{"Loss Rate", "66%"},
|
||||
{"Win Rate", "34%"},
|
||||
{"Profit-Loss Ratio", "0.29"},
|
||||
{"Alpha", "-4.827"},
|
||||
{"Beta", "1.43"},
|
||||
{"Annual Standard Deviation", "0.876"},
|
||||
{"Annual Variance", "0.767"},
|
||||
{"Information Ratio", "-4.288"},
|
||||
{"Tracking Error", "0.851"},
|
||||
{"Treynor Ratio", "-0.637"},
|
||||
{"Total Fees", "$2655.91"},
|
||||
{"Estimated Strategy Capacity", "$11000.00"},
|
||||
{"Fitness Score", "0.052"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.2"},
|
||||
{"Return Over Maximum Drawdown", "-3.481"},
|
||||
{"Portfolio Turnover", "0.307"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "54f571c11525656e9b383e235e77002e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances between SPY and BND. Tests capacity of the weakest link, which in this
|
||||
/// case is BND, dragging down the capacity estimate.
|
||||
/// </summary>
|
||||
public class SpyBondPortfolioRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 3, 31);
|
||||
SetCash(10000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
var bnd = AddEquity("BND", Resolution.Hour).Symbol;
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
|
||||
{
|
||||
SetHoldings(_spy, 0.5m);
|
||||
SetHoldings(bnd, 0.5m);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "21"},
|
||||
{"Average Win", "0.02%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "-33.564%"},
|
||||
{"Drawdown", "19.700%"},
|
||||
{"Expectancy", "-0.140"},
|
||||
{"Net Profit", "-9.655%"},
|
||||
{"Sharpe Ratio", "-0.99"},
|
||||
{"Probabilistic Sharpe Ratio", "13.754%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.72"},
|
||||
{"Alpha", "-0.022"},
|
||||
{"Beta", "0.538"},
|
||||
{"Annual Standard Deviation", "0.309"},
|
||||
{"Annual Variance", "0.096"},
|
||||
{"Information Ratio", "0.826"},
|
||||
{"Tracking Error", "0.269"},
|
||||
{"Treynor Ratio", "-0.569"},
|
||||
{"Total Fees", "$21.00"},
|
||||
{"Estimated Strategy Capacity", "$1100000.00"},
|
||||
{"Fitness Score", "0.005"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.524"},
|
||||
{"Return Over Maximum Drawdown", "-1.688"},
|
||||
{"Portfolio Turnover", "0.02"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "95a130426900aaf227a08a5d1c617b2b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user