Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1afc18e5ed | ||
|
|
87874fdc6d | ||
|
|
d4b350bc99 | ||
|
|
4accdf9a9c | ||
|
|
8df9d48dfe | ||
|
|
910530213a | ||
|
|
9f0f455111 | ||
|
|
ab4526c144 | ||
|
|
b851242971 | ||
|
|
400a72afcd | ||
|
|
971707e03e | ||
|
|
1074226f1f | ||
|
|
9ffb942038 | ||
|
|
305c5ef35f | ||
|
|
6e93ce7134 | ||
|
|
0882a84111 | ||
|
|
13d321adff | ||
|
|
c5f27eb4cd | ||
|
|
4fa83d533e | ||
|
|
0ec84ba6a8 | ||
|
|
aa2e6d5fb6 | ||
|
|
82a2185f1b | ||
|
|
e0debbe789 | ||
|
|
171786439a | ||
|
|
abf532063a | ||
|
|
aee7bc1ad5 | ||
|
|
df57428bd7 | ||
|
|
9d734c4d8f | ||
|
|
765ce87df1 | ||
|
|
8a5766fa39 | ||
|
|
933e5ce6ca | ||
|
|
dc433493b7 | ||
|
|
9acf68ad19 | ||
|
|
5ebf451fb3 | ||
|
|
a4d49c05ca | ||
|
|
aaba566954 | ||
|
|
bf28a1d313 | ||
|
|
85a4d3364b | ||
|
|
eccca2c029 | ||
|
|
b0314e1c7c | ||
|
|
3410832ccf | ||
|
|
d573a0f6c7 | ||
|
|
7a3d8667c5 | ||
|
|
c3543f844a | ||
|
|
1fdb36ee89 | ||
|
|
cd9e451ead | ||
|
|
b4f6b51ad1 | ||
|
|
a5e395d298 | ||
|
|
a40329c70c | ||
|
|
6546647e08 | ||
|
|
46829f0f01 | ||
|
|
e722e72aaa | ||
|
|
e92230a7fe | ||
|
|
7881aeb3a5 | ||
|
|
32fdb51ab5 | ||
|
|
190fe012f1 | ||
|
|
893ca2b41d | ||
|
|
c30bd32fb0 | ||
|
|
e720147e50 | ||
|
|
b77f0122b2 | ||
|
|
646adb9131 | ||
|
|
e2ae173d99 | ||
|
|
1cfc044034 | ||
|
|
9b7af08b3e | ||
|
|
1a02fbaae5 | ||
|
|
ed835faf35 | ||
|
|
5ea70e2a89 | ||
|
|
2603694263 | ||
|
|
4a3a7a44f5 | ||
|
|
76c930a035 | ||
|
|
12f70aab46 | ||
|
|
650ce2e2b5 | ||
|
|
ef4fea7592 | ||
|
|
3cf9cc7d41 | ||
|
|
a9b634b096 | ||
|
|
1793add749 | ||
|
|
41636c94c3 | ||
|
|
2624b8c6f5 | ||
|
|
d8a86f182f | ||
|
|
0da9d626dc | ||
|
|
9888081cc0 | ||
|
|
611326b140 | ||
|
|
907a9f086c | ||
|
|
0c4e577885 | ||
|
|
e823dfdfb7 | ||
|
|
4469d18eb6 | ||
|
|
808ba17bff | ||
|
|
00f68b951f | ||
|
|
c07b643273 | ||
|
|
95f199eae5 | ||
|
|
2cb239a330 | ||
|
|
cb326788b3 | ||
|
|
e2e2b5f102 | ||
|
|
f75e81bd7d | ||
|
|
522fe14951 | ||
|
|
9cf4075957 | ||
|
|
1ed390c5f7 | ||
|
|
f5224f8be9 | ||
|
|
8d11bbf0ba | ||
|
|
1dcdfe79b0 | ||
|
|
e453635458 | ||
|
|
d84ad9ebfc | ||
|
|
f9adc6b136 | ||
|
|
e5f62fa4dd | ||
|
|
3430b46e6a | ||
|
|
00ac4f33af | ||
|
|
0d752abae6 | ||
|
|
2a77a8d3c0 | ||
|
|
49d6cb0021 | ||
|
|
9a81414a94 | ||
|
|
3f85c9ab82 | ||
|
|
f062b54450 | ||
|
|
64b95b2e8e | ||
|
|
7bcaaf8f23 | ||
|
|
8383163aae | ||
|
|
04f3c850ba | ||
|
|
5bd0675423 | ||
|
|
6eb3822193 | ||
|
|
12b62f6ec9 | ||
|
|
8d2455b629 | ||
|
|
171f0f19d5 | ||
|
|
e5a50109b4 | ||
|
|
c8d13080a8 | ||
|
|
8d352b6318 | ||
|
|
00cd8947a8 | ||
|
|
c211d04798 | ||
|
|
55195867a9 | ||
|
|
c9a3ad35e1 | ||
|
|
0d45bf5101 | ||
|
|
66552b49bd | ||
|
|
0642f58bda | ||
|
|
c7e6c96933 | ||
|
|
5c10b2cb82 | ||
|
|
4dd2ad85a9 | ||
|
|
10defd4928 | ||
|
|
891aeb87d3 |
@@ -77,31 +77,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "199"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-12.392%"},
|
||||
{"Compounding Annual Return", "-12.611%"},
|
||||
{"Drawdown", "0.200%"},
|
||||
{"Expectancy", "-0.586"},
|
||||
{"Net Profit", "-0.169%"},
|
||||
{"Sharpe Ratio", "-9.597"},
|
||||
{"Probabilistic Sharpe Ratio", "13.309%"},
|
||||
{"Loss Rate", "79%"},
|
||||
{"Win Rate", "21%"},
|
||||
{"Profit-Loss Ratio", "0.95"},
|
||||
{"Expectancy", "-0.585"},
|
||||
{"Net Profit", "-0.172%"},
|
||||
{"Sharpe Ratio", "-10.169"},
|
||||
{"Probabilistic Sharpe Ratio", "12.075%"},
|
||||
{"Loss Rate", "78%"},
|
||||
{"Win Rate", "22%"},
|
||||
{"Profit-Loss Ratio", "0.87"},
|
||||
{"Alpha", "-0.149"},
|
||||
{"Beta", "0.036"},
|
||||
{"Beta", "0.035"},
|
||||
{"Annual Standard Deviation", "0.008"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-9.605"},
|
||||
{"Tracking Error", "0.214"},
|
||||
{"Treynor Ratio", "-2.136"},
|
||||
{"Information Ratio", "-9.603"},
|
||||
{"Tracking Error", "0.215"},
|
||||
{"Treynor Ratio", "-2.264"},
|
||||
{"Total Fees", "$199.00"},
|
||||
{"Estimated Strategy Capacity", "$25000000.00"},
|
||||
{"Estimated Strategy Capacity", "$26000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "-21.623"},
|
||||
{"Return Over Maximum Drawdown", "-77.986"},
|
||||
{"Portfolio Turnover", "1.154"},
|
||||
{"Sortino Ratio", "-22.493"},
|
||||
{"Return Over Maximum Drawdown", "-77.93"},
|
||||
{"Portfolio Turnover", "1.211"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
@@ -115,7 +115,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "7baad0d75f652da1b801ec2fc368e710"}
|
||||
{"OrderListHash", "3c4c4085810cc5ecdb927d3647b9bbf3"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing GH issue #5748 where in some cases an option underlying symbol was not being
|
||||
/// removed from all universes it was hold
|
||||
/// </summary>
|
||||
public class AddAndRemoveOptionContractRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contract;
|
||||
private bool _hasRemoved;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 06, 06);
|
||||
SetEndDate(2014, 06, 09);
|
||||
|
||||
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
|
||||
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
|
||||
|
||||
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
|
||||
_contract = OptionChainProvider.GetOptionContractList(aapl, Time)
|
||||
.OrderBy(symbol => symbol.ID.Symbol)
|
||||
.FirstOrDefault(optionContract => optionContract.ID.OptionRight == OptionRight.Call
|
||||
&& optionContract.ID.OptionStyle == OptionStyle.American);
|
||||
AddOptionContract(_contract);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (slice.HasData)
|
||||
{
|
||||
if (!_hasRemoved)
|
||||
{
|
||||
RemoveOptionContract(_contract);
|
||||
RemoveSecurity(_contract.Underlying);
|
||||
_hasRemoved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Expect a single call to OnData where we removed the option and underlying");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_hasRemoved)
|
||||
{
|
||||
throw new Exception("Expect a single call to OnData where we removed the option and underlying");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <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 Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"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", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "486118a60d78f74811fe8d927c2c6b43"}
|
||||
{"OrderListHash", "b006bb7864c0b2f1a6552fb2aa7f03b8"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,34 +83,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "10"},
|
||||
{"Total Trades", "11"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-13.928%"},
|
||||
{"Compounding Annual Return", "-14.217%"},
|
||||
{"Drawdown", "3.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.164%"},
|
||||
{"Sharpe Ratio", "-0.12"},
|
||||
{"Probabilistic Sharpe Ratio", "45.109%"},
|
||||
{"Net Profit", "-0.168%"},
|
||||
{"Sharpe Ratio", "-0.126"},
|
||||
{"Probabilistic Sharpe Ratio", "45.081%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-2.892"},
|
||||
{"Alpha", "-2.896"},
|
||||
{"Beta", "0.551"},
|
||||
{"Annual Standard Deviation", "0.385"},
|
||||
{"Annual Variance", "0.149"},
|
||||
{"Information Ratio", "-13.646"},
|
||||
{"Annual Variance", "0.148"},
|
||||
{"Information Ratio", "-13.66"},
|
||||
{"Tracking Error", "0.382"},
|
||||
{"Treynor Ratio", "-0.084"},
|
||||
{"Total Fees", "$22.21"},
|
||||
{"Treynor Ratio", "-0.088"},
|
||||
{"Total Fees", "$23.21"},
|
||||
{"Estimated Strategy Capacity", "$340000000.00"},
|
||||
{"Lowest Capacity Asset", "FB V6OIPNZEM8V9"},
|
||||
{"Fitness Score", "0.147"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-4.264"},
|
||||
{"Portfolio Turnover", "0.268"},
|
||||
{"Return Over Maximum Drawdown", "-4.352"},
|
||||
{"Portfolio Turnover", "0.269"},
|
||||
{"Total Insights Generated", "15"},
|
||||
{"Total Insights Closed", "12"},
|
||||
{"Total Insights Analysis Completed", "12"},
|
||||
@@ -124,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "28605a89cd5f0d59ebe14af370764291"}
|
||||
{"OrderListHash", "a7a0983c8413ff241e7d223438f3d508"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2014, 03, 24);
|
||||
SetEndDate(2014, 04, 07);
|
||||
SetCash(100000);
|
||||
@@ -90,34 +94,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "25"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Total Trades", "27"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-75.369%"},
|
||||
{"Compounding Annual Return", "-75.320%"},
|
||||
{"Drawdown", "5.800%"},
|
||||
{"Expectancy", "-0.748"},
|
||||
{"Net Profit", "-5.596%"},
|
||||
{"Sharpe Ratio", "-3.271"},
|
||||
{"Probabilistic Sharpe Ratio", "5.816%"},
|
||||
{"Loss Rate", "85%"},
|
||||
{"Win Rate", "15%"},
|
||||
{"Profit-Loss Ratio", "0.64"},
|
||||
{"Alpha", "-0.595"},
|
||||
{"Expectancy", "-0.731"},
|
||||
{"Net Profit", "-5.588%"},
|
||||
{"Sharpe Ratio", "-3.272"},
|
||||
{"Probabilistic Sharpe Ratio", "5.825%"},
|
||||
{"Loss Rate", "86%"},
|
||||
{"Win Rate", "14%"},
|
||||
{"Profit-Loss Ratio", "0.89"},
|
||||
{"Alpha", "-0.594"},
|
||||
{"Beta", "0.707"},
|
||||
{"Annual Standard Deviation", "0.204"},
|
||||
{"Annual Standard Deviation", "0.203"},
|
||||
{"Annual Variance", "0.041"},
|
||||
{"Information Ratio", "-2.928"},
|
||||
{"Information Ratio", "-2.929"},
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Treynor Ratio", "-0.942"},
|
||||
{"Total Fees", "$35.25"},
|
||||
{"Total Fees", "$37.25"},
|
||||
{"Estimated Strategy Capacity", "$520000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.004"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "-4.466"},
|
||||
{"Return Over Maximum Drawdown", "-13.048"},
|
||||
{"Portfolio Turnover", "0.083"},
|
||||
{"Sortino Ratio", "-4.469"},
|
||||
{"Return Over Maximum Drawdown", "-13.057"},
|
||||
{"Portfolio Turnover", "0.084"},
|
||||
{"Total Insights Generated", "33"},
|
||||
{"Total Insights Closed", "30"},
|
||||
{"Total Insights Analysis Completed", "30"},
|
||||
@@ -131,7 +135,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "93b8c04ef334327062d5a79e6dd73130"}
|
||||
{"OrderListHash", "f837879b96f5e565b60fd040299d2123"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
170
Algorithm.CSharp/AlphaStreamsBasicTemplateAlgorithm.cs
Normal file
170
Algorithm.CSharp/AlphaStreamsBasicTemplateAlgorithm.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Brokerages;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Data.Custom.AlphaStreams;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm consuming an alpha streams portfolio state and trading based on it
|
||||
/// </summary>
|
||||
public class AlphaStreamsBasicTemplateAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Dictionary<Symbol, HashSet<Symbol>> _symbolsPerAlpha = new Dictionary<Symbol, HashSet<Symbol>>();
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 04, 04);
|
||||
SetEndDate(2018, 04, 06);
|
||||
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.01m;
|
||||
SetPortfolioConstruction(new EqualWeightingAlphaStreamsPortfolioConstructionModel());
|
||||
|
||||
SetSecurityInitializer(new BrokerageModelSecurityInitializer(new DefaultBrokerageModel(),
|
||||
new FuncSecuritySeeder(GetLastKnownPrices)));
|
||||
|
||||
foreach (var alphaId in new [] { "623b06b231eb1cc1aa3643a46", "9fc8ef73792331b11dbd5429a" })
|
||||
{
|
||||
AddData<AlphaStreamsPortfolioState>(alphaId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var portfolioState in data.Get<AlphaStreamsPortfolioState>().Values)
|
||||
{
|
||||
var alphaId = portfolioState.Symbol;
|
||||
var currentSymbols = _symbolsPerAlpha[alphaId];
|
||||
|
||||
var newSymbols = new HashSet<Symbol>(currentSymbols.Count);
|
||||
foreach (var symbol in portfolioState.PositionGroups?.SelectMany(positionGroup => positionGroup.Positions).Select(state => state.Symbol) ?? Enumerable.Empty<Symbol>())
|
||||
{
|
||||
// only add it if it's not used by any alpha (already added check)
|
||||
if (newSymbols.Add(symbol) && !UsedBySomeAlpha(symbol))
|
||||
{
|
||||
AddSecurity(symbol, resolution: UniverseSettings.Resolution);
|
||||
}
|
||||
}
|
||||
_symbolsPerAlpha[alphaId] = newSymbols;
|
||||
|
||||
foreach (var symbol in currentSymbols.Where(symbol => !UsedBySomeAlpha(symbol)))
|
||||
{
|
||||
RemoveSecurity(symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Log($"OnOrderEvent: {orderEvent}");
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
changes.FilterCustomSecurities = false;
|
||||
foreach (var addedSecurity in changes.AddedSecurities)
|
||||
{
|
||||
if (addedSecurity.Symbol.IsCustomDataType<AlphaStreamsPortfolioState>())
|
||||
{
|
||||
_symbolsPerAlpha[addedSecurity.Symbol] = new HashSet<Symbol>();
|
||||
}
|
||||
}
|
||||
|
||||
Log($"OnSecuritiesChanged: {changes}");
|
||||
}
|
||||
|
||||
private bool UsedBySomeAlpha(Symbol asset)
|
||||
{
|
||||
return _symbolsPerAlpha.Any(pair => pair.Value.Contains(asset));
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.12%"},
|
||||
{"Compounding Annual Return", "-14.722%"},
|
||||
{"Drawdown", "0.200%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.116%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "2.474"},
|
||||
{"Tracking Error", "0.339"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$83000.00"},
|
||||
{"Lowest Capacity Asset", "BTCUSD XJ"},
|
||||
{"Fitness Score", "0.017"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-138.588"},
|
||||
{"Portfolio Turnover", "0.034"},
|
||||
{"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", "2b94bc50a74caebe06c075cdab1bc6da"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm with existing holdings consuming an alpha streams portfolio state and trading based on it
|
||||
/// </summary>
|
||||
public class AlphaStreamsDifferentAccountCurrencyBasicTemplateAlgorithm : AlphaStreamsWithHoldingsBasicTemplateAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetAccountCurrency("EUR");
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-78.502%"},
|
||||
{"Drawdown", "3.100%"},
|
||||
{"Expectancy", "7.797"},
|
||||
{"Net Profit", "-1.134%"},
|
||||
{"Sharpe Ratio", "-2.456"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "16.59"},
|
||||
{"Alpha", "0.008"},
|
||||
{"Beta", "1.012"},
|
||||
{"Annual Standard Deviation", "0.343"},
|
||||
{"Annual Variance", "0.117"},
|
||||
{"Information Ratio", "-0.57"},
|
||||
{"Tracking Error", "0.004"},
|
||||
{"Treynor Ratio", "-0.831"},
|
||||
{"Total Fees", "$2.89"},
|
||||
{"Estimated Strategy Capacity", "$8900000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.506"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.506"},
|
||||
{"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", "a9dd0a0ab6070455479d1b9caaa4e69c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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 System.Collections.Generic;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Data.Custom.AlphaStreams;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm consuming an alpha streams portfolio state and trading based on it
|
||||
/// </summary>
|
||||
public class AlphaStreamsUniverseSelectionTemplateAlgorithm : AlphaStreamsBasicTemplateAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 04, 04);
|
||||
SetEndDate(2018, 04, 06);
|
||||
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.01m;
|
||||
SetPortfolioConstruction(new EqualWeightingAlphaStreamsPortfolioConstructionModel());
|
||||
|
||||
SetUniverseSelection(new ScheduledUniverseSelectionModel(
|
||||
DateRules.EveryDay(),
|
||||
TimeRules.Midnight,
|
||||
SelectAlphas,
|
||||
new UniverseSettings(UniverseSettings)
|
||||
{
|
||||
SubscriptionDataTypes = new List<Tuple<Type, TickType>>
|
||||
{new(typeof(AlphaStreamsPortfolioState), TickType.Trade)},
|
||||
FillForward = false,
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
private IEnumerable<Symbol> SelectAlphas(DateTime dateTime)
|
||||
{
|
||||
Log($"SelectAlphas() {Time}");
|
||||
foreach (var alphaId in new[] {"623b06b231eb1cc1aa3643a46", "9fc8ef73792331b11dbd5429a"})
|
||||
{
|
||||
var alphaSymbol = new Symbol(SecurityIdentifier.GenerateBase(typeof(AlphaStreamsPortfolioState), alphaId, Market.USA),
|
||||
alphaId);
|
||||
|
||||
yield return alphaSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics
|
||||
{
|
||||
get
|
||||
{
|
||||
var result = base.ExpectedStatistics;
|
||||
result["Compounding Annual Return"] = "-13.200%";
|
||||
result["Information Ratio"] = "2.827";
|
||||
result["Tracking Error"] = "0.248";
|
||||
result["Fitness Score"] = "0.011";
|
||||
result["Return Over Maximum Drawdown"] = "-113.513";
|
||||
result["Portfolio Turnover"] = "0.023";
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.Orders;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data.Custom.AlphaStreams;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm with existing holdings consuming an alpha streams portfolio state and trading based on it
|
||||
/// </summary>
|
||||
public class AlphaStreamsWithHoldingsBasicTemplateAlgorithm : AlphaStreamsBasicTemplateAlgorithm
|
||||
{
|
||||
private decimal _expectedSpyQuantity;
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 04, 04);
|
||||
SetEndDate(2018, 04, 06);
|
||||
SetCash(100000);
|
||||
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.001m;
|
||||
SetPortfolioConstruction(new EqualWeightingAlphaStreamsPortfolioConstructionModel());
|
||||
|
||||
// AAPL should be liquidated since it's not hold by the alpha
|
||||
// This is handled by the PCM
|
||||
var aapl = AddEquity("AAPL", Resolution.Hour);
|
||||
aapl.Holdings.SetHoldings(40, 10);
|
||||
|
||||
// SPY will be bought following the alpha streams portfolio
|
||||
// This is handled by the PCM + Execution Model
|
||||
var spy = AddEquity("SPY", Resolution.Hour);
|
||||
spy.Holdings.SetHoldings(246, -10);
|
||||
|
||||
AddData<AlphaStreamsPortfolioState>("94d820a93fff127fa46c15231d");
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
if (_expectedSpyQuantity == 0 && orderEvent.Symbol == "SPY" && orderEvent.Status == OrderStatus.Filled)
|
||||
{
|
||||
var security = Securities["SPY"];
|
||||
var priceInAccountCurrency = Portfolio.CashBook.ConvertToAccountCurrency(security.AskPrice, security.QuoteCurrency.Symbol);
|
||||
_expectedSpyQuantity = (Portfolio.TotalPortfolioValue - Settings.FreePortfolioValue) / priceInAccountCurrency;
|
||||
_expectedSpyQuantity = _expectedSpyQuantity.DiscretelyRoundBy(1, MidpointRounding.ToZero);
|
||||
}
|
||||
|
||||
base.OnOrderEvent(orderEvent);
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (Securities["AAPL"].HoldStock)
|
||||
{
|
||||
throw new Exception("We should no longer hold AAPL since the alpha does not");
|
||||
}
|
||||
|
||||
// we allow some padding for small price differences
|
||||
if (Math.Abs(Securities["SPY"].Holdings.Quantity - _expectedSpyQuantity) > _expectedSpyQuantity * 0.03m)
|
||||
{
|
||||
throw new Exception($"Unexpected SPY holdings. Expected {_expectedSpyQuantity} was {Securities["SPY"].Holdings.Quantity}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-87.617%"},
|
||||
{"Drawdown", "3.100%"},
|
||||
{"Expectancy", "8.518"},
|
||||
{"Net Profit", "-1.515%"},
|
||||
{"Sharpe Ratio", "-2.45"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "18.04"},
|
||||
{"Alpha", "0.008"},
|
||||
{"Beta", "1.015"},
|
||||
{"Annual Standard Deviation", "0.344"},
|
||||
{"Annual Variance", "0.118"},
|
||||
{"Information Ratio", "-0.856"},
|
||||
{"Tracking Error", "0.005"},
|
||||
{"Treynor Ratio", "-0.83"},
|
||||
{"Total Fees", "$3.09"},
|
||||
{"Estimated Strategy Capacity", "$8900000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.511"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "6113.173"},
|
||||
{"Portfolio Turnover", "0.511"},
|
||||
{"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", "788eb2c74715a78476ba0db3b2654eb6"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Benzinga;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
/// <summary>
|
||||
/// Benzinga is a provider of news data. Their news is made in-house
|
||||
/// and covers stock related news such as corporate events.
|
||||
/// </summary>
|
||||
public class BenzingaNewsAlgorithm : QCAlgorithm
|
||||
{
|
||||
// Predefine a dictionary of words with scores to scan for in the description
|
||||
// of the Benzinga news article
|
||||
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
|
||||
{
|
||||
{"bad", -0.5}, {"good", 0.5},
|
||||
{"negative", -0.5}, {"great", 0.5},
|
||||
{"growth", 0.5}, {"fail", -0.5},
|
||||
{"failed", -0.5}, {"success", 0.5},
|
||||
{"nailed", 0.5}, {"beat", 0.5},
|
||||
{"missed", -0.5}
|
||||
};
|
||||
|
||||
// Trade only every 5 days
|
||||
private DateTime _lastTrade = DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 6, 5);
|
||||
SetEndDate(2018, 8, 4);
|
||||
SetCash(100000);
|
||||
|
||||
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
|
||||
var ibm = AddEquity("IBM", Resolution.Hour).Symbol;
|
||||
|
||||
AddData<BenzingaNews>(aapl);
|
||||
AddData<BenzingaNews>(ibm);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if ((Time - _lastTrade) < TimeSpan.FromDays(5))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get rid of our holdings after 5 days, and start fresh
|
||||
Liquidate();
|
||||
|
||||
// Get all Benzinga data and loop over it
|
||||
foreach (var article in data.Get<BenzingaNews>().Values)
|
||||
{
|
||||
// Select the same Symbol we're getting a data point for
|
||||
// from the articles list so that we can get the sentiment of the article.
|
||||
// We use the underlying Symbol because the Symbols included in the `Symbols` property
|
||||
// are equity Symbols.
|
||||
var selectedSymbol = article.Symbols.SingleOrDefault(s => s == article.Symbol.Underlying);
|
||||
if (selectedSymbol == null)
|
||||
{
|
||||
throw new Exception($"Could not find current Symbol {article.Symbol.Underlying} even though it should exist");
|
||||
}
|
||||
|
||||
// The intersection of the article contents and the pre-defined words are the words that are included in both collections
|
||||
var intersection = article.Contents.ToLowerInvariant().Split(' ').Intersect(_words.Keys);
|
||||
// Get the words, then get the aggregate sentiment
|
||||
var sentimentSum = intersection.Select(x => _words[x]).Sum();
|
||||
|
||||
if (sentimentSum >= 0.5)
|
||||
{
|
||||
Log($"Longing {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
|
||||
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
|
||||
|
||||
_lastTrade = Time;
|
||||
}
|
||||
if (sentimentSum <= -0.5)
|
||||
{
|
||||
Log($"Shorting {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
|
||||
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
|
||||
|
||||
_lastTrade = Time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(BenzingaNews), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Data.Custom.Fred;
|
||||
using QuantConnect.Data.Custom.USEnergy;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
public class CachedAlternativeDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _cboeVix;
|
||||
private Symbol _usEnergy;
|
||||
private Symbol _fredPeakToTrough;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2003, 1, 1);
|
||||
SetEndDate(2019, 10, 11);
|
||||
SetCash(100000);
|
||||
|
||||
// QuantConnect caches a small subset of alternative data for easy consumption for the community.
|
||||
// You can use this in your algorithm as demonstrated below:
|
||||
|
||||
_cboeVix = AddData<CBOE>("VIX", Resolution.Daily).Symbol;
|
||||
// United States EIA data: https://eia.gov/
|
||||
_usEnergy = AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries, Resolution.Daily).Symbol;
|
||||
// FRED data
|
||||
_fredPeakToTrough = AddData<Fred>(Fred.OECDRecessionIndicators.UnitedStatesFromPeakThroughTheTrough, Resolution.Daily).Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.ContainsKey(_cboeVix))
|
||||
{
|
||||
var vix = data.Get<CBOE>(_cboeVix);
|
||||
Log($"VIX: {vix}");
|
||||
}
|
||||
|
||||
if (data.ContainsKey(_usEnergy))
|
||||
{
|
||||
var inputIntoRefineries = data.Get<USEnergy>(_usEnergy);
|
||||
Log($"U.S. Input Into Refineries: {Time}, {inputIntoRefineries.Value}");
|
||||
}
|
||||
|
||||
if (data.ContainsKey(_fredPeakToTrough))
|
||||
{
|
||||
var peakToTrough = data.Get<Fred>(_fredPeakToTrough);
|
||||
Log($"OECD based Recession Indicator for the United States from the Peak through the Trough: {peakToTrough}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Quiver;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
/// <summary>
|
||||
/// Quiver Quantitative is a provider of alternative data.
|
||||
/// This algorithm shows how to consume the <see cref="QuiverWallStreetBets"/>
|
||||
/// </summary>
|
||||
public class QuiverWallStreetBetsDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 1, 1);
|
||||
SetEndDate(2020, 6, 1);
|
||||
SetCash(100000);
|
||||
|
||||
var aapl = AddEquity("AAPL", Resolution.Daily).Symbol;
|
||||
var quiverWSBSymbol = AddData<QuiverWallStreetBets>(aapl).Symbol;
|
||||
var history = History<QuiverWallStreetBets>(quiverWSBSymbol, 60, Resolution.Daily);
|
||||
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var points = data.Get<QuiverWallStreetBets>();
|
||||
foreach (var point in points.Values)
|
||||
{
|
||||
// Go long in the stock if it was mentioned more than 5 times in the WallStreetBets daily discussion
|
||||
if (point.Mentions > 5)
|
||||
{
|
||||
SetHoldings(point.Symbol.Underlying, 1);
|
||||
}
|
||||
// Go short in the stock if it was mentioned less than 5 times in the WallStreetBets daily discussion
|
||||
if (point.Mentions < 5)
|
||||
{
|
||||
SetHoldings(point.Symbol.Underlying, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class SECReport8KAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 1, 1);
|
||||
SetEndDate(2019, 8, 21);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
|
||||
|
||||
// Request underlying equity data.
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add SEC report 10-Q data for the underlying IBM asset
|
||||
var earningsFiling = AddData<SECReport10Q>(ibm, Resolution.Daily).Symbol;
|
||||
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
|
||||
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
// Add SEC data from the filtered coarse selection
|
||||
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
|
||||
.Select(x => x.Symbol)
|
||||
.Take(10);
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
AddData<SECReport8K>(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Store the symbols we want to long in a list
|
||||
// so that we can have an equal-weighted portfolio
|
||||
var longEquitySymbols = new List<Symbol>();
|
||||
|
||||
// Get all SEC data and loop over it
|
||||
foreach (var report in data.Get<SECReport8K>().Values)
|
||||
{
|
||||
// Get the length of all contents contained within the report
|
||||
var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
|
||||
|
||||
if (reportTextLength > 20000)
|
||||
{
|
||||
longEquitySymbols.Add(report.Symbol.Underlying);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var equitySymbol in longEquitySymbols)
|
||||
{
|
||||
SetHoldings(equitySymbol, 1m / longEquitySymbols.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SECReport8K), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SmartInsider;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class SmartInsiderTransactionAlgorithm : QCAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 3, 1);
|
||||
SetEndDate(2019, 7, 4);
|
||||
SetCash(1000000);
|
||||
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));
|
||||
|
||||
// Request underlying equity data.
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add Smart Insider stock buyback transaction data for the underlying IBM asset
|
||||
var si = AddData<SmartInsiderTransaction>(ibm).Symbol;
|
||||
// Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol.
|
||||
var history = History<SmartInsiderTransaction>(si, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseUniverse(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
|
||||
.Select(x => x.Symbol)
|
||||
.Take(10);
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
AddData<SmartInsiderTransaction>(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Get all SmartInsider data available
|
||||
var transactions = data.Get<SmartInsiderTransaction>();
|
||||
|
||||
foreach (var transaction in transactions.Values)
|
||||
{
|
||||
if (transaction.VolumePercentage == null || transaction.EventType == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Using the Smart Insider transaction information, buy when company does a stock buyback
|
||||
if (transaction.EventType == SmartInsiderEventType.Transaction && transaction.VolumePercentage > 5)
|
||||
{
|
||||
SetHoldings(transaction.Symbol.Underlying, (decimal)transaction.VolumePercentage / 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SmartInsiderTransaction), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Look for positive and negative words in the news article description
|
||||
/// and trade based on the sum of the sentiment
|
||||
/// </summary>
|
||||
public class TiingoNewsAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _tiingoSymbol;
|
||||
|
||||
// Predefine a dictionary of words with scores to scan for in the description
|
||||
// of the Tiingo news article
|
||||
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
|
||||
{
|
||||
{"bad", -0.5}, {"good", 0.5},
|
||||
{ "negative", -0.5}, {"great", 0.5},
|
||||
{"growth", 0.5}, {"fail", -0.5},
|
||||
{"failed", -0.5}, {"success", 0.5},
|
||||
{"nailed", 0.5}, {"beat", 0.5},
|
||||
{"missed", -0.5}
|
||||
};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 6, 10);
|
||||
SetEndDate(2019, 10, 3);
|
||||
SetCash(100000);
|
||||
|
||||
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
|
||||
_tiingoSymbol = AddData<TiingoNews>(aapl).Symbol;
|
||||
|
||||
// Request underlying equity data
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add news data for the underlying IBM asset
|
||||
var news = AddData<TiingoNews>(ibm).Symbol;
|
||||
// Request 60 days of history with the TiingoNews IBM Custom Data Symbol.
|
||||
var history = History<TiingoNews>(news, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
//Confirm that the data is in the collection
|
||||
if (!data.ContainsKey(_tiingoSymbol)) return;
|
||||
|
||||
// Gets the first piece of data from the Slice
|
||||
var article = data.Get<TiingoNews>(_tiingoSymbol);
|
||||
|
||||
// Article descriptions come in all caps. Lower and split by word
|
||||
var descriptionWords = article.Description.ToLowerInvariant().Split(' ');
|
||||
|
||||
// Take the intersection of predefined words and the words in the
|
||||
// description to get a list of matching words
|
||||
var intersection = _words.Keys.Intersect(descriptionWords);
|
||||
|
||||
// Get the sum of the article's sentiment, and go long or short
|
||||
// depending if it's a positive or negative description
|
||||
var sentiment = intersection.Select(x => _words[x]).Sum();
|
||||
|
||||
SetHoldings(article.Symbol.Underlying, sentiment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.TradingEconomics;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Trades on interest rate announcements from data provided by Trading Economics
|
||||
/// </summary>
|
||||
public class TradingEconomicsAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _interestRate;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 11, 1);
|
||||
SetEndDate(2019, 10, 3);
|
||||
SetCash(100000);
|
||||
|
||||
AddEquity("AGG", Resolution.Hour);
|
||||
AddEquity("SPY", Resolution.Hour);
|
||||
|
||||
_interestRate = AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol;
|
||||
|
||||
// Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
|
||||
// We should expect no historical data because 2013-11-01 is before the absolute first point of data
|
||||
var history = History<TradingEconomicsCalendar>(_interestRate, 365, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request (should be zero)
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Make sure we have an interest rate calendar event
|
||||
if (!data.ContainsKey(_interestRate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var announcement = data.Get<TradingEconomicsCalendar>(_interestRate);
|
||||
|
||||
// Confirm it's a FED Rate Decision
|
||||
if (announcement.Event != TradingEconomics.Event.UnitedStates.FedInterestRateDecision)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// In the event of a rate increase, rebalance 50% to Bonds.
|
||||
var interestRateDecreased = announcement.Actual <= announcement.Previous;
|
||||
|
||||
if (interestRateDecreased)
|
||||
{
|
||||
SetHoldings("SPY", 1);
|
||||
SetHoldings("AGG", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetHoldings("SPY", 0.5);
|
||||
SetHoldings("AGG", 0.5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class USTreasuryYieldCurveRateAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _yieldCurve;
|
||||
private Symbol _spy;
|
||||
private DateTime _lastInversion = DateTime.MinValue;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2000, 3, 1);
|
||||
SetEndDate(2019, 9, 15);
|
||||
SetCash(100000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
_yieldCurve = AddData<USTreasuryYieldCurveRate>("USTYCR", Resolution.Daily).Symbol;
|
||||
|
||||
// Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
|
||||
var history = History<USTreasuryYieldCurveRate>(_yieldCurve, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!data.ContainsKey(_yieldCurve))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Preserve null values by getting the data with `slice.Get<T>`
|
||||
// Accessing the data using `data[_yieldCurve]` results in null
|
||||
// values becoming `default(decimal)` which is equal to 0
|
||||
var rates = data.Get<USTreasuryYieldCurveRate>().Values.First();
|
||||
|
||||
// Check for null before using the values
|
||||
if (!rates.TenYear.HasValue || !rates.TwoYear.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Only advance if a year has gone by
|
||||
if (Time - _lastInversion < TimeSpan.FromDays(365))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if there is a yield curve inversion after not having one for a year, short SPY for two years
|
||||
if (!Portfolio.Invested && rates.TwoYear > rates.TenYear)
|
||||
{
|
||||
Debug($"{Time} - Yield curve inversion! Shorting the market for two years");
|
||||
SetHoldings(_spy, -0.5);
|
||||
|
||||
_lastInversion = Time;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If two years have passed, liquidate our position in SPY
|
||||
if (Time - _lastInversion >= TimeSpan.FromDays(365 * 2))
|
||||
{
|
||||
Liquidate(_spy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
Algorithm.CSharp/BasicTemplateAtreyuAlgorithm.cs
Normal file
130
Algorithm.CSharp/BasicTemplateAtreyuAlgorithm.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Brokerages;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template algorithm for the Atreyu brokerage
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="using quantconnect" />
|
||||
/// <meta name="tag" content="trading and orders" />
|
||||
public class BasicTemplateAtreyuAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
SetCash(100000);
|
||||
|
||||
SetBrokerageModel(BrokerageName.Atreyu);
|
||||
AddEquity("SPY", Resolution.Minute);
|
||||
|
||||
DefaultOrderProperties = new AtreyuOrderProperties
|
||||
{
|
||||
// Can specify the default exchange to execute an order on.
|
||||
// If not specified will default to the primary exchange
|
||||
Exchange = Exchange.NASDAQ,
|
||||
// Currently only support order for the day
|
||||
TimeInForce = TimeInForce.Day
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
// will set 25% of our buying power with a market order that will be routed to exchange set in the default order properties (NASDAQ)
|
||||
SetHoldings("SPY", 0.25m);
|
||||
// will increase our SPY holdings to 50% of our buying power with a market order that will be routed to ARCA
|
||||
SetHoldings("SPY", 0.50m, orderProperties: new AtreyuOrderProperties { Exchange = Exchange.ARCA });
|
||||
|
||||
Debug("Purchased SPY!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "93.443%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.847%"},
|
||||
{"Sharpe Ratio", "6.515"},
|
||||
{"Probabilistic Sharpe Ratio", "67.535%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0.11"},
|
||||
{"Annual Variance", "0.012"},
|
||||
{"Information Ratio", "6.515"},
|
||||
{"Tracking Error", "0.11"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.52"},
|
||||
{"Estimated Strategy Capacity", "$8600000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.124"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "78.376"},
|
||||
{"Portfolio Turnover", "0.124"},
|
||||
{"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", "cb542eaaeab5eac3bcae5d915ded30da"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template algorithm which showcases <see cref="ConstituentsUniverse"/> simple use case
|
||||
/// </summary>
|
||||
public class BasicTemplateConstituentUniverseAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
// by default will use algorithms UniverseSettings
|
||||
AddUniverse(Universe.Constituent.Steel());
|
||||
|
||||
// we specify the UniverseSettings it should use
|
||||
AddUniverse(Universe.Constituent.AggressiveGrowth(
|
||||
new UniverseSettings(Resolution.Hour,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
UniverseSettings.MinimumTimeInUniverse)));
|
||||
|
||||
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
134
Algorithm.CSharp/BasicTemplateIndiaAlgorithm.cs
Normal file
134
Algorithm.CSharp/BasicTemplateIndiaAlgorithm.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template India algorithm simply initializes the date range and cash. This is a skeleton
|
||||
/// framework you can use for designing an algorithm.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="using quantconnect" />
|
||||
/// <meta name="tag" content="trading and orders" />
|
||||
public class BasicTemplateIndiaAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2003, 10, 07); //Set Start Date
|
||||
SetEndDate(2003, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
// Find more symbols here: http://quantconnect.com/data
|
||||
// Equities Resolutions: Tick, Second, Minute, Hour, Daily.
|
||||
AddEquity("UNIONBANK", Resolution.Second, Market.India);
|
||||
|
||||
//Set Order Prperties as per the requirements for order placement
|
||||
DefaultOrderProperties = new ZerodhaOrderProperties(exchange: Exchange.NSE);
|
||||
//override default productType value set in config.json if needed - order specific productType value
|
||||
//DefaultOrderProperties = new ZerodhaOrderProperties(exchange: "nse",ZerodhaOrderProperties.KiteProductType.CNC);
|
||||
|
||||
// General Debug statement for acknowledgement
|
||||
Debug("Intialization Done");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var marketTicket = MarketOrder("UNIONBANK", 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
if (orderEvent.Status.IsFill())
|
||||
{
|
||||
Debug($"Purchased Complete: {orderEvent.Symbol}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <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 Trades", "3"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-1.01%"},
|
||||
{"Compounding Annual Return", "261.134%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.655%"},
|
||||
{"Sharpe Ratio", "8.505"},
|
||||
{"Probabilistic Sharpe Ratio", "66.840%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.091"},
|
||||
{"Beta", "1.006"},
|
||||
{"Annual Standard Deviation", "0.224"},
|
||||
{"Annual Variance", "0.05"},
|
||||
{"Information Ratio", "-33.445"},
|
||||
{"Tracking Error", "0.002"},
|
||||
{"Treynor Ratio", "1.893"},
|
||||
{"Total Fees", "$10.32"},
|
||||
{"Estimated Strategy Capacity", "$27000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "85.095"},
|
||||
{"Portfolio Turnover", "0.747"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$135639.1761"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$21852.9784"},
|
||||
{"Mean Population Estimated Insight Value", "$220.7372"},
|
||||
{"Mean Population Direction", "53.5354%"},
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "ad2216297c759d8e5aef48ff065f8919"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
public class SECReportBenchmarkAlgorithm : QCAlgorithm
|
||||
{
|
||||
private List<Security> _securities;
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 1, 1);
|
||||
SetEndDate(2019, 1, 1);
|
||||
|
||||
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
|
||||
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
|
||||
_securities = new List<Security>();
|
||||
|
||||
foreach (var ticker in tickers)
|
||||
{
|
||||
var equity = AddEquity(ticker);
|
||||
_securities.Add(equity);
|
||||
|
||||
AddData<SECReport8K>(equity.Symbol, Resolution.Daily);
|
||||
AddData<SECReport10K>(equity.Symbol, Resolution.Daily);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var security in _securities)
|
||||
{
|
||||
SECReport8K report8K = security.Data.Get<SECReport8K>();
|
||||
SECReport10K report10K = security.Data.Get<SECReport10K>();
|
||||
|
||||
if (!security.HoldStock && report8K != null && report10K != null)
|
||||
{
|
||||
SetHoldings(security.Symbol, 1d / _securities.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SmartInsider;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
public class SmartInsiderEventBenchmarkAlgorithm : QCAlgorithm
|
||||
{
|
||||
private List<Security> _securities;
|
||||
private List<Symbol> _customSymbols;
|
||||
private int _historySymbolCount;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2010, 1, 1);
|
||||
SetEndDate(2019, 1, 1);
|
||||
|
||||
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
|
||||
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
|
||||
_securities = new List<Security>();
|
||||
_customSymbols = new List<Symbol>();
|
||||
|
||||
foreach (var ticker in tickers)
|
||||
{
|
||||
var equity = AddEquity(ticker, Resolution.Hour);
|
||||
_securities.Add(equity);
|
||||
|
||||
_customSymbols.Add(
|
||||
AddData<SmartInsiderIntention>(equity.Symbol, Resolution.Daily).Symbol);
|
||||
_customSymbols.Add(
|
||||
AddData<SmartInsiderTransaction>(equity.Symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
|
||||
Schedule.On(DateRules.EveryDay(), TimeRules.At(16, 0), () =>
|
||||
{
|
||||
foreach (var slice in History(_customSymbols, TimeSpan.FromDays(5)))
|
||||
{
|
||||
_historySymbolCount += slice.Count;
|
||||
}
|
||||
|
||||
foreach (var security in _securities)
|
||||
{
|
||||
SmartInsiderIntention intention = security.Data.Get<SmartInsiderIntention>();
|
||||
SmartInsiderTransaction transaction = security.Data.Get<SmartInsiderTransaction>();
|
||||
|
||||
if (!security.HoldStock && intention != null && transaction != null)
|
||||
{
|
||||
SetHoldings(security.Symbol, 1d / _securities.Count);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var intentions = data.Get<SmartInsiderIntention>();
|
||||
var transactions = data.Get<SmartInsiderTransaction>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
@@ -74,34 +78,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "17"},
|
||||
{"Total Trades", "20"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.17%"},
|
||||
{"Compounding Annual Return", "62.899%"},
|
||||
{"Average Loss", "-0.13%"},
|
||||
{"Compounding Annual Return", "62.435%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "0.671%"},
|
||||
{"Sharpe Ratio", "3.528"},
|
||||
{"Probabilistic Sharpe Ratio", "59.247%"},
|
||||
{"Net Profit", "0.667%"},
|
||||
{"Sharpe Ratio", "3.507"},
|
||||
{"Probabilistic Sharpe Ratio", "59.181%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.381"},
|
||||
{"Beta", "0.565"},
|
||||
{"Alpha", "-0.384"},
|
||||
{"Beta", "0.564"},
|
||||
{"Annual Standard Deviation", "0.116"},
|
||||
{"Annual Variance", "0.013"},
|
||||
{"Information Ratio", "-10.77"},
|
||||
{"Information Ratio", "-10.791"},
|
||||
{"Tracking Error", "0.092"},
|
||||
{"Treynor Ratio", "0.723"},
|
||||
{"Total Fees", "$43.20"},
|
||||
{"Estimated Strategy Capacity", "$3200000.00"},
|
||||
{"Treynor Ratio", "0.718"},
|
||||
{"Total Fees", "$46.20"},
|
||||
{"Estimated Strategy Capacity", "$2300000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.644"},
|
||||
{"Fitness Score", "0.645"},
|
||||
{"Kelly Criterion Estimate", "13.787"},
|
||||
{"Kelly Criterion Probability Value", "0.231"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "66.129"},
|
||||
{"Portfolio Turnover", "0.644"},
|
||||
{"Return Over Maximum Drawdown", "65.642"},
|
||||
{"Portfolio Turnover", "0.645"},
|
||||
{"Total Insights Generated", "13"},
|
||||
{"Total Insights Closed", "10"},
|
||||
{"Total Insights Analysis Completed", "10"},
|
||||
@@ -115,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "70%"},
|
||||
{"Rolling Averaged Population Direction", "94.5154%"},
|
||||
{"Rolling Averaged Population Magnitude", "94.5154%"},
|
||||
{"OrderListHash", "b6b918fcc982a0126901ccbf14792d54"}
|
||||
{"OrderListHash", "0945ff7a39bb8f8a07b3dcc817c070aa"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm of a custom universe selection using coarse data and adding TiingoNews
|
||||
/// If conditions are met will add the underlying and trade it
|
||||
/// </summary>
|
||||
public class CoarseTiingoNewsUniverseSelectionAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const int NumberOfSymbols = 3;
|
||||
private List<Symbol> _symbols;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 03, 24);
|
||||
SetEndDate(2014, 04, 07);
|
||||
|
||||
UniverseSettings.FillForward = false;
|
||||
|
||||
AddUniverse(new CustomDataCoarseFundamentalUniverse(UniverseSettings, CoarseSelectionFunction));
|
||||
|
||||
_symbols = new List<Symbol>();
|
||||
}
|
||||
|
||||
// sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
// sort descending by daily dollar volume
|
||||
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
|
||||
|
||||
// take the top entries from our sorted collection
|
||||
var top = sortedByDollarVolume.Take(NumberOfSymbols);
|
||||
|
||||
// we need to return only the symbol objects
|
||||
return top.Select(x => QuantConnect.Symbol.CreateBase(typeof(TiingoNews), x.Symbol, x.Symbol.ID.Market));
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var articles = data.Get<TiingoNews>();
|
||||
|
||||
foreach (var kvp in articles)
|
||||
{
|
||||
var news = kvp.Value;
|
||||
if (news.Title.IndexOf("Stocks Drop", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
|
||||
{
|
||||
if (!Securities.ContainsKey(kvp.Key.Underlying))
|
||||
{
|
||||
// add underlying we want to trade
|
||||
AddSecurity(kvp.Key.Underlying);
|
||||
_symbols.Add(kvp.Key.Underlying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var symbol in _symbols)
|
||||
{
|
||||
if (Securities[symbol].HasData)
|
||||
{
|
||||
SetHoldings(symbol, 1m / _symbols.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
changes.FilterCustomSecurities = false;
|
||||
Log($"{Time} {changes}");
|
||||
}
|
||||
|
||||
private class CustomDataCoarseFundamentalUniverse : CoarseFundamentalUniverse
|
||||
{
|
||||
public CustomDataCoarseFundamentalUniverse(UniverseSettings universeSettings, Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>> selector)
|
||||
: base(universeSettings, selector)
|
||||
{ }
|
||||
|
||||
public override IEnumerable<SubscriptionRequest> GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc,
|
||||
ISubscriptionDataConfigService subscriptionService)
|
||||
{
|
||||
var config = subscriptionService.Add(
|
||||
typeof(TiingoNews),
|
||||
security.Symbol,
|
||||
UniverseSettings.Resolution,
|
||||
UniverseSettings.FillForward,
|
||||
UniverseSettings.ExtendedMarketHours,
|
||||
dataNormalizationMode: UniverseSettings.DataNormalizationMode);
|
||||
return new[]{new SubscriptionRequest(isUniverseSubscription: false,
|
||||
universe: this,
|
||||
security: security,
|
||||
configuration: config,
|
||||
startTimeUtc: currentTimeUtc,
|
||||
endTimeUtc: maximumEndTimeUtc)};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,30 +74,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "7"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.40%"},
|
||||
{"Compounding Annual Return", "1143.721%"},
|
||||
{"Compounding Annual Return", "1143.086%"},
|
||||
{"Drawdown", "1.800%"},
|
||||
{"Expectancy", "-0.321"},
|
||||
{"Expectancy", "-0.319"},
|
||||
{"Net Profit", "3.275%"},
|
||||
{"Sharpe Ratio", "23.505"},
|
||||
{"Probabilistic Sharpe Ratio", "80.498%"},
|
||||
{"Sharpe Ratio", "23.495"},
|
||||
{"Probabilistic Sharpe Ratio", "80.494%"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "0.02"},
|
||||
{"Alpha", "4.369"},
|
||||
{"Alpha", "4.366"},
|
||||
{"Beta", "1.255"},
|
||||
{"Annual Standard Deviation", "0.292"},
|
||||
{"Annual Variance", "0.085"},
|
||||
{"Information Ratio", "47.982"},
|
||||
{"Information Ratio", "47.955"},
|
||||
{"Tracking Error", "0.102"},
|
||||
{"Treynor Ratio", "5.463"},
|
||||
{"Total Fees", "$71.36"},
|
||||
{"Treynor Ratio", "5.461"},
|
||||
{"Total Fees", "$71.37"},
|
||||
{"Estimated Strategy Capacity", "$3500000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.501"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "148.133"},
|
||||
{"Return Over Maximum Drawdown", "1487.868"},
|
||||
{"Sortino Ratio", "148.07"},
|
||||
{"Return Over Maximum Drawdown", "1487.238"},
|
||||
{"Portfolio Turnover", "0.501"},
|
||||
{"Total Insights Generated", "2"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -112,7 +112,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "61b6afca11a1f15a63237d0346f383f7"}
|
||||
{"OrderListHash", "5a171f804d47cd27f84aaef791da8594"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
@@ -74,34 +78,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Total Trades", "17"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "38.832%"},
|
||||
{"Compounding Annual Return", "37.229%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "0.420%"},
|
||||
{"Sharpe Ratio", "5.579"},
|
||||
{"Probabilistic Sharpe Ratio", "67.318%"},
|
||||
{"Net Profit", "0.405%"},
|
||||
{"Sharpe Ratio", "5.424"},
|
||||
{"Probabilistic Sharpe Ratio", "66.818%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.184"},
|
||||
{"Beta", "0.248"},
|
||||
{"Alpha", "-0.191"},
|
||||
{"Beta", "0.247"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-10.012"},
|
||||
{"Tracking Error", "0.167"},
|
||||
{"Treynor Ratio", "1.241"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Estimated Strategy Capacity", "$38000000.00"},
|
||||
{"Information Ratio", "-10.052"},
|
||||
{"Tracking Error", "0.168"},
|
||||
{"Treynor Ratio", "1.207"},
|
||||
{"Total Fees", "$17.00"},
|
||||
{"Estimated Strategy Capacity", "$45000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.063"},
|
||||
{"Fitness Score", "0.067"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "70.89"},
|
||||
{"Portfolio Turnover", "0.063"},
|
||||
{"Return Over Maximum Drawdown", "65.855"},
|
||||
{"Portfolio Turnover", "0.067"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
@@ -115,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "21e4704a124ba562d042e1e9962f4316"}
|
||||
{"OrderListHash", "8a8c913e5ad4ea956a345c84430649c2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(100000); // Set Strategy Cash
|
||||
|
||||
// Add QC500 Universe
|
||||
AddUniverse(Universe.Index.QC500);
|
||||
AddUniverse(Universe.QC500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "9ce7252112d0ad7be0704297f7d48a88"}
|
||||
{"OrderListHash", "b7b8e83e4456e143c2c4c11fa31a1cf2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "3df007afa8125770e8f1a49263af90a2"}
|
||||
{"OrderListHash", "eba70a03119f2e8fe526d1092fbc36d0"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "61f4d3c109fc4b6b9eb14d2e4eec4843"}
|
||||
{"OrderListHash", "e357cfa77fd5e5b974c68d550fa66490"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2017, 07, 04);
|
||||
SetEndDate(2018, 07, 04);
|
||||
|
||||
@@ -187,31 +191,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "6441"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.07%"},
|
||||
{"Compounding Annual Return", "14.722%"},
|
||||
{"Drawdown", "10.700%"},
|
||||
{"Expectancy", "0.067"},
|
||||
{"Net Profit", "14.722%"},
|
||||
{"Sharpe Ratio", "1.056"},
|
||||
{"Probabilistic Sharpe Ratio", "49.750%"},
|
||||
{"Compounding Annual Return", "14.802%"},
|
||||
{"Drawdown", "10.400%"},
|
||||
{"Expectancy", "0.068"},
|
||||
{"Net Profit", "14.802%"},
|
||||
{"Sharpe Ratio", "1.077"},
|
||||
{"Probabilistic Sharpe Ratio", "50.578%"},
|
||||
{"Loss Rate", "46%"},
|
||||
{"Win Rate", "54%"},
|
||||
{"Profit-Loss Ratio", "0.97"},
|
||||
{"Alpha", "0.136"},
|
||||
{"Beta", "-0.07"},
|
||||
{"Annual Standard Deviation", "0.121"},
|
||||
{"Annual Variance", "0.015"},
|
||||
{"Information Ratio", "0.043"},
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-1.836"},
|
||||
{"Total Fees", "$7500.86"},
|
||||
{"Alpha", "0.137"},
|
||||
{"Beta", "-0.069"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "0.046"},
|
||||
{"Tracking Error", "0.169"},
|
||||
{"Treynor Ratio", "-1.869"},
|
||||
{"Total Fees", "$7495.19"},
|
||||
{"Estimated Strategy Capacity", "$320000.00"},
|
||||
{"Lowest Capacity Asset", "BNO UN3IMQ2JU1YD"},
|
||||
{"Fitness Score", "0.691"},
|
||||
{"Fitness Score", "0.695"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.238"},
|
||||
{"Return Over Maximum Drawdown", "1.378"},
|
||||
{"Portfolio Turnover", "1.638"},
|
||||
{"Sortino Ratio", "1.269"},
|
||||
{"Return Over Maximum Drawdown", "1.424"},
|
||||
{"Portfolio Turnover", "1.613"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -225,7 +229,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6047b278450c563805d0ea68c04c013a"}
|
||||
{"OrderListHash", "df66ec72bb4332b14bbe31ec9bea7ffc"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// this sets the resolution for data subscriptions added by our universe
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
// set our start and end for backtest mode
|
||||
SetStartDate(2017, 07, 04);
|
||||
SetEndDate(2018, 07, 04);
|
||||
@@ -160,31 +164,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "5059"},
|
||||
{"Average Win", "0.08%"},
|
||||
{"Average Loss", "-0.08%"},
|
||||
{"Compounding Annual Return", "16.134%"},
|
||||
{"Drawdown", "10.600%"},
|
||||
{"Expectancy", "0.079"},
|
||||
{"Net Profit", "16.134%"},
|
||||
{"Sharpe Ratio", "1.151"},
|
||||
{"Probabilistic Sharpe Ratio", "53.288%"},
|
||||
{"Compounding Annual Return", "16.153%"},
|
||||
{"Drawdown", "10.300%"},
|
||||
{"Expectancy", "0.081"},
|
||||
{"Net Profit", "16.153%"},
|
||||
{"Sharpe Ratio", "1.17"},
|
||||
{"Probabilistic Sharpe Ratio", "54.048%"},
|
||||
{"Loss Rate", "45%"},
|
||||
{"Win Rate", "55%"},
|
||||
{"Profit-Loss Ratio", "0.96"},
|
||||
{"Alpha", "0.148"},
|
||||
{"Beta", "-0.069"},
|
||||
{"Annual Standard Deviation", "0.121"},
|
||||
{"Annual Variance", "0.015"},
|
||||
{"Profit-Loss Ratio", "0.97"},
|
||||
{"Alpha", "0.147"},
|
||||
{"Beta", "-0.068"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "0.11"},
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-2.017"},
|
||||
{"Total Fees", "$5875.05"},
|
||||
{"Tracking Error", "0.169"},
|
||||
{"Treynor Ratio", "-2.057"},
|
||||
{"Total Fees", "$5869.25"},
|
||||
{"Estimated Strategy Capacity", "$320000.00"},
|
||||
{"Lowest Capacity Asset", "BNO UN3IMQ2JU1YD"},
|
||||
{"Fitness Score", "0.707"},
|
||||
{"Fitness Score", "0.711"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.361"},
|
||||
{"Return Over Maximum Drawdown", "1.521"},
|
||||
{"Portfolio Turnover", "1.295"},
|
||||
{"Sortino Ratio", "1.389"},
|
||||
{"Return Over Maximum Drawdown", "1.564"},
|
||||
{"Portfolio Turnover", "1.271"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -198,7 +202,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "3600b36f0393af24858793e4606c8f63"}
|
||||
{"OrderListHash", "5f08ae4997156d48171559e452dda9d3"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an example algorithm showcasing the <see cref="Security.Data"/> features
|
||||
/// </summary>
|
||||
public class DynamicSecurityDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Security GOOGL;
|
||||
private const string Ticker = "GOOGL";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2015, 10, 22);
|
||||
SetEndDate(2015, 10, 30);
|
||||
|
||||
GOOGL = AddEquity(Ticker, Resolution.Daily);
|
||||
|
||||
AddData<SECReport8K>(Ticker, Resolution.Daily);
|
||||
AddData<SECReport10K>(Ticker, Resolution.Daily);
|
||||
AddData<SECReport10Q>(Ticker, Resolution.Daily);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// The Security object's Data property provides convenient access
|
||||
// to the various types of data related to that security. You can
|
||||
// access not only the security's price data, but also any custom
|
||||
// data that is mapped to the security, such as our SEC reports.
|
||||
|
||||
// 1. Get the most recent data point of a particular type:
|
||||
// 1.a Using the C# generic method, Get<T>:
|
||||
SECReport8K googlSec8kReport = GOOGL.Data.Get<SECReport8K>();
|
||||
SECReport10K googlSec10kReport = GOOGL.Data.Get<SECReport10K>();
|
||||
Log($"{Time:o}: 8K: {googlSec8kReport}");
|
||||
Log($"{Time:o}: 10K: {googlSec10kReport}");
|
||||
|
||||
// 2. Get the list of data points of a particular type for the most recent time step:
|
||||
// 2.a Using the C# generic method, GetAll<T>:
|
||||
List<SECReport8K> googlSec8kReports = GOOGL.Data.GetAll<SECReport8K>();
|
||||
List<SECReport10K> googlSec10kReports = GOOGL.Data.GetAll<SECReport10K>();
|
||||
Log($"{Time:o}: List: 8K: {googlSec8kReports.Count}");
|
||||
Log($"{Time:o}: List: 10K: {googlSec10kReports.Count}");
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
Buy(GOOGL.Symbol, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
147
Algorithm.CSharp/DynamicSecurityDataRegressionAlgorithm.cs
Normal file
147
Algorithm.CSharp/DynamicSecurityDataRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* 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.IO;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an example algorithm showcasing the <see cref="Security.Data"/> features
|
||||
/// </summary>
|
||||
public class DynamicSecurityDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Security Equity;
|
||||
private const string Ticker = "GOOGL";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2015, 10, 22);
|
||||
SetEndDate(2015, 10, 30);
|
||||
|
||||
Equity = AddEquity(Ticker, Resolution.Daily);
|
||||
var customLinkedEquity = AddData<LinkedData>(Ticker, Resolution.Daily).Symbol;
|
||||
|
||||
// Adding linked data manually to cache for example purposes, since
|
||||
// LinkedData is a type used for testing and doesn't point to any real data.
|
||||
Equity.Cache.AddDataList(new List<LinkedData>
|
||||
{
|
||||
new LinkedData
|
||||
{
|
||||
Count = 100,
|
||||
|
||||
Symbol = customLinkedEquity,
|
||||
EndTime = StartDate,
|
||||
},
|
||||
new LinkedData
|
||||
{
|
||||
Count = 50,
|
||||
|
||||
Symbol = customLinkedEquity,
|
||||
EndTime = StartDate
|
||||
}
|
||||
}, typeof(LinkedData), false);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// The Security object's Data property provides convenient access
|
||||
// to the various types of data related to that security. You can
|
||||
// access not only the security's price data, but also any custom
|
||||
// data that is mapped to the security, such as our SEC reports.
|
||||
|
||||
// 1. Get the most recent data point of a particular type:
|
||||
// 1.a Using the C# generic method, Get<T>:
|
||||
LinkedData customLinkedData = Equity.Data.Get<LinkedData>();
|
||||
Log($"{Time:o}: LinkedData: {customLinkedData}");
|
||||
|
||||
// 2. Get the list of data points of a particular type for the most recent time step:
|
||||
// 2.a Using the C# generic method, GetAll<T>:
|
||||
List<LinkedData> customLinkedDataList = Equity.Data.GetAll<LinkedData>();
|
||||
Log($"{Time:o}: List: LinkedData: {customLinkedDataList.Count}");
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
Buy(Equity.Symbol, 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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "28.411%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.618%"},
|
||||
{"Sharpe Ratio", "9.975"},
|
||||
{"Probabilistic Sharpe Ratio", "99.752%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.23"},
|
||||
{"Beta", "-0.031"},
|
||||
{"Annual Standard Deviation", "0.022"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.899"},
|
||||
{"Tracking Error", "0.101"},
|
||||
{"Treynor Ratio", "-6.961"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$1000000000.00"},
|
||||
{"Lowest Capacity Asset", "GOOG T1AZ164W5VTX"},
|
||||
{"Fitness Score", "0.008"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "383.48"},
|
||||
{"Portfolio Turnover", "0.008"},
|
||||
{"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", "668caaf6ff8f35e16f05228541e99720"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// set algorithm framework models except ALPHA
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(_symbol));
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -111,34 +115,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "5"},
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-72.266%"},
|
||||
{"Compounding Annual Return", "-72.233%"},
|
||||
{"Drawdown", "2.900%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-1.742%"},
|
||||
{"Sharpe Ratio", "-2.983"},
|
||||
{"Probabilistic Sharpe Ratio", "22.301%"},
|
||||
{"Net Profit", "-1.740%"},
|
||||
{"Sharpe Ratio", "-2.982"},
|
||||
{"Probabilistic Sharpe Ratio", "22.315%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.388"},
|
||||
{"Alpha", "-0.387"},
|
||||
{"Beta", "-0.138"},
|
||||
{"Annual Standard Deviation", "0.195"},
|
||||
{"Annual Variance", "0.038"},
|
||||
{"Information Ratio", "-6.727"},
|
||||
{"Tracking Error", "0.294"},
|
||||
{"Treynor Ratio", "4.204"},
|
||||
{"Total Fees", "$19.23"},
|
||||
{"Estimated Strategy Capacity", "$540000000.00"},
|
||||
{"Treynor Ratio", "4.201"},
|
||||
{"Total Fees", "$20.23"},
|
||||
{"Estimated Strategy Capacity", "$520000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.054"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-4.06"},
|
||||
{"Return Over Maximum Drawdown", "-25.225"},
|
||||
{"Portfolio Turnover", "0.999"},
|
||||
{"Sortino Ratio", "-4.059"},
|
||||
{"Return Over Maximum Drawdown", "-25.228"},
|
||||
{"Portfolio Turnover", "1"},
|
||||
{"Total Insights Generated", "1"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -152,7 +156,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "39c512346541c1d40c04a514d605b723"}
|
||||
{"OrderListHash", "4c45e3bf74e05e81b872d293cb65391a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "50%"},
|
||||
{"Rolling Averaged Population Direction", "50%"},
|
||||
{"Rolling Averaged Population Magnitude", "50%"},
|
||||
{"OrderListHash", "657b9cb12ee7097df61fff5661192ccf"}
|
||||
{"OrderListHash", "de18d7406b7b5126fcb974f9d283aca0"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetAlpha(new ConstantFutureContractAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
}
|
||||
|
||||
// future symbol universe selection function
|
||||
@@ -128,34 +132,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "4"},
|
||||
{"Total Trades", "7"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.91%"},
|
||||
{"Compounding Annual Return", "-99.755%"},
|
||||
{"Average Loss", "-1.40%"},
|
||||
{"Compounding Annual Return", "-99.829%"},
|
||||
{"Drawdown", "29.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-7.463%"},
|
||||
{"Sharpe Ratio", "-0.605"},
|
||||
{"Probabilistic Sharpe Ratio", "34.850%"},
|
||||
{"Net Profit", "-7.888%"},
|
||||
{"Sharpe Ratio", "-0.612"},
|
||||
{"Probabilistic Sharpe Ratio", "34.280%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-13.915"},
|
||||
{"Beta", "6.519"},
|
||||
{"Annual Standard Deviation", "1.632"},
|
||||
{"Annual Variance", "2.665"},
|
||||
{"Information Ratio", "-2.066"},
|
||||
{"Tracking Error", "1.438"},
|
||||
{"Alpha", "-13.93"},
|
||||
{"Beta", "6.525"},
|
||||
{"Annual Standard Deviation", "1.619"},
|
||||
{"Annual Variance", "2.62"},
|
||||
{"Information Ratio", "-2.091"},
|
||||
{"Tracking Error", "1.422"},
|
||||
{"Treynor Ratio", "-0.152"},
|
||||
{"Total Fees", "$33.30"},
|
||||
{"Estimated Strategy Capacity", "$17000000.00"},
|
||||
{"Total Fees", "$40.70"},
|
||||
{"Estimated Strategy Capacity", "$4000000.00"},
|
||||
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
|
||||
{"Fitness Score", "0.079"},
|
||||
{"Fitness Score", "0.072"},
|
||||
{"Kelly Criterion Estimate", "-9.366"},
|
||||
{"Kelly Criterion Probability Value", "0.607"},
|
||||
{"Sortino Ratio", "-4.657"},
|
||||
{"Return Over Maximum Drawdown", "-5.203"},
|
||||
{"Portfolio Turnover", "4.377"},
|
||||
{"Sortino Ratio", "-5.172"},
|
||||
{"Return Over Maximum Drawdown", "-5.25"},
|
||||
{"Portfolio Turnover", "4.987"},
|
||||
{"Total Insights Generated", "10"},
|
||||
{"Total Insights Closed", "8"},
|
||||
{"Total Insights Analysis Completed", "8"},
|
||||
@@ -169,7 +173,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "25.058%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f4c4b763b5ade918cfb7932e276d069f"}
|
||||
{"OrderListHash", "874fc945335aa8d93f2e3734641f9890"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Estimize;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example algorithm shows how to import and use Estimize data types.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="estimize" />
|
||||
public class EstimizeDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2017, 1, 1);
|
||||
SetEndDate(2017, 12, 31);
|
||||
|
||||
// be sure to add the underlying data source for our estimize data as it requires the mappings
|
||||
AddEquity("AAPL");
|
||||
|
||||
AddData<EstimizeRelease>("AAPL");
|
||||
AddData<EstimizeEstimate>("AAPL");
|
||||
AddData<EstimizeConsensus>("AAPL");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">EstimizeRelease object containing the stock release data</param>
|
||||
public void OnData(EstimizeRelease data)
|
||||
{
|
||||
Log($"{Time} - {data}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">EstimizeEstimate object containing the stock release data</param>
|
||||
public void OnData(EstimizeEstimate data)
|
||||
{
|
||||
Log($"{Time} - {data}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">EstimizeConsensus object containing the stock release data</param>
|
||||
public void OnData(EstimizeConsensus data)
|
||||
{
|
||||
Log($"{Time} - {data}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,33 +127,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "18"},
|
||||
{"Total Trades", "19"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-74.117%"},
|
||||
{"Compounding Annual Return", "-73.997%"},
|
||||
{"Drawdown", "2.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-1.044%"},
|
||||
{"Sharpe Ratio", "-8.269"},
|
||||
{"Net Profit", "-1.040%"},
|
||||
{"Sharpe Ratio", "-8.265"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.187"},
|
||||
{"Beta", "0.584"},
|
||||
{"Beta", "0.585"},
|
||||
{"Annual Standard Deviation", "0.065"},
|
||||
{"Annual Variance", "0.004"},
|
||||
{"Information Ratio", "1.354"},
|
||||
{"Information Ratio", "1.345"},
|
||||
{"Tracking Error", "0.048"},
|
||||
{"Treynor Ratio", "-0.926"},
|
||||
{"Total Fees", "$20.45"},
|
||||
{"Estimated Strategy Capacity", "$350000.00"},
|
||||
{"Treynor Ratio", "-0.925"},
|
||||
{"Total Fees", "$21.45"},
|
||||
{"Estimated Strategy Capacity", "$830000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-11.829"},
|
||||
{"Return Over Maximum Drawdown", "-71.014"},
|
||||
{"Sortino Ratio", "-11.746"},
|
||||
{"Return Over Maximum Drawdown", "-71.142"},
|
||||
{"Portfolio Turnover", "0.341"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -168,7 +168,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "fbefbed1d94294a14bc563a71b336056"}
|
||||
{"OrderListHash", "6ee62edf1ac883882b0fcef8cb3e9bae"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,13 +79,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "8.171%"},
|
||||
{"Drawdown", "55.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "125.419%"},
|
||||
{"Net Profit", "125.420%"},
|
||||
{"Sharpe Ratio", "0.469"},
|
||||
{"Probabilistic Sharpe Ratio", "2.603%"},
|
||||
{"Loss Rate", "100%"},
|
||||
@@ -98,8 +98,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "-0.001"},
|
||||
{"Tracking Error", "0.265"},
|
||||
{"Treynor Ratio", "-0.927"},
|
||||
{"Total Fees", "$44.46"},
|
||||
{"Estimated Strategy Capacity", "$1300000000.00"},
|
||||
{"Total Fees", "$43.46"},
|
||||
{"Estimated Strategy Capacity", "$430000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "37.332"},
|
||||
@@ -120,7 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "43.4499%"},
|
||||
{"Rolling Averaged Population Direction", "48.5717%"},
|
||||
{"Rolling Averaged Population Magnitude", "48.5717%"},
|
||||
{"OrderListHash", "03cc0ad5b1c4b7803b2e9483da1d7543"}
|
||||
{"OrderListHash", "3aa1d64da57ef9841bef4aa8b0292521"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Data.Market;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing GH issue #5232
|
||||
/// Regression algorithm reproducing GH issue #5232, where we expect SPWR to be mapped to SPWRA
|
||||
/// </summary>
|
||||
public class HourResolutionMappingEventRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
@@ -127,7 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "8d5c6263fbdfa4b2338fc725e27b93e9"}
|
||||
{"OrderListHash", "4bf8a2d15c6c6ac98e55d7c6ea10f54e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4014a968be616942fad8aff7c37104bc"}
|
||||
{"OrderListHash", "d22c476870c3d52698c94a055b90ed6e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "fb41809f0365b2c06d0ff9d8e40a4775"}
|
||||
{"OrderListHash", "f6ee7a06dc920d5fdabc4bccb84c90df"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm that will test that <see cref="IAlgorithmSettings.MinimumOrderMarginPortfolioPercentage"/>
|
||||
/// is respected by the <see cref="ImmediateExecutionModel"/>
|
||||
/// </summary>
|
||||
public class ImmediateExecutionModelMinimumOrderMarginRegressionAlgorithm : BasicTemplateFrameworkAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
// this setting is the difference between doing 3 trades and > 60
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.001m;
|
||||
SetPortfolioConstruction(new CustomPortfolioConstructionModel(TimeKeeper));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
private class CustomPortfolioConstructionModel : EqualWeightingPortfolioConstructionModel
|
||||
{
|
||||
private ITimeKeeper _timeKeeper;
|
||||
public CustomPortfolioConstructionModel(ITimeKeeper timeKeeper)
|
||||
{
|
||||
_timeKeeper = timeKeeper;
|
||||
}
|
||||
protected override Dictionary<Insight, double> DetermineTargetPercent(List<Insight> activeInsights)
|
||||
{
|
||||
var baseResult = base.DetermineTargetPercent(activeInsights);
|
||||
|
||||
// we generate some fake noise in the percentage allocation
|
||||
var adjustPercentage = _timeKeeper.UtcTime.Minute % 2 == 0;
|
||||
return baseResult.ToDictionary(pair => pair.Key, pair => adjustPercentage ? pair.Value - 0.001 : pair.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "b2d634cb245e439e68aedc264ad37809"}
|
||||
{"OrderListHash", "818346776a934bcaabb2752b31f8b092"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
@@ -74,34 +78,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Total Trades", "17"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "38.832%"},
|
||||
{"Compounding Annual Return", "37.229%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "0.420%"},
|
||||
{"Sharpe Ratio", "5.579"},
|
||||
{"Probabilistic Sharpe Ratio", "67.318%"},
|
||||
{"Net Profit", "0.405%"},
|
||||
{"Sharpe Ratio", "5.424"},
|
||||
{"Probabilistic Sharpe Ratio", "66.818%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.184"},
|
||||
{"Beta", "0.248"},
|
||||
{"Alpha", "-0.191"},
|
||||
{"Beta", "0.247"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-10.012"},
|
||||
{"Tracking Error", "0.167"},
|
||||
{"Treynor Ratio", "1.241"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Estimated Strategy Capacity", "$38000000.00"},
|
||||
{"Information Ratio", "-10.052"},
|
||||
{"Tracking Error", "0.168"},
|
||||
{"Treynor Ratio", "1.207"},
|
||||
{"Total Fees", "$17.00"},
|
||||
{"Estimated Strategy Capacity", "$45000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.063"},
|
||||
{"Fitness Score", "0.067"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "70.89"},
|
||||
{"Portfolio Turnover", "0.063"},
|
||||
{"Return Over Maximum Drawdown", "65.855"},
|
||||
{"Portfolio Turnover", "0.067"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
@@ -115,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "21e4704a124ba562d042e1e9962f4316"}
|
||||
{"OrderListHash", "8a8c913e5ad4ea956a345c84430649c2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,30 +85,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.12%"},
|
||||
{"Compounding Annual Return", "240.487%"},
|
||||
{"Compounding Annual Return", "239.838%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.579%"},
|
||||
{"Sharpe Ratio", "8.903"},
|
||||
{"Net Profit", "1.576%"},
|
||||
{"Sharpe Ratio", "8.895"},
|
||||
{"Probabilistic Sharpe Ratio", "67.609%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.002"},
|
||||
{"Beta", "0.999"},
|
||||
{"Alpha", "-0.003"},
|
||||
{"Beta", "0.997"},
|
||||
{"Annual Standard Deviation", "0.222"},
|
||||
{"Annual Variance", "0.049"},
|
||||
{"Information Ratio", "-14.44"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "1.981"},
|
||||
{"Information Ratio", "-14.544"},
|
||||
{"Tracking Error", "0.001"},
|
||||
{"Treynor Ratio", "1.979"},
|
||||
{"Total Fees", "$65.43"},
|
||||
{"Estimated Strategy Capacity", "$5600000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.979"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "7.448"},
|
||||
{"Return Over Maximum Drawdown", "70.494"},
|
||||
{"Sortino Ratio", "7.443"},
|
||||
{"Return Over Maximum Drawdown", "70.425"},
|
||||
{"Portfolio Turnover", "4.74"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
@@ -123,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "5d45f854274d541d6f32c4aa7ed6e11d"}
|
||||
{"OrderListHash", "5058ddf4d396a288471e8954ded3bf7a"}
|
||||
};
|
||||
|
||||
private class TestBrokerageModel : DefaultBrokerageModel
|
||||
|
||||
@@ -52,6 +52,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Resolution.Daily, PortfolioBias.Long));
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
// set algorithm framework models
|
||||
SetUniverseSelection(
|
||||
new ManualUniverseSelectionModel(
|
||||
@@ -98,33 +102,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "9"},
|
||||
{"Total Trades", "13"},
|
||||
{"Average Win", "0.99%"},
|
||||
{"Average Loss", "-0.60%"},
|
||||
{"Compounding Annual Return", "216.678%"},
|
||||
{"Average Loss", "-0.20%"},
|
||||
{"Compounding Annual Return", "216.590%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "0.318"},
|
||||
{"Net Profit", "1.485%"},
|
||||
{"Sharpe Ratio", "7.299"},
|
||||
{"Probabilistic Sharpe Ratio", "64.957%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "1.64"},
|
||||
{"Expectancy", "0.476"},
|
||||
{"Net Profit", "1.484%"},
|
||||
{"Sharpe Ratio", "7.296"},
|
||||
{"Probabilistic Sharpe Ratio", "64.952%"},
|
||||
{"Loss Rate", "75%"},
|
||||
{"Win Rate", "25%"},
|
||||
{"Profit-Loss Ratio", "4.91"},
|
||||
{"Alpha", "-0.36"},
|
||||
{"Beta", "1.003"},
|
||||
{"Annual Standard Deviation", "0.223"},
|
||||
{"Annual Variance", "0.05"},
|
||||
{"Information Ratio", "-100.088"},
|
||||
{"Information Ratio", "-100.202"},
|
||||
{"Tracking Error", "0.004"},
|
||||
{"Treynor Ratio", "1.624"},
|
||||
{"Total Fees", "$309.75"},
|
||||
{"Estimated Strategy Capacity", "$15000000.00"},
|
||||
{"Total Fees", "$313.73"},
|
||||
{"Estimated Strategy Capacity", "$16000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.999"},
|
||||
{"Kelly Criterion Estimate", "-6.821"},
|
||||
{"Kelly Criterion Probability Value", "0.592"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "68.722"},
|
||||
{"Return Over Maximum Drawdown", "68.689"},
|
||||
{"Portfolio Turnover", "1.741"},
|
||||
{"Total Insights Generated", "10"},
|
||||
{"Total Insights Closed", "8"},
|
||||
@@ -139,7 +143,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "73.1163%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "79a973155c0106b60249931daa89c54b"}
|
||||
{"OrderListHash", "bdee04be3413e3cd32c3ce95bcc4994b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
110
Algorithm.CSharp/MappedBenchmarkRegressionAlgorithm.cs
Normal file
110
Algorithm.CSharp/MappedBenchmarkRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm using a benchmark security which should be mapped from SPWR to SPWRA during the backtest
|
||||
/// </summary>
|
||||
public class MappedBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2008, 08, 20);
|
||||
SetEndDate(2008, 10, 1);
|
||||
|
||||
SetBenchmark("SPWR");
|
||||
AddEquity("SPY", Resolution.Hour);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <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 Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-50.371%"},
|
||||
{"Drawdown", "12.700%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-7.863%"},
|
||||
{"Sharpe Ratio", "-1.25"},
|
||||
{"Probabilistic Sharpe Ratio", "17.179%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.357"},
|
||||
{"Beta", "0.262"},
|
||||
{"Annual Standard Deviation", "0.404"},
|
||||
{"Annual Variance", "0.163"},
|
||||
{"Information Ratio", "0.07"},
|
||||
{"Tracking Error", "0.873"},
|
||||
{"Treynor Ratio", "-1.927"},
|
||||
{"Total Fees", "$5.10"},
|
||||
{"Estimated Strategy Capacity", "$180000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-3.681"},
|
||||
{"Return Over Maximum Drawdown", "-4.174"},
|
||||
{"Portfolio Turnover", "0.034"},
|
||||
{"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", "d5466a4f274a65313a1f58c78d3cfd00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -118,22 +118,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0.39%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "1754.167%"},
|
||||
{"Compounding Annual Return", "1750.998%"},
|
||||
{"Drawdown", "5.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "3.804%"},
|
||||
{"Sharpe Ratio", "18.048"},
|
||||
{"Probabilistic Sharpe Ratio", "67.763%"},
|
||||
{"Net Profit", "3.802%"},
|
||||
{"Sharpe Ratio", "18.029"},
|
||||
{"Probabilistic Sharpe Ratio", "67.762%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "4.105"},
|
||||
{"Beta", "2.018"},
|
||||
{"Alpha", "4.093"},
|
||||
{"Beta", "2.017"},
|
||||
{"Annual Standard Deviation", "0.449"},
|
||||
{"Annual Variance", "0.202"},
|
||||
{"Information Ratio", "27.019"},
|
||||
{"Tracking Error", "0.227"},
|
||||
{"Treynor Ratio", "4.017"},
|
||||
{"Annual Variance", "0.201"},
|
||||
{"Information Ratio", "26.993"},
|
||||
{"Tracking Error", "0.226"},
|
||||
{"Treynor Ratio", "4.012"},
|
||||
{"Total Fees", "$27.50"},
|
||||
{"Estimated Strategy Capacity", "$22000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
@@ -141,8 +141,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "209.948"},
|
||||
{"Portfolio Turnover", "1.982"},
|
||||
{"Return Over Maximum Drawdown", "209.889"},
|
||||
{"Portfolio Turnover", "1.983"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -156,7 +156,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "944baeb4b368b53b21d03fc4b2853576"}
|
||||
{"OrderListHash", "06b7f4d59c69f75c498e342909039dbc"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,30 +86,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "14"},
|
||||
{"Average Win", "0.21%"},
|
||||
{"Average Loss", "-0.53%"},
|
||||
{"Compounding Annual Return", "496.516%"},
|
||||
{"Compounding Annual Return", "496.266%"},
|
||||
{"Drawdown", "1.200%"},
|
||||
{"Expectancy", "-0.446"},
|
||||
{"Net Profit", "2.477%"},
|
||||
{"Sharpe Ratio", "13.432"},
|
||||
{"Probabilistic Sharpe Ratio", "74.259%"},
|
||||
{"Expectancy", "-0.444"},
|
||||
{"Net Profit", "2.476%"},
|
||||
{"Sharpe Ratio", "13.427"},
|
||||
{"Probabilistic Sharpe Ratio", "74.256%"},
|
||||
{"Loss Rate", "60%"},
|
||||
{"Win Rate", "40%"},
|
||||
{"Profit-Loss Ratio", "0.39"},
|
||||
{"Alpha", "1.364"},
|
||||
{"Alpha", "1.363"},
|
||||
{"Beta", "0.797"},
|
||||
{"Annual Standard Deviation", "0.185"},
|
||||
{"Annual Variance", "0.034"},
|
||||
{"Information Ratio", "10.111"},
|
||||
{"Information Ratio", "10.101"},
|
||||
{"Tracking Error", "0.107"},
|
||||
{"Treynor Ratio", "3.11"},
|
||||
{"Total Fees", "$33.01"},
|
||||
{"Treynor Ratio", "3.108"},
|
||||
{"Total Fees", "$33.02"},
|
||||
{"Estimated Strategy Capacity", "$24000000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.721"},
|
||||
{"Kelly Criterion Estimate", "13.787"},
|
||||
{"Kelly Criterion Probability Value", "0.231"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "409.172"},
|
||||
{"Return Over Maximum Drawdown", "408.965"},
|
||||
{"Portfolio Turnover", "0.721"},
|
||||
{"Total Insights Generated", "13"},
|
||||
{"Total Insights Closed", "10"},
|
||||
@@ -124,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "70%"},
|
||||
{"Rolling Averaged Population Direction", "94.5154%"},
|
||||
{"Rolling Averaged Population Magnitude", "94.5154%"},
|
||||
{"OrderListHash", "142004a866da177aa8d83a1f75d32e84"}
|
||||
{"OrderListHash", "882365cfef306729c7e5eda8c1d4b38c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
85
Algorithm.CSharp/MinimumOrderMarginRegressionAlgorithm.cs
Normal file
85
Algorithm.CSharp/MinimumOrderMarginRegressionAlgorithm.cs
Normal file
@@ -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 QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm testing the effect of <see cref="IAlgorithmSettings.MinimumOrderMarginPortfolioPercentage"/>.
|
||||
/// Setting a minimum order size of 1% of portfolio reduces order count significantly
|
||||
/// </summary>
|
||||
public class MinimumOrderMarginRegressionAlgorithm : NoMinimumOrderMarginRegressionAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.01m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "39.100%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.423%"},
|
||||
{"Sharpe Ratio", "5.634"},
|
||||
{"Probabilistic Sharpe Ratio", "67.498%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.181"},
|
||||
{"Beta", "0.248"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-9.989"},
|
||||
{"Tracking Error", "0.167"},
|
||||
{"Treynor Ratio", "1.254"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$150000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.062"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "71.484"},
|
||||
{"Portfolio Turnover", "0.062"},
|
||||
{"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", "86f2942f2fcfc7ee9e44521f86adc07d"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -102,33 +102,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "10"},
|
||||
{"Average Win", "2.44%"},
|
||||
{"Average Win", "2.45%"},
|
||||
{"Average Loss", "-1.97%"},
|
||||
{"Compounding Annual Return", "9652.166%"},
|
||||
{"Compounding Annual Return", "9644.133%"},
|
||||
{"Drawdown", "9.800%"},
|
||||
{"Expectancy", "0.346"},
|
||||
{"Net Profit", "6.031%"},
|
||||
{"Sharpe Ratio", "42.916"},
|
||||
{"Probabilistic Sharpe Ratio", "63.960%"},
|
||||
{"Net Profit", "6.030%"},
|
||||
{"Sharpe Ratio", "42.882"},
|
||||
{"Probabilistic Sharpe Ratio", "63.958%"},
|
||||
{"Loss Rate", "40%"},
|
||||
{"Win Rate", "60%"},
|
||||
{"Profit-Loss Ratio", "1.24"},
|
||||
{"Alpha", "28.402"},
|
||||
{"Beta", "3.699"},
|
||||
{"Alpha", "28.369"},
|
||||
{"Beta", "3.698"},
|
||||
{"Annual Standard Deviation", "0.833"},
|
||||
{"Annual Variance", "0.693"},
|
||||
{"Information Ratio", "55.006"},
|
||||
{"Information Ratio", "54.961"},
|
||||
{"Tracking Error", "0.614"},
|
||||
{"Treynor Ratio", "9.661"},
|
||||
{"Total Fees", "$109.24"},
|
||||
{"Estimated Strategy Capacity", "$8300000.00"},
|
||||
{"Treynor Ratio", "9.654"},
|
||||
{"Total Fees", "$109.28"},
|
||||
{"Estimated Strategy Capacity", "$8400000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.999"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "108.835"},
|
||||
{"Portfolio Turnover", "7.207"},
|
||||
{"Return Over Maximum Drawdown", "108.753"},
|
||||
{"Portfolio Turnover", "7.21"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -142,7 +142,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "3a14e9b1ddbf4531b26368cbacdb2fdf"}
|
||||
{"OrderListHash", "d43d7155325d65ad1eaeb740f46fa63c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
108
Algorithm.CSharp/NoMinimumOrderMarginRegressionAlgorithm.cs
Normal file
108
Algorithm.CSharp/NoMinimumOrderMarginRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm testing the effect of No <see cref="IAlgorithmSettings.MinimumOrderMarginPortfolioPercentage"/>
|
||||
/// causing multiple trades to be filled, see <see cref="MinimumOrderMarginRegressionAlgorithm"/> instead
|
||||
/// </summary>
|
||||
public class NoMinimumOrderMarginRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
AddEquity("SPY", Resolution.Minute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
SetHoldings("SPY", 0.25);
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "59"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "32.831%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-0.919"},
|
||||
{"Net Profit", "0.364%"},
|
||||
{"Sharpe Ratio", "4.969"},
|
||||
{"Probabilistic Sharpe Ratio", "65.344%"},
|
||||
{"Loss Rate", "93%"},
|
||||
{"Win Rate", "7%"},
|
||||
{"Profit-Loss Ratio", "0.22"},
|
||||
{"Alpha", "-0.213"},
|
||||
{"Beta", "0.243"},
|
||||
{"Annual Standard Deviation", "0.054"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-10.175"},
|
||||
{"Tracking Error", "0.168"},
|
||||
{"Treynor Ratio", "1.106"},
|
||||
{"Total Fees", "$59.00"},
|
||||
{"Estimated Strategy Capacity", "$13000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.077"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "4.656"},
|
||||
{"Return Over Maximum Drawdown", "51.751"},
|
||||
{"Portfolio Turnover", "0.081"},
|
||||
{"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", "74d06b3d2605e1c7796284fd8835b3a5"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -100,22 +100,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "54.832%"},
|
||||
{"Compounding Annual Return", "0.562%"},
|
||||
{"Drawdown", "3.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.561%"},
|
||||
{"Sharpe Ratio", "16.177"},
|
||||
{"Net Profit", "0.007%"},
|
||||
{"Sharpe Ratio", "7.5"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "2.48"},
|
||||
{"Beta", "-1.387"},
|
||||
{"Annual Standard Deviation", "0.063"},
|
||||
{"Annual Variance", "0.004"},
|
||||
{"Information Ratio", "-0.235"},
|
||||
{"Tracking Error", "0.109"},
|
||||
{"Treynor Ratio", "-0.738"},
|
||||
{"Alpha", "0.036"},
|
||||
{"Beta", "-0.026"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-22.218"},
|
||||
{"Tracking Error", "0.047"},
|
||||
{"Treynor Ratio", "-0.342"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$4200000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "63d0336c6fd05ac54aaec6a4af623f05"}
|
||||
{"OrderListHash", "16316e5491987b323d8c9f0ff87b20ee"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,30 +491,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "8"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "91.903%"},
|
||||
{"Compounding Annual Return", "91.836%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "0.837%"},
|
||||
{"Sharpe Ratio", "12.937"},
|
||||
{"Probabilistic Sharpe Ratio", "99.060%"},
|
||||
{"Net Profit", "0.836%"},
|
||||
{"Sharpe Ratio", "12.924"},
|
||||
{"Probabilistic Sharpe Ratio", "99.044%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.248"},
|
||||
{"Beta", "0.229"},
|
||||
{"Alpha", "0.247"},
|
||||
{"Beta", "0.23"},
|
||||
{"Annual Standard Deviation", "0.054"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-7.423"},
|
||||
{"Information Ratio", "-7.426"},
|
||||
{"Tracking Error", "0.172"},
|
||||
{"Treynor Ratio", "3.062"},
|
||||
{"Treynor Ratio", "3.059"},
|
||||
{"Total Fees", "$8.00"},
|
||||
{"Estimated Strategy Capacity", "$48000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.093"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "152.568"},
|
||||
{"Return Over Maximum Drawdown", "1192.069"},
|
||||
{"Sortino Ratio", "150.447"},
|
||||
{"Return Over Maximum Drawdown", "1180.131"},
|
||||
{"Portfolio Turnover", "0.093"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -529,7 +529,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4c82126e7ba029738d8bd2ad39cc5ed9"}
|
||||
{"OrderListHash", "11d64052951ca2d3abf586c88d41a97a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,22 +65,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0.82%"},
|
||||
{"Average Loss", "-0.39%"},
|
||||
{"Compounding Annual Return", "47.333%"},
|
||||
{"Compounding Annual Return", "47.234%"},
|
||||
{"Drawdown", "0.700%"},
|
||||
{"Expectancy", "0.548"},
|
||||
{"Net Profit", "0.497%"},
|
||||
{"Sharpe Ratio", "10.786"},
|
||||
{"Probabilistic Sharpe Ratio", "86.350%"},
|
||||
{"Net Profit", "0.496%"},
|
||||
{"Sharpe Ratio", "10.749"},
|
||||
{"Probabilistic Sharpe Ratio", "86.164%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "2.10"},
|
||||
{"Alpha", "0.236"},
|
||||
{"Alpha", "0.235"},
|
||||
{"Beta", "0.066"},
|
||||
{"Annual Standard Deviation", "0.034"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "-7.693"},
|
||||
{"Information Ratio", "-7.696"},
|
||||
{"Tracking Error", "0.21"},
|
||||
{"Treynor Ratio", "5.545"},
|
||||
{"Treynor Ratio", "5.536"},
|
||||
{"Total Fees", "$25.78"},
|
||||
{"Estimated Strategy Capacity", "$1900000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
@@ -103,7 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "7a83246974169eed049b81e82b194b9f"}
|
||||
{"OrderListHash", "b68340c2b8ff6803f585623f720de18a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2015, 1, 1);
|
||||
SetEndDate(2018, 1, 1);
|
||||
|
||||
@@ -121,15 +125,15 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "28"},
|
||||
{"Average Win", "0.78%"},
|
||||
{"Total Trades", "34"},
|
||||
{"Average Win", "0.60%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "18.497%"},
|
||||
{"Compounding Annual Return", "18.537%"},
|
||||
{"Drawdown", "9.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "66.312%"},
|
||||
{"Sharpe Ratio", "1.751"},
|
||||
{"Probabilistic Sharpe Ratio", "87.887%"},
|
||||
{"Net Profit", "66.479%"},
|
||||
{"Sharpe Ratio", "1.755"},
|
||||
{"Probabilistic Sharpe Ratio", "88.014%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -137,17 +141,17 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "-0.051"},
|
||||
{"Annual Standard Deviation", "0.088"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "0.374"},
|
||||
{"Information Ratio", "0.377"},
|
||||
{"Tracking Error", "0.147"},
|
||||
{"Treynor Ratio", "-3.026"},
|
||||
{"Total Fees", "$42.31"},
|
||||
{"Estimated Strategy Capacity", "$730000.00"},
|
||||
{"Treynor Ratio", "-3.035"},
|
||||
{"Total Fees", "$48.31"},
|
||||
{"Estimated Strategy Capacity", "$320000.00"},
|
||||
{"Lowest Capacity Asset", "BNO UN3IMQ2JU1YD"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "2.123"},
|
||||
{"Return Over Maximum Drawdown", "1.998"},
|
||||
{"Sortino Ratio", "2.128"},
|
||||
{"Return Over Maximum Drawdown", "2.002"},
|
||||
{"Portfolio Turnover", "0.001"},
|
||||
{"Total Insights Generated", "5327"},
|
||||
{"Total Insights Closed", "5320"},
|
||||
@@ -162,7 +166,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "2192f9d1cafbdfda4dfd63655ffba819"}
|
||||
{"OrderListHash", "a0076f3bae4c6f0be8805df052020fb9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2015, 1, 1);
|
||||
SetEndDate(2017, 1, 1);
|
||||
|
||||
@@ -79,33 +83,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "324"},
|
||||
{"Total Trades", "362"},
|
||||
{"Average Win", "0.06%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "11.449%"},
|
||||
{"Drawdown", "18.300%"},
|
||||
{"Expectancy", "1.324"},
|
||||
{"Net Profit", "24.208%"},
|
||||
{"Sharpe Ratio", "0.691"},
|
||||
{"Probabilistic Sharpe Ratio", "29.687%"},
|
||||
{"Loss Rate", "23%"},
|
||||
{"Win Rate", "77%"},
|
||||
{"Profit-Loss Ratio", "2.02"},
|
||||
{"Compounding Annual Return", "11.407%"},
|
||||
{"Drawdown", "18.200%"},
|
||||
{"Expectancy", "1.300"},
|
||||
{"Net Profit", "24.116%"},
|
||||
{"Sharpe Ratio", "0.689"},
|
||||
{"Probabilistic Sharpe Ratio", "29.629%"},
|
||||
{"Loss Rate", "24%"},
|
||||
{"Win Rate", "76%"},
|
||||
{"Profit-Loss Ratio", "2.01"},
|
||||
{"Alpha", "0.106"},
|
||||
{"Beta", "0.006"},
|
||||
{"Annual Standard Deviation", "0.154"},
|
||||
{"Annual Variance", "0.024"},
|
||||
{"Information Ratio", "0.22"},
|
||||
{"Information Ratio", "0.219"},
|
||||
{"Tracking Error", "0.201"},
|
||||
{"Treynor Ratio", "16.657"},
|
||||
{"Total Fees", "$328.83"},
|
||||
{"Estimated Strategy Capacity", "$83000000.00"},
|
||||
{"Treynor Ratio", "16.79"},
|
||||
{"Total Fees", "$366.83"},
|
||||
{"Estimated Strategy Capacity", "$40000000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "0.95"},
|
||||
{"Return Over Maximum Drawdown", "0.626"},
|
||||
{"Sortino Ratio", "0.949"},
|
||||
{"Return Over Maximum Drawdown", "0.625"},
|
||||
{"Portfolio Turnover", "0.003"},
|
||||
{"Total Insights Generated", "2028"},
|
||||
{"Total Insights Closed", "2024"},
|
||||
@@ -120,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f3f5d85ceb98efcbf8f5e78f0a980944"}
|
||||
{"OrderListHash", "20d5c49aff16826f5a7fba8f3b9c23f2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2015, 1, 1);
|
||||
SetEndDate(2017, 1, 1);
|
||||
|
||||
@@ -87,33 +91,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "86"},
|
||||
{"Average Win", "0.15%"},
|
||||
{"Total Trades", "91"},
|
||||
{"Average Win", "0.14%"},
|
||||
{"Average Loss", "-0.04%"},
|
||||
{"Compounding Annual Return", "9.824%"},
|
||||
{"Drawdown", "18.200%"},
|
||||
{"Expectancy", "2.583"},
|
||||
{"Net Profit", "20.613%"},
|
||||
{"Compounding Annual Return", "9.810%"},
|
||||
{"Drawdown", "18.100%"},
|
||||
{"Expectancy", "2.562"},
|
||||
{"Net Profit", "20.583%"},
|
||||
{"Sharpe Ratio", "0.602"},
|
||||
{"Probabilistic Sharpe Ratio", "25.485%"},
|
||||
{"Loss Rate", "19%"},
|
||||
{"Win Rate", "81%"},
|
||||
{"Profit-Loss Ratio", "3.45"},
|
||||
{"Probabilistic Sharpe Ratio", "25.490%"},
|
||||
{"Loss Rate", "21%"},
|
||||
{"Win Rate", "79%"},
|
||||
{"Profit-Loss Ratio", "3.48"},
|
||||
{"Alpha", "0.093"},
|
||||
{"Beta", "0.011"},
|
||||
{"Annual Standard Deviation", "0.155"},
|
||||
{"Annual Variance", "0.024"},
|
||||
{"Information Ratio", "0.155"},
|
||||
{"Tracking Error", "0.202"},
|
||||
{"Treynor Ratio", "8.214"},
|
||||
{"Total Fees", "$90.57"},
|
||||
{"Information Ratio", "0.154"},
|
||||
{"Tracking Error", "0.201"},
|
||||
{"Treynor Ratio", "8.293"},
|
||||
{"Total Fees", "$95.57"},
|
||||
{"Estimated Strategy Capacity", "$82000000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "0.814"},
|
||||
{"Return Over Maximum Drawdown", "0.54"},
|
||||
{"Sortino Ratio", "0.815"},
|
||||
{"Return Over Maximum Drawdown", "0.541"},
|
||||
{"Portfolio Turnover", "0.002"},
|
||||
{"Total Insights Generated", "2028"},
|
||||
{"Total Insights Closed", "2024"},
|
||||
@@ -128,7 +132,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "af0b8590dfbd0c3f09cc22a04a0816e2"}
|
||||
{"OrderListHash", "6d2a084c752e24c6d46866dba64f8d88"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<DebugType>portable</DebugType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.4" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.6" />
|
||||
<PackageReference Include="Accord" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Fuzzy" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.MachineLearning" Version="3.6.0" />
|
||||
|
||||
@@ -85,33 +85,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1590"},
|
||||
{"Total Trades", "1589"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-1.167%"},
|
||||
{"Compounding Annual Return", "-1.158%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "-0.974"},
|
||||
{"Expectancy", "-0.989"},
|
||||
{"Net Profit", "-0.016%"},
|
||||
{"Sharpe Ratio", "-8.696"},
|
||||
{"Probabilistic Sharpe Ratio", "0.002%"},
|
||||
{"Loss Rate", "99%"},
|
||||
{"Win Rate", "1%"},
|
||||
{"Profit-Loss Ratio", "3.17"},
|
||||
{"Sharpe Ratio", "-8.353"},
|
||||
{"Probabilistic Sharpe Ratio", "0.025%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "1.81"},
|
||||
{"Alpha", "-0.006"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-7.193"},
|
||||
{"Information Ratio", "-7.192"},
|
||||
{"Tracking Error", "0.195"},
|
||||
{"Treynor Ratio", "8.201"},
|
||||
{"Total Fees", "$1590.00"},
|
||||
{"Treynor Ratio", "8.322"},
|
||||
{"Total Fees", "$1589.00"},
|
||||
{"Estimated Strategy Capacity", "$67000000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-14.995"},
|
||||
{"Return Over Maximum Drawdown", "-72.578"},
|
||||
{"Sortino Ratio", "-15.241"},
|
||||
{"Return Over Maximum Drawdown", "-72.582"},
|
||||
{"Portfolio Turnover", "0.018"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -126,7 +126,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "98388f6232375a64b6858a6e3e82c321"}
|
||||
{"OrderListHash", "b500cbcfb4acc2e3b07a6ee1b7f41d1a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
@@ -27,7 +26,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Regression algorithm ensures that added data matches expectations
|
||||
/// </summary>
|
||||
public class CustomDataAddDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomDataIconicTypesAddDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _googlEquity;
|
||||
|
||||
@@ -38,17 +37,17 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(100000);
|
||||
|
||||
var twxEquity = AddEquity("TWX", Resolution.Daily).Symbol;
|
||||
var customTwxSymbol = AddData<SECReport8K>(twxEquity, Resolution.Daily).Symbol;
|
||||
var customTwxSymbol = AddData<LinkedData>(twxEquity, Resolution.Daily).Symbol;
|
||||
|
||||
_googlEquity = AddEquity("GOOGL", Resolution.Daily).Symbol;
|
||||
var customGooglSymbol = AddData<SECReport10K>("GOOGL", Resolution.Daily).Symbol;
|
||||
var customGooglSymbol = AddData<LinkedData>("GOOGL", Resolution.Daily).Symbol;
|
||||
|
||||
var usTreasury = AddData<USTreasuryYieldCurveRate>("GOOGL", Resolution.Daily).Symbol;
|
||||
var usTreasuryUnderlyingEquity = QuantConnect.Symbol.Create("MSFT", SecurityType.Equity, Market.USA);
|
||||
var usTreasuryUnderlying = AddData<USTreasuryYieldCurveRate>(usTreasuryUnderlyingEquity, Resolution.Daily).Symbol;
|
||||
var unlinkedDataSymbol = AddData<UnlinkedData>("GOOGL", Resolution.Daily).Symbol;
|
||||
var unlinkedDataSymbolUnderlyingEquity = QuantConnect.Symbol.Create("MSFT", SecurityType.Equity, Market.USA);
|
||||
var unlinkedDataSymbolUnderlying = AddData<UnlinkedData>(unlinkedDataSymbolUnderlyingEquity, Resolution.Daily).Symbol;
|
||||
|
||||
var optionSymbol = AddOption("TWX", Resolution.Minute).Symbol;
|
||||
var customOptionSymbol = AddData<SECReport10K>(optionSymbol, Resolution.Daily).Symbol;
|
||||
var customOptionSymbol = AddData<LinkedData>(optionSymbol, Resolution.Daily).Symbol;
|
||||
|
||||
if (customTwxSymbol.Underlying != twxEquity)
|
||||
{
|
||||
@@ -58,17 +57,17 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
throw new Exception($"Underlying symbol for {customGooglSymbol} is not equal to GOOGL equity. Expected {_googlEquity} got {customGooglSymbol.Underlying}");
|
||||
}
|
||||
if (usTreasury.HasUnderlying)
|
||||
if (unlinkedDataSymbol.HasUnderlying)
|
||||
{
|
||||
throw new Exception($"US Treasury yield curve (no underlying) has underlying when it shouldn't. Found {usTreasury.Underlying}");
|
||||
throw new Exception($"Unlinked data type (no underlying) has underlying when it shouldn't. Found {unlinkedDataSymbol.Underlying}");
|
||||
}
|
||||
if (!usTreasuryUnderlying.HasUnderlying)
|
||||
if (!unlinkedDataSymbolUnderlying.HasUnderlying)
|
||||
{
|
||||
throw new Exception("US Treasury yield curve (with underlying) has no underlying Symbol even though we added with Symbol");
|
||||
throw new Exception("Unlinked data type (with underlying) has no underlying Symbol even though we added with Symbol");
|
||||
}
|
||||
if (usTreasuryUnderlying.Underlying != usTreasuryUnderlyingEquity)
|
||||
if (unlinkedDataSymbolUnderlying.Underlying != unlinkedDataSymbolUnderlyingEquity)
|
||||
{
|
||||
throw new Exception($"US Treasury yield curve underlying does not equal equity Symbol added. Expected {usTreasuryUnderlyingEquity} got {usTreasuryUnderlying.Underlying}");
|
||||
throw new Exception($"Unlinked data type underlying does not equal equity Symbol added. Expected {unlinkedDataSymbolUnderlyingEquity} got {unlinkedDataSymbolUnderlying.Underlying}");
|
||||
}
|
||||
if (customOptionSymbol.Underlying != optionSymbol)
|
||||
{
|
||||
@@ -77,13 +76,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
try
|
||||
{
|
||||
var customDataNoCache = AddData<SECReport10Q>("AAPL", Resolution.Daily);
|
||||
var customDataNoCache = AddData<LinkedData>("AAPL", Resolution.Daily);
|
||||
throw new Exception("AAPL was found in the SymbolCache, though it should be missing");
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// This is exactly what we wanted. AAPL shouldn't have been found in the SymbolCache, and because
|
||||
// SECReport10Q is a mappable type, we threw
|
||||
// LinkedData is mappable, we threw
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.Custom;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Data.Custom.Fred;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
using QuantConnect.Data.Custom.USEnergy;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
@@ -31,7 +25,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// This regression algorithm tests the performance related GH issue 3772
|
||||
/// </summary>
|
||||
public class DefaultResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomDataIconicTypesDefaultResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -41,14 +35,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
var types = new[]
|
||||
{
|
||||
typeof(SECReport8K),
|
||||
typeof(SECReport10K),
|
||||
typeof(SECReport10Q),
|
||||
typeof(USTreasuryYieldCurveRate),
|
||||
typeof(USEnergy),
|
||||
typeof(CBOE),
|
||||
typeof(TiingoPrice),
|
||||
typeof(Fred)
|
||||
typeof(UnlinkedDataTradeBar),
|
||||
typeof(DailyUnlinkedData),
|
||||
typeof(DailyLinkedData)
|
||||
};
|
||||
|
||||
foreach (var type in types)
|
||||
@@ -73,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
var security = AddData<USEnergyAPI>(spy);
|
||||
var security = AddData<HourlyDefaultResolutionUnlinkedData>(spy);
|
||||
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(security.Symbol)
|
||||
.Any(config => config.Resolution != Resolution.Hour))
|
||||
{
|
||||
@@ -82,7 +71,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
AddOption("AAPL", Resolution.Daily);
|
||||
throw new Exception("Was expecting an ArgumentException to be thrown");
|
||||
}
|
||||
@@ -101,6 +89,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Quit();
|
||||
}
|
||||
|
||||
private class DailyUnlinkedData : UnlinkedData
|
||||
{
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
|
||||
private class DailyLinkedData : LinkedData
|
||||
{
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return DailyResolution;
|
||||
}
|
||||
}
|
||||
|
||||
private class HourlyDefaultResolutionUnlinkedData : UnlinkedData
|
||||
{
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Hour;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@@ -18,7 +18,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="regression test" />d
|
||||
public class CustomDataAddDataCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomDataLinkedIconicTypeAddDataCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<Symbol> _customSymbols = new List<Symbol>();
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
_customSymbols.Add(AddData<SECReport8K>(symbol, Resolution.Daily).Symbol);
|
||||
_customSymbols.Add(AddData<LinkedData>(symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
@@ -121,10 +121,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Fees", "$14.45"},
|
||||
{"Estimated Strategy Capacity", "$370000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-7.238"},
|
||||
{"Sortino Ratio", "-6.201"},
|
||||
{"Return Over Maximum Drawdown", "-16.848"},
|
||||
{"Portfolio Turnover", "0.038"},
|
||||
{"Total Insights Generated", "0"},
|
||||
@@ -18,7 +18,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="regression test" />
|
||||
public class CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomDataLinkedIconicTypeAddDataOnSecuritiesChangedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<Symbol> _customSymbols = new List<Symbol>();
|
||||
|
||||
@@ -85,7 +85,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
_customSymbols.Clear();
|
||||
iterated = true;
|
||||
}
|
||||
_customSymbols.Add(AddData<SECReport8K>(added.Symbol, Resolution.Daily).Symbol);
|
||||
_customSymbols.Add(AddData<LinkedData>(added.Symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,10 +126,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Fees", "$14.45"},
|
||||
{"Estimated Strategy Capacity", "$370000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-7.238"},
|
||||
{"Sortino Ratio", "-6.201"},
|
||||
{"Return Over Maximum Drawdown", "-16.848"},
|
||||
{"Portfolio Turnover", "0.038"},
|
||||
{"Total Insights Generated", "0"},
|
||||
@@ -17,7 +17,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
@@ -26,14 +26,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Tests the consolidation of custom data with random data
|
||||
/// </summary>
|
||||
public class CBOECustomDataConsolidationRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomDataUnlinkedTradeBarIconicTypeConsolidationRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _vix;
|
||||
private BollingerBands _bb;
|
||||
private bool _invested;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the algorithm with fake VIX data
|
||||
/// Initializes the algorithm with fake "VIX" data
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Incrementally updating data
|
||||
/// </summary>
|
||||
private class IncrementallyGeneratedCustomData : CBOE
|
||||
private class IncrementallyGeneratedCustomData : UnlinkedDataTradeBar
|
||||
{
|
||||
private const decimal _start = 10.01m;
|
||||
private static decimal _step;
|
||||
@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <returns>Incremental BaseData instance</returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var vix = new CBOE();
|
||||
var unlinkedBar = new UnlinkedDataTradeBar();
|
||||
_step += 0.10m;
|
||||
var open = _start + _step;
|
||||
var close = _start + _step + 0.02m;
|
||||
@@ -111,8 +111,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Symbol = new Symbol(
|
||||
SecurityIdentifier.GenerateBase(typeof(IncrementallyGeneratedCustomData), "VIX", Market.USA, false),
|
||||
"VIX"),
|
||||
Period = vix.Period,
|
||||
DataType = vix.DataType
|
||||
Period = unlinkedBar.Period,
|
||||
DataType = unlinkedBar.DataType
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -138,22 +138,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0.029%"},
|
||||
{"Compounding Annual Return", "28.248%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.000%"},
|
||||
{"Sharpe Ratio", "28.4"},
|
||||
{"Probabilistic Sharpe Ratio", "88.597%"},
|
||||
{"Net Profit", "0.330%"},
|
||||
{"Sharpe Ratio", "30.713"},
|
||||
{"Probabilistic Sharpe Ratio", "88.947%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Alpha", "0.152"},
|
||||
{"Beta", "0.021"},
|
||||
{"Annual Standard Deviation", "0.006"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-7.163"},
|
||||
{"Tracking Error", "0.195"},
|
||||
{"Treynor Ratio", "8.093"},
|
||||
{"Information Ratio", "-6.368"},
|
||||
{"Tracking Error", "0.191"},
|
||||
{"Treynor Ratio", "8.726"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "VIX.IncrementallyGeneratedCustomData 2S"},
|
||||
@@ -176,7 +176,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "918912ee4f64cd0290f3d58deca02713"}
|
||||
{"OrderListHash", "27b250ae26a92f52d39302b8c299726e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the delisting of the composite Symbol (ETF symbol) and the removal of
|
||||
/// the universe and the symbol from the algorithm.
|
||||
/// </summary>
|
||||
public class ETFConstituentUniverseCompositeDelistingRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
protected virtual bool AddETFSubscription { get; set; } = true;
|
||||
|
||||
private Symbol _gdvd;
|
||||
private Symbol _aapl;
|
||||
private DateTime _delistingDate;
|
||||
private int _universeSymbolCount;
|
||||
private bool _universeAdded;
|
||||
private bool _universeRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 12, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
|
||||
_delistingDate = new DateTime(2021, 1, 21);
|
||||
|
||||
_aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
|
||||
if (AddETFSubscription)
|
||||
{
|
||||
Log("Adding ETF constituent universe Symbol by using AddEquity(...)");
|
||||
_gdvd = AddEquity("GDVD", Resolution.Hour).Symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Adding ETF constituent universe Symbol by using Symbol.Create(...)");
|
||||
_gdvd = QuantConnect.Symbol.Create("GDVD", SecurityType.Equity, Market.USA);
|
||||
}
|
||||
|
||||
AddUniverse(Universe.ETF(_gdvd, universeFilterFunc: FilterETFs));
|
||||
}
|
||||
|
||||
private IEnumerable<Symbol> FilterETFs(IEnumerable<ETFConstituentData> constituents)
|
||||
{
|
||||
if (UtcTime.Date > _delistingDate)
|
||||
{
|
||||
throw new Exception($"Performing constituent universe selection on {UtcTime:yyyy-MM-dd HH:mm:ss.fff} after composite ETF has been delisted");
|
||||
}
|
||||
|
||||
var constituentSymbols = constituents.Select(x => x.Symbol).ToList();
|
||||
_universeSymbolCount = constituentSymbols.Count;
|
||||
|
||||
return constituentSymbols;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (UtcTime.Date > _delistingDate && data.Keys.Any(x => x != _aapl))
|
||||
{
|
||||
throw new Exception($"Received unexpected slice in OnData(...) after universe was deselected");
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_aapl, 0.5m);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
if (changes.AddedSecurities.Count != 0 && UtcTime > _delistingDate)
|
||||
{
|
||||
throw new Exception("New securities added after ETF constituents were delisted");
|
||||
}
|
||||
|
||||
_universeAdded |= changes.AddedSecurities.Count >= _universeSymbolCount;
|
||||
// Subtract 1 from universe Symbol count for AAPL, since it was manually added to the algorithm
|
||||
_universeRemoved |= changes.RemovedSecurities.Count == _universeSymbolCount - 1 && UtcTime.Date >= _delistingDate && UtcTime.Date < EndDate;
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_universeAdded)
|
||||
{
|
||||
throw new Exception("ETF constituent universe was never added to the algorithm");
|
||||
}
|
||||
if (!_universeRemoved)
|
||||
{
|
||||
throw new Exception("ETF constituent universe was not removed from the algorithm after delisting");
|
||||
}
|
||||
if (ActiveSecurities.Count > 2)
|
||||
{
|
||||
throw new Exception($"Expected less than 2 securities after algorithm ended, found {Securities.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "26.315%"},
|
||||
{"Drawdown", "5.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "3.893%"},
|
||||
{"Sharpe Ratio", "1.652"},
|
||||
{"Probabilistic Sharpe Ratio", "57.203%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.203"},
|
||||
{"Beta", "0.696"},
|
||||
{"Annual Standard Deviation", "0.169"},
|
||||
{"Annual Variance", "0.029"},
|
||||
{"Information Ratio", "1.139"},
|
||||
{"Tracking Error", "0.149"},
|
||||
{"Treynor Ratio", "0.402"},
|
||||
{"Total Fees", "$2.04"},
|
||||
{"Estimated Strategy Capacity", "$260000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.011"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "5.155"},
|
||||
{"Return Over Maximum Drawdown", "9.927"},
|
||||
{"Portfolio Turnover", "0.012"},
|
||||
{"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", "49d511dbd5e31d6c25afda0f55aa28c2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
/*
|
||||
* 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");
|
||||
*
|
||||
* 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.
|
||||
@@ -14,21 +14,21 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.IconicTypes;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Data.Custom.SEC
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies format for parsing <see cref="DateTime"/> values from SEC data
|
||||
/// Tests the delisting of the composite Symbol (ETF symbol) and the removal of
|
||||
/// the universe and the symbol from the algorithm, without adding a subscription via AddEquity
|
||||
/// </summary>
|
||||
public class SECReportDateTimeConverter : IsoDateTimeConverter
|
||||
public class ETFConstituentUniverseCompositeDelistingRegressionAlgorithmNoAddEquityETF : ETFConstituentUniverseCompositeDelistingRegressionAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor, initializes DateTime format
|
||||
/// </summary>
|
||||
public SECReportDateTimeConverter()
|
||||
{
|
||||
DateTimeFormat = "yyyyMMdd HH:mm:ss";
|
||||
}
|
||||
protected override bool AddETFSubscription { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* 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.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests a custom filter function when creating an ETF constituents universe for SPY
|
||||
/// </summary>
|
||||
public class ETFConstituentUniverseFilterFunctionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Dictionary<Symbol, ETFConstituentData> _etfConstituentData = new Dictionary<Symbol, ETFConstituentData>();
|
||||
|
||||
private Symbol _aapl;
|
||||
private Symbol _spy;
|
||||
private bool _filtered;
|
||||
private bool _securitiesChanged;
|
||||
private bool _receivedData;
|
||||
private bool _etfRebalanced;
|
||||
private int _rebalanceCount;
|
||||
private int _rebalanceAssetCount;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 12, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
|
||||
AddUniverse(Universe.ETF(_spy, universeFilterFunc: FilterETFs));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters ETFs, performing some sanity checks
|
||||
/// </summary>
|
||||
/// <param name="constituents">Constituents of the ETF universe added above</param>
|
||||
/// <returns>Constituent Symbols to add to algorithm</returns>
|
||||
/// <exception cref="ArgumentException">Constituents collection was not structured as expected</exception>
|
||||
private IEnumerable<Symbol> FilterETFs(IEnumerable<ETFConstituentData> constituents)
|
||||
{
|
||||
var constituentsData = constituents.ToList();
|
||||
_etfConstituentData = constituentsData.ToDictionary(x => x.Symbol, x => x);
|
||||
|
||||
var constituentsSymbols = constituentsData.Select(x => x.Symbol).ToList();
|
||||
if (constituentsData.Count == 0)
|
||||
{
|
||||
throw new ArgumentException($"Constituents collection is empty on {UtcTime:yyyy-MM-dd HH:mm:ss.fff}");
|
||||
}
|
||||
if (!constituentsSymbols.Contains(_aapl))
|
||||
{
|
||||
throw new ArgumentException("AAPL is not in the constituents data provided to the algorithm");
|
||||
}
|
||||
|
||||
var aaplData = constituentsData.Single(x => x.Symbol == _aapl);
|
||||
if (aaplData.Weight == 0m)
|
||||
{
|
||||
throw new ArgumentException("AAPL weight is expected to be a non-zero value");
|
||||
}
|
||||
|
||||
_filtered = true;
|
||||
_etfRebalanced = true;
|
||||
|
||||
return constituentsSymbols;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!_filtered && data.Bars.Count != 0 && data.Bars.ContainsKey(_aapl))
|
||||
{
|
||||
throw new Exception("AAPL TradeBar data added to algorithm before constituent universe selection took place");
|
||||
}
|
||||
|
||||
if (data.Bars.Count == 1 && data.Bars.ContainsKey(_spy))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.Bars.Count != 0 && !data.Bars.ContainsKey(_aapl))
|
||||
{
|
||||
throw new Exception($"Expected AAPL TradeBar data in OnData on {UtcTime:yyyy-MM-dd HH:mm:ss}");
|
||||
}
|
||||
|
||||
_receivedData = true;
|
||||
// If the ETF hasn't changed its weights, then let's not update our holdings
|
||||
if (!_etfRebalanced)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var bar in data.Bars.Values)
|
||||
{
|
||||
if (_etfConstituentData.TryGetValue(bar.Symbol, out var constituentData) &&
|
||||
constituentData.Weight != null &&
|
||||
constituentData.Weight >= 0.0001m)
|
||||
{
|
||||
// If the weight of the constituent is less than 1%, then it will be set to 1%
|
||||
// If the weight of the constituent exceeds more than 5%, then it will be capped to 5%
|
||||
// Otherwise, if the weight falls in between, then we use that value.
|
||||
var boundedWeight = Math.Max(0.01m, Math.Min(constituentData.Weight.Value, 0.05m));
|
||||
SetHoldings(bar.Symbol, boundedWeight);
|
||||
|
||||
if (_etfRebalanced)
|
||||
{
|
||||
_rebalanceCount++;
|
||||
}
|
||||
_etfRebalanced = false;
|
||||
_rebalanceAssetCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if new securities have been added to the algorithm after universe selection has occurred
|
||||
/// </summary>
|
||||
/// <param name="changes">Security changes</param>
|
||||
/// <exception cref="ArgumentException">Expected number of stocks were not added to the algorithm</exception>
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
if (_filtered && !_securitiesChanged && changes.AddedSecurities.Count < 500)
|
||||
{
|
||||
throw new ArgumentException($"Added SPY S&P 500 ETF to algorithm, but less than 500 equities were loaded (added {changes.AddedSecurities.Count} securities)");
|
||||
}
|
||||
|
||||
_securitiesChanged = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that all expected events were triggered by the end of the algorithm
|
||||
/// </summary>
|
||||
/// <exception cref="Exception">An expected event didn't happen</exception>
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_rebalanceCount != 1)
|
||||
{
|
||||
throw new Exception($"Expected 1 rebalance, instead rebalanced: {_rebalanceCount}");
|
||||
}
|
||||
if (_rebalanceAssetCount != 4)
|
||||
{
|
||||
throw new Exception($"Invested in {_rebalanceAssetCount} assets (expected 4)");
|
||||
}
|
||||
if (!_filtered)
|
||||
{
|
||||
throw new Exception("Universe selection was never triggered");
|
||||
}
|
||||
if (!_securitiesChanged)
|
||||
{
|
||||
throw new Exception("Security changes never propagated to the algorithm");
|
||||
}
|
||||
if (!_receivedData)
|
||||
{
|
||||
throw new Exception("Data was never loaded for the S&P 500 constituent AAPL");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "2.118%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.343%"},
|
||||
{"Sharpe Ratio", "1.251"},
|
||||
{"Probabilistic Sharpe Ratio", "53.741%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.011"},
|
||||
{"Beta", "0.098"},
|
||||
{"Annual Standard Deviation", "0.018"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-0.754"},
|
||||
{"Tracking Error", "0.116"},
|
||||
{"Treynor Ratio", "0.223"},
|
||||
{"Total Fees", "$4.00"},
|
||||
{"Estimated Strategy Capacity", "$100000000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "4.028"},
|
||||
{"Return Over Maximum Drawdown", "7.694"},
|
||||
{"Portfolio Turnover", "0.001"},
|
||||
{"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", "12bc2f33ccf788ffb2c0a57a68199485"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* 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.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests ETF constituents universe selection with the algorithm framework models (Alpha, PortfolioConstruction, Execution)
|
||||
/// </summary>
|
||||
public class ETFConstituentUniverseFrameworkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<ETFConstituentData> ConstituentData = new List<ETFConstituentData>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the algorithm, setting up the framework classes and ETF constituent universe settings
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 12, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
|
||||
SetAlpha(new ETFConstituentAlphaModel());
|
||||
SetPortfolioConstruction(new ETFConstituentPortfolioModel());
|
||||
SetExecution(new ETFConstituentExecutionModel());
|
||||
|
||||
var spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
AddUniverse(Universe.ETF(spy, UniverseSettings, FilterETFConstituents));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters ETF constituents
|
||||
/// </summary>
|
||||
/// <param name="constituents">ETF constituents</param>
|
||||
/// <returns>ETF constituent Symbols that we want to include in the algorithm</returns>
|
||||
public IEnumerable<Symbol> FilterETFConstituents(IEnumerable<ETFConstituentData> constituents)
|
||||
{
|
||||
var constituentData = constituents
|
||||
.Where(x => (x.Weight ?? 0m) >= 0.001m)
|
||||
.ToList();
|
||||
|
||||
ConstituentData = constituentData;
|
||||
|
||||
return constituentData
|
||||
.Select(x => x.Symbol)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// no-op for performance
|
||||
/// </summary>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alpha model for ETF constituents, where we generate insights based on the weighting
|
||||
/// of the ETF constituent
|
||||
/// </summary>
|
||||
private class ETFConstituentAlphaModel : IAlphaModel
|
||||
{
|
||||
public void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new insights based on constituent data and their weighting
|
||||
/// in their respective ETF
|
||||
/// </summary>
|
||||
public IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
|
||||
{
|
||||
var algo = (ETFConstituentUniverseFrameworkRegressionAlgorithm) algorithm;
|
||||
|
||||
foreach (var constituent in algo.ConstituentData)
|
||||
{
|
||||
if (!data.Bars.ContainsKey(constituent.Symbol) &&
|
||||
!data.QuoteBars.ContainsKey(constituent.Symbol))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var insightDirection = constituent.Weight != null && constituent.Weight >= 0.01m
|
||||
? InsightDirection.Up
|
||||
: InsightDirection.Down;
|
||||
|
||||
yield return new Insight(
|
||||
algorithm.UtcTime,
|
||||
constituent.Symbol,
|
||||
TimeSpan.FromDays(1),
|
||||
InsightType.Price,
|
||||
insightDirection,
|
||||
1 * (double)insightDirection,
|
||||
1.0,
|
||||
weight: (double)(constituent.Weight ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates targets for ETF constituents, which will be set to the weighting
|
||||
/// of the constituent in their respective ETF
|
||||
/// </summary>
|
||||
private class ETFConstituentPortfolioModel : IPortfolioConstructionModel
|
||||
{
|
||||
private bool _hasAdded;
|
||||
|
||||
/// <summary>
|
||||
/// Securities changed, detects if we've got new additions to the universe
|
||||
/// so that we don't try to trade every loop
|
||||
/// </summary>
|
||||
public void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
|
||||
{
|
||||
_hasAdded = changes.AddedSecurities.Count != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates portfolio targets based on the insights provided to us by the alpha model.
|
||||
/// Emits portfolio targets setting the quantity to the weight of the constituent
|
||||
/// in its respective ETF.
|
||||
/// </summary>
|
||||
public IEnumerable<IPortfolioTarget> CreateTargets(QCAlgorithm algorithm, Insight[] insights)
|
||||
{
|
||||
if (!_hasAdded)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var insight in insights)
|
||||
{
|
||||
yield return new PortfolioTarget(insight.Symbol, (decimal) (insight.Weight ?? 0));
|
||||
_hasAdded = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes based on ETF constituent weighting
|
||||
/// </summary>
|
||||
private class ETFConstituentExecutionModel : IExecutionModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Liquidates if constituents have been removed from the universe
|
||||
/// </summary>
|
||||
public void OnSecuritiesChanged(QCAlgorithm algorithm, SecurityChanges changes)
|
||||
{
|
||||
foreach (var change in changes.RemovedSecurities)
|
||||
{
|
||||
algorithm.Liquidate(change.Symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates orders for constituents that attempts to add
|
||||
/// the weighting of the constituent in our portfolio. The
|
||||
/// resulting algorithm portfolio weight might not be equal
|
||||
/// to the leverage of the ETF (1x, 2x, 3x, etc.)
|
||||
/// </summary>
|
||||
public void Execute(QCAlgorithm algorithm, IPortfolioTarget[] targets)
|
||||
{
|
||||
foreach (var target in targets)
|
||||
{
|
||||
algorithm.SetHoldings(target.Symbol, target.Quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "3.225%"},
|
||||
{"Drawdown", "0.800%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.520%"},
|
||||
{"Sharpe Ratio", "1.518"},
|
||||
{"Probabilistic Sharpe Ratio", "57.759%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.022"},
|
||||
{"Beta", "0.101"},
|
||||
{"Annual Standard Deviation", "0.022"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-0.653"},
|
||||
{"Tracking Error", "0.117"},
|
||||
{"Treynor Ratio", "0.333"},
|
||||
{"Total Fees", "$4.00"},
|
||||
{"Estimated Strategy Capacity", "$1300000000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "1.528"},
|
||||
{"Kelly Criterion Probability Value", "0.091"},
|
||||
{"Sortino Ratio", "4.929"},
|
||||
{"Return Over Maximum Drawdown", "8.624"},
|
||||
{"Portfolio Turnover", "0.001"},
|
||||
{"Total Insights Generated", "1108"},
|
||||
{"Total Insights Closed", "1080"},
|
||||
{"Total Insights Analysis Completed", "1080"},
|
||||
{"Long Insight Count", "277"},
|
||||
{"Short Insight Count", "831"},
|
||||
{"Long/Short Ratio", "33.33%"},
|
||||
{"Estimated Monthly Alpha Value", "$4169774.3402"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$8322174.6207"},
|
||||
{"Mean Population Estimated Insight Value", "$7705.7172"},
|
||||
{"Mean Population Direction", "49.7222%"},
|
||||
{"Mean Population Magnitude", "49.7222%"},
|
||||
{"Rolling Averaged Population Direction", "56.0724%"},
|
||||
{"Rolling Averaged Population Magnitude", "56.0724%"},
|
||||
{"OrderListHash", "eb27e818f4a6609329a52feeb74bd554"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* 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.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the mapping of the ETF symbol that has a constituent universe attached to it and ensures
|
||||
/// that data is loaded after the mapping event takes place.
|
||||
/// </summary>
|
||||
public class ETFConstituentUniverseMappedCompositeRegressionAlgorithm: QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _aapl;
|
||||
private Symbol _qqq;
|
||||
private Dictionary<DateTime, int> _filterDateConstituentSymbolCount = new Dictionary<DateTime, int>();
|
||||
private Dictionary<DateTime, bool> _constituentDataEncountered = new Dictionary<DateTime, bool>();
|
||||
private HashSet<Symbol> _constituentSymbols = new HashSet<Symbol>();
|
||||
private bool _mappingEventOccurred;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2011, 2, 1);
|
||||
SetEndDate(2011, 4, 4);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
|
||||
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
_qqq = AddEquity("QQQ", Resolution.Daily).Symbol;
|
||||
AddUniverse(Universe.ETF(_qqq, universeFilterFunc: FilterETFs));
|
||||
}
|
||||
|
||||
private IEnumerable<Symbol> FilterETFs(IEnumerable<ETFConstituentData> constituents)
|
||||
{
|
||||
var constituentSymbols = constituents.Select(x => x.Symbol).ToHashSet();
|
||||
if (!constituentSymbols.Contains(_aapl))
|
||||
{
|
||||
throw new Exception("AAPL not found in QQQ constituents");
|
||||
}
|
||||
|
||||
_filterDateConstituentSymbolCount[UtcTime.Date] = constituentSymbols.Count;
|
||||
foreach (var symbol in constituentSymbols)
|
||||
{
|
||||
_constituentSymbols.Add(symbol);
|
||||
}
|
||||
|
||||
return constituentSymbols;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.SymbolChangedEvents.Count != 0)
|
||||
{
|
||||
foreach (var symbolChanged in data.SymbolChangedEvents.Values)
|
||||
{
|
||||
if (symbolChanged.Symbol != _qqq)
|
||||
{
|
||||
throw new Exception($"Mapped symbol is not QQQ. Instead, found: {symbolChanged.Symbol}");
|
||||
}
|
||||
if (symbolChanged.OldSymbol != "QQQQ")
|
||||
{
|
||||
throw new Exception($"Old QQQ Symbol is not QQQQ. Instead, found: {symbolChanged.OldSymbol}");
|
||||
}
|
||||
if (symbolChanged.NewSymbol != "QQQ")
|
||||
{
|
||||
throw new Exception($"New QQQ Symbol is not QQQ. Instead, found: {symbolChanged.NewSymbol}");
|
||||
}
|
||||
|
||||
_mappingEventOccurred = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.Keys.Count == 1 && data.ContainsKey(_qqq))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_constituentDataEncountered.ContainsKey(UtcTime.Date))
|
||||
{
|
||||
_constituentDataEncountered[UtcTime.Date] = false;
|
||||
}
|
||||
|
||||
if (_constituentSymbols.Intersect(data.Keys).Any())
|
||||
{
|
||||
_constituentDataEncountered[UtcTime.Date] = true;
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_aapl, 0.5m);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_filterDateConstituentSymbolCount.Count != 2)
|
||||
{
|
||||
throw new Exception($"ETF constituent filtering function was not called 2 times (actual: {_filterDateConstituentSymbolCount.Count}");
|
||||
}
|
||||
if (!_mappingEventOccurred)
|
||||
{
|
||||
throw new Exception("No mapping/SymbolChangedEvent occurred. Expected for QQQ to be mapped from QQQQ -> QQQ");
|
||||
}
|
||||
|
||||
foreach (var kvp in _filterDateConstituentSymbolCount)
|
||||
{
|
||||
if (kvp.Value < 25)
|
||||
{
|
||||
throw new Exception($"Expected 25 or more constituents in filter function on {kvp.Key:yyyy-MM-dd HH:mm:ss.fff}, found {kvp.Value}");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kvp in _constituentDataEncountered)
|
||||
{
|
||||
if (!kvp.Value)
|
||||
{
|
||||
throw new Exception($"Received data in OnData(...) but it did not contain any constituent data on {kvp.Key:yyyy-MM-dd HH:mm:ss.fff}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-9.690%"},
|
||||
{"Drawdown", "4.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-1.743%"},
|
||||
{"Sharpe Ratio", "-0.977"},
|
||||
{"Probabilistic Sharpe Ratio", "18.957%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.154"},
|
||||
{"Beta", "0.446"},
|
||||
{"Annual Standard Deviation", "0.09"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "-2.349"},
|
||||
{"Tracking Error", "0.1"},
|
||||
{"Treynor Ratio", "-0.198"},
|
||||
{"Total Fees", "$22.93"},
|
||||
{"Estimated Strategy Capacity", "$75000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.691"},
|
||||
{"Return Over Maximum Drawdown", "-2.806"},
|
||||
{"Portfolio Turnover", "0.01"},
|
||||
{"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", "50e968429008fb1c39fd577f5ebe74cf"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* 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.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm demonstrating the usage of the RSI indicator
|
||||
/// in combination with ETF constituents data to replicate the weighting
|
||||
/// of the ETF's assets in our own account.
|
||||
/// </summary>
|
||||
public class ETFConstituentUniverseRSIAlphaModelAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 12, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
|
||||
SetAlpha(new ConstituentWeightedRsiAlphaModel());
|
||||
SetPortfolioConstruction(new InsightWeightingPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
|
||||
var spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
|
||||
// We load hourly data for ETF constituents in this algorithm
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
Settings.MinimumOrderMarginPortfolioPercentage = 0.01m;
|
||||
|
||||
AddUniverse(Universe.ETF(spy, UniverseSettings, FilterETFConstituents));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filters ETF constituents and adds the resulting Symbols to the ETF constituent universe
|
||||
/// </summary>
|
||||
/// <param name="constituents">ETF constituents, i.e. the components of the ETF and their weighting</param>
|
||||
/// <returns>Symbols to add to universe</returns>
|
||||
public IEnumerable<Symbol> FilterETFConstituents(IEnumerable<ETFConstituentData> constituents)
|
||||
{
|
||||
return constituents
|
||||
.Where(x => x.Weight != null && x.Weight >= 0.001m)
|
||||
.Select(x => x.Symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Alpha model making use of the RSI indicator and ETF constituent weighting to determine
|
||||
/// which assets we should invest in and the direction of investment
|
||||
/// </summary>
|
||||
private class ConstituentWeightedRsiAlphaModel : AlphaModel
|
||||
{
|
||||
private Dictionary<Symbol, SymbolData> _rsiSymbolData = new Dictionary<Symbol, SymbolData>();
|
||||
|
||||
/// <summary>
|
||||
/// Receives new data and emits new <see cref="Insight"/> instances
|
||||
/// </summary>
|
||||
/// <param name="algorithm">Algorithm</param>
|
||||
/// <param name="data">Current data</param>
|
||||
/// <returns>Enumerable of insights for assets to invest with a specific weight</returns>
|
||||
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
|
||||
{
|
||||
// Cast first, and then access the constituents collection defined in our algorithm.
|
||||
var algoConstituents = data.Bars.Keys
|
||||
.Where(x => algorithm.Securities[x].Cache.HasData(typeof(ETFConstituentData)))
|
||||
.Select(x => algorithm.Securities[x].Cache.GetData<ETFConstituentData>())
|
||||
.ToList();
|
||||
|
||||
if (algoConstituents.Count == 0 || data.Bars.Count == 0)
|
||||
{
|
||||
// Don't do anything if we have no data we can work with
|
||||
yield break;
|
||||
}
|
||||
|
||||
var constituents = algoConstituents
|
||||
.ToDictionary(x => x.Symbol, x => x);
|
||||
|
||||
foreach (var bar in data.Bars.Values)
|
||||
{
|
||||
if (!constituents.ContainsKey(bar.Symbol))
|
||||
{
|
||||
// Dealing with a manually added equity, which in this case is SPY
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_rsiSymbolData.ContainsKey(bar.Symbol))
|
||||
{
|
||||
// First time we're initializing the RSI.
|
||||
// It won't be ready now, but it will be
|
||||
// after 7 data points.
|
||||
var constituent = constituents[bar.Symbol];
|
||||
_rsiSymbolData[bar.Symbol] = new SymbolData(bar.Symbol, algorithm, constituent, 7);
|
||||
}
|
||||
}
|
||||
|
||||
// Let's make sure all RSI indicators are ready before we emit any insights.
|
||||
var allReady = _rsiSymbolData.All(kvp => kvp.Value.Rsi.IsReady);
|
||||
if (!allReady)
|
||||
{
|
||||
// We're still warming up the RSI indicators.
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var kvp in _rsiSymbolData)
|
||||
{
|
||||
var symbol = kvp.Key;
|
||||
var symbolData = kvp.Value;
|
||||
|
||||
var averageLoss = symbolData.Rsi.AverageLoss.Current.Value;
|
||||
var averageGain = symbolData.Rsi.AverageGain.Current.Value;
|
||||
|
||||
// If we've lost more than gained, then we think it's going to go down more
|
||||
var direction = averageLoss > averageGain
|
||||
? InsightDirection.Down
|
||||
: InsightDirection.Up;
|
||||
|
||||
// Set the weight of the insight as the weight of the ETF's
|
||||
// holding. The InsightWeightingPortfolioConstructionModel
|
||||
// will rebalance our portfolio to have the same percentage
|
||||
// of holdings in our algorithm that the ETF has.
|
||||
yield return Insight.Price(
|
||||
symbol,
|
||||
TimeSpan.FromDays(1),
|
||||
direction,
|
||||
(double)(direction == InsightDirection.Down
|
||||
? averageLoss
|
||||
: averageGain),
|
||||
weight: (double?) symbolData.Constituent.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to access ETF constituent data and RSI indicators
|
||||
/// for a single Symbol
|
||||
/// </summary>
|
||||
private class SymbolData
|
||||
{
|
||||
/// <summary>
|
||||
/// Symbol this data belongs to
|
||||
/// </summary>
|
||||
public Symbol Symbol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Symbol's constituent data for the ETF it belongs to
|
||||
/// </summary>
|
||||
public ETFConstituentData Constituent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// RSI indicator for the Symbol's price data
|
||||
/// </summary>
|
||||
public RelativeStrengthIndex Rsi { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of SymbolData
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol to add data for</param>
|
||||
/// <param name="constituent">ETF constituent data</param>
|
||||
/// <param name="period">RSI period</param>
|
||||
public SymbolData(Symbol symbol, QCAlgorithm algorithm, ETFConstituentData constituent, int period)
|
||||
{
|
||||
Symbol = symbol;
|
||||
Constituent = constituent;
|
||||
Rsi = algorithm.RSI(symbol, period, MovingAverageType.Exponential, Resolution.Hour);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "52"},
|
||||
{"Average Win", "0.09%"},
|
||||
{"Average Loss", "-0.05%"},
|
||||
{"Compounding Annual Return", "3.919%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "0.080"},
|
||||
{"Net Profit", "0.630%"},
|
||||
{"Sharpe Ratio", "2.197"},
|
||||
{"Probabilistic Sharpe Ratio", "67.639%"},
|
||||
{"Loss Rate", "61%"},
|
||||
{"Win Rate", "39%"},
|
||||
{"Profit-Loss Ratio", "1.75"},
|
||||
{"Alpha", "0.043"},
|
||||
{"Beta", "-0.024"},
|
||||
{"Annual Standard Deviation", "0.018"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-0.522"},
|
||||
{"Tracking Error", "0.133"},
|
||||
{"Treynor Ratio", "-1.678"},
|
||||
{"Total Fees", "$52.00"},
|
||||
{"Estimated Strategy Capacity", "$430000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.144"},
|
||||
{"Kelly Criterion Estimate", "-2.61"},
|
||||
{"Kelly Criterion Probability Value", "0.987"},
|
||||
{"Sortino Ratio", "2.877"},
|
||||
{"Return Over Maximum Drawdown", "6.437"},
|
||||
{"Portfolio Turnover", "0.162"},
|
||||
{"Total Insights Generated", "1076"},
|
||||
{"Total Insights Closed", "1048"},
|
||||
{"Total Insights Analysis Completed", "1048"},
|
||||
{"Long Insight Count", "530"},
|
||||
{"Short Insight Count", "546"},
|
||||
{"Long/Short Ratio", "97.07%"},
|
||||
{"Estimated Monthly Alpha Value", "$-378965.1"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-756351.1"},
|
||||
{"Mean Population Estimated Insight Value", "$-721.7091"},
|
||||
{"Mean Population Direction", "45.8015%"},
|
||||
{"Mean Population Magnitude", "45.8015%"},
|
||||
{"Rolling Averaged Population Direction", "45.6662%"},
|
||||
{"Rolling Averaged Population Magnitude", "45.6662%"},
|
||||
{"OrderListHash", "f320b74a7bb7207f3f88f7fce9d0f286"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstration algorithm showing how to use and access SEC data
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="fundamental" />
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="SEC" />
|
||||
public class SECReportDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _symbol;
|
||||
|
||||
public const string Ticker = "AAPL";
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 1, 1);
|
||||
SetEndDate(2019, 1, 31);
|
||||
SetCash(100000);
|
||||
|
||||
_symbol = AddData<SECReport10Q>(Ticker, Resolution.Daily).Symbol;
|
||||
AddData<SECReport8K>(Ticker, Resolution.Daily);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var data = slice.Get<ISECReport>();
|
||||
|
||||
foreach (var submission in data.Values)
|
||||
{
|
||||
Log($"Form Type {submission.Report.FormType}");
|
||||
Log($"Filing Date: {submission.Report.FilingDate:yyyy-MM-dd}");
|
||||
|
||||
foreach (var filer in submission.Report.Filers)
|
||||
{
|
||||
Log($"Filing company name: {filer.CompanyData.ConformedName}");
|
||||
Log($"Filing company CIK: {filer.CompanyData.Cik}");
|
||||
Log($"Filing company EIN: {filer.CompanyData.IrsNumber}");
|
||||
|
||||
foreach (var formerCompany in filer.FormerCompanies)
|
||||
{
|
||||
Log($"Former company name of {filer.CompanyData.ConformedName}: {formerCompany.FormerConformedName}");
|
||||
Log($"Date of company name change: {formerCompany.Changed:yyyy-MM-dd}");
|
||||
}
|
||||
}
|
||||
|
||||
// SEC documents can come in multiple documents.
|
||||
// For multi-document reports, sometimes the document contents after the first document
|
||||
// are files that have a binary format, such as JPG and PDF files
|
||||
foreach (var document in submission.Report.Documents)
|
||||
{
|
||||
Log($"Filename: {document.Filename}");
|
||||
Log($"Document description: {document.Description}");
|
||||
|
||||
// Print sample of contents contained within the document
|
||||
Log(document.Text.Substring(0, 100));
|
||||
Log("=================");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Hour;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2017, 01, 01);
|
||||
SetEndDate(2017, 02, 01);
|
||||
|
||||
@@ -192,33 +196,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "90"},
|
||||
{"Total Trades", "92"},
|
||||
{"Average Win", "0.16%"},
|
||||
{"Average Loss", "-0.09%"},
|
||||
{"Compounding Annual Return", "50.158%"},
|
||||
{"Average Loss", "-0.08%"},
|
||||
{"Compounding Annual Return", "50.130%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0.871"},
|
||||
{"Net Profit", "3.686%"},
|
||||
{"Sharpe Ratio", "7.03"},
|
||||
{"Probabilistic Sharpe Ratio", "99.076%"},
|
||||
{"Loss Rate", "34%"},
|
||||
{"Win Rate", "66%"},
|
||||
{"Profit-Loss Ratio", "1.84"},
|
||||
{"Expectancy", "0.887"},
|
||||
{"Net Profit", "3.684%"},
|
||||
{"Sharpe Ratio", "7.029"},
|
||||
{"Probabilistic Sharpe Ratio", "99.078%"},
|
||||
{"Loss Rate", "35%"},
|
||||
{"Win Rate", "65%"},
|
||||
{"Profit-Loss Ratio", "1.89"},
|
||||
{"Alpha", "0.354"},
|
||||
{"Beta", "0.183"},
|
||||
{"Beta", "0.182"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "2.937"},
|
||||
{"Information Ratio", "2.934"},
|
||||
{"Tracking Error", "0.071"},
|
||||
{"Treynor Ratio", "2.119"},
|
||||
{"Total Fees", "$40.38"},
|
||||
{"Treynor Ratio", "2.126"},
|
||||
{"Total Fees", "$42.35"},
|
||||
{"Estimated Strategy Capacity", "$3200000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.751"},
|
||||
{"Kelly Criterion Estimate", "24.01"},
|
||||
{"Kelly Criterion Probability Value", "0.075"},
|
||||
{"Sortino Ratio", "43.079"},
|
||||
{"Return Over Maximum Drawdown", "123.633"},
|
||||
{"Sortino Ratio", "43.136"},
|
||||
{"Return Over Maximum Drawdown", "123.916"},
|
||||
{"Portfolio Turnover", "0.751"},
|
||||
{"Total Insights Generated", "55"},
|
||||
{"Total Insights Closed", "53"},
|
||||
@@ -233,7 +237,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "55.0223%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "48e2a0900c21adb8f3514aa40afb5d46"}
|
||||
{"OrderListHash", "18209554e81f4169a66cd32f9c50462b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "33.3333%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "54c7f348ffba5fc0a3799e73ab17b86d"}
|
||||
{"OrderListHash", "2eb3f3dabc4ad19cd53ab6d378d3edd0"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// use leverage 1 so we test the margin impact ordering
|
||||
_spy = AddEquity("SPY", Resolution.Minute, Market.USA, false, 1).Symbol;
|
||||
_ibm = AddEquity("IBM", Resolution.Minute, Market.USA, false, 1).Symbol;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -74,34 +78,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "9"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "354.868%"},
|
||||
{"Total Trades", "149"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "306.792%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.956%"},
|
||||
{"Sharpe Ratio", "11.804"},
|
||||
{"Probabilistic Sharpe Ratio", "65.588%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.964"},
|
||||
{"Beta", "0.994"},
|
||||
{"Annual Standard Deviation", "0.249"},
|
||||
{"Annual Variance", "0.062"},
|
||||
{"Information Ratio", "8.381"},
|
||||
{"Expectancy", "-0.916"},
|
||||
{"Net Profit", "1.810%"},
|
||||
{"Sharpe Ratio", "10.567"},
|
||||
{"Probabilistic Sharpe Ratio", "64.730%"},
|
||||
{"Loss Rate", "92%"},
|
||||
{"Win Rate", "8%"},
|
||||
{"Profit-Loss Ratio", "0.04"},
|
||||
{"Alpha", "0.659"},
|
||||
{"Beta", "0.988"},
|
||||
{"Annual Standard Deviation", "0.248"},
|
||||
{"Annual Variance", "0.061"},
|
||||
{"Information Ratio", "5.565"},
|
||||
{"Tracking Error", "0.114"},
|
||||
{"Treynor Ratio", "2.953"},
|
||||
{"Total Fees", "$13.02"},
|
||||
{"Estimated Strategy Capacity", "$3400000.00"},
|
||||
{"Treynor Ratio", "2.65"},
|
||||
{"Total Fees", "$153.02"},
|
||||
{"Estimated Strategy Capacity", "$400000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.549"},
|
||||
{"Fitness Score", "0.577"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "18.757"},
|
||||
{"Return Over Maximum Drawdown", "125.776"},
|
||||
{"Portfolio Turnover", "0.551"},
|
||||
{"Sortino Ratio", "16.701"},
|
||||
{"Return Over Maximum Drawdown", "111.126"},
|
||||
{"Portfolio Turnover", "0.579"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -115,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "e674780fa5478c91b0745395c8775252"}
|
||||
{"OrderListHash", "50e863194b0b0e6c5e704b1bd05e9060"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
111
Algorithm.CSharp/SetHoldingsRegressionAlgorithm.cs
Normal file
111
Algorithm.CSharp/SetHoldingsRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm testing the SetHolding trading API precision
|
||||
/// </summary>
|
||||
public class SetHoldingsRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 08);
|
||||
AddEquity("SPY", Resolution.Minute);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings("SPY", 0.1m);
|
||||
SetHoldings("SPY", 0.2d);
|
||||
SetHoldings("SPY", 0.3f);
|
||||
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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <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 Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$5.41"},
|
||||
{"Estimated Strategy Capacity", "$2800000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.995"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.995"},
|
||||
{"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", "211aa90fef127ec5652eff1b3d2b8ca8"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
private readonly List<OrderTicket> _ordersAllowed = new List<OrderTicket>();
|
||||
private readonly List<OrderTicket> _ordersDenied = new List<OrderTicket>();
|
||||
private bool _initialize;
|
||||
private OrderEvent _lastOrderEvent;
|
||||
private bool _invalidatedAllowedOrder;
|
||||
private bool _invalidatedNewOrderWithPortfolioHoldings;
|
||||
|
||||
@@ -125,10 +126,21 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
_lastOrderEvent = orderEvent;
|
||||
}
|
||||
|
||||
private void HandleOrder(OrderTicket orderTicket)
|
||||
{
|
||||
if (orderTicket.SubmitRequest.Status == OrderRequestStatus.Error)
|
||||
{
|
||||
if (_lastOrderEvent == null || _lastOrderEvent.Status != OrderStatus.Invalid)
|
||||
{
|
||||
throw new Exception($"Expected order event with invalid status for ticket {orderTicket}");
|
||||
}
|
||||
|
||||
_lastOrderEvent = null;
|
||||
_ordersDenied.Add(orderTicket);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SmartInsider;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm demonstrating usage of SmartInsider data
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="smart insider" />
|
||||
/// <meta name="tag" content="form 4" />
|
||||
/// <meta name="tag" content="insider trading" />
|
||||
public class SmartInsiderDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _symbol;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 7, 25);
|
||||
SetEndDate(2019, 8, 2);
|
||||
SetCash(100000);
|
||||
|
||||
AddData<SmartInsiderIntention>("KO");
|
||||
AddData<SmartInsiderTransaction>("KO");
|
||||
|
||||
_symbol = AddEquity("KO", Resolution.Daily).Symbol;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insider transaction data will be provided to us here
|
||||
/// </summary>
|
||||
/// <param name="data">Transaction data</param>
|
||||
public void OnData(SmartInsiderTransaction data)
|
||||
{
|
||||
var hasOpenOrders = Transactions.GetOpenOrders().Any();
|
||||
|
||||
if (!Portfolio.Invested && !hasOpenOrders)
|
||||
{
|
||||
if (data.BuybackPercentage > 0.0001m && data.VolumePercentage > 0.001m)
|
||||
{
|
||||
Log($"Buying {_symbol.Value} due to stock transaction");
|
||||
SetHoldings(_symbol, 0.50m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insider intention data will be provided to us here
|
||||
/// </summary>
|
||||
/// <param name="data">Intention data</param>
|
||||
public void OnData(SmartInsiderIntention data)
|
||||
{
|
||||
var hasOpenOrders = Transactions.GetOpenOrders().Any();
|
||||
|
||||
if (!Portfolio.Invested && !hasOpenOrders)
|
||||
{
|
||||
if (data.Percentage > 0.0001m)
|
||||
{
|
||||
Log($"Buying {_symbol.Value} due to intention to purchase stock");
|
||||
SetHoldings(_symbol, 0.50m);
|
||||
}
|
||||
}
|
||||
else if (Portfolio.Invested && !hasOpenOrders)
|
||||
{
|
||||
if (data.Percentage < 0.00m)
|
||||
{
|
||||
Log($"Liquidating {_symbol.Value}");
|
||||
Liquidate(_symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
Algorithm.CSharp/SparseDataRegressionAlgorithm.cs
Normal file
128
Algorithm.CSharp/SparseDataRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing an issue with sparse data which would cause auxiliary data to be emitted out of order
|
||||
/// </summary>
|
||||
public class SparseDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private bool _gotDividend;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2010, 2, 22);
|
||||
SetEndDate(2010, 2, 27);
|
||||
AddEquity("TAPA", Resolution.Hour);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var dividend in data.Dividends)
|
||||
{
|
||||
Debug($"{Time}. {dividend.Value}");
|
||||
_gotDividend = true;
|
||||
if (Time != dividend.Value.Time || Time.Day != 24)
|
||||
{
|
||||
throw new Exception("Got a dividend at an unexpected point in time");
|
||||
}
|
||||
}
|
||||
foreach (var tradeBar in data.Bars)
|
||||
{
|
||||
Debug($"{Time}. {tradeBar.Value}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_gotDividend)
|
||||
{
|
||||
throw new Exception("Never got a dividend!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <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 Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "1.376"},
|
||||
{"Tracking Error", "0.14"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"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", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
144
Algorithm.CSharp/SplitPartialShareRegressionAlgorithm.cs
Normal file
144
Algorithm.CSharp/SplitPartialShareRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm asserting the split is handled correctly. Specifically GH issue #5765, where cash
|
||||
/// difference applied due to share count difference was using the split reference price instead of the new price,
|
||||
/// increasing cash holdings by a higher amount than it should have
|
||||
/// </summary>
|
||||
public class SplitPartialShareRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private decimal _cash;
|
||||
private SplitType? _splitType;
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 06, 05);
|
||||
SetEndDate(2014, 06, 09);
|
||||
|
||||
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
|
||||
|
||||
AddEquity("AAPL");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var dataSplit in data.Splits)
|
||||
{
|
||||
if (_splitType == null || _splitType < dataSplit.Value.Type)
|
||||
{
|
||||
_splitType = dataSplit.Value.Type;
|
||||
|
||||
if (_splitType == SplitType.Warning && _cash != Portfolio.CashBook[Currencies.USD].Amount)
|
||||
{
|
||||
throw new Exception("Unexpected cash amount change before split");
|
||||
}
|
||||
|
||||
if (_splitType == SplitType.SplitOccurred)
|
||||
{
|
||||
var newCash = Portfolio.CashBook[Currencies.USD].Amount;
|
||||
if (_cash == newCash || newCash - _cash >= dataSplit.Value.SplitFactor * dataSplit.Value.ReferencePrice)
|
||||
{
|
||||
throw new Exception("Unexpected cash amount change after split");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Unexpected split event {dataSplit.Value.Type}");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
Buy("AAPL", 1);
|
||||
_cash = Portfolio.CashBook[Currencies.USD].Amount;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_splitType == null)
|
||||
{
|
||||
throw new Exception("No split was emitted!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <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 Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0.562%"},
|
||||
{"Drawdown", "3.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.007%"},
|
||||
{"Sharpe Ratio", "7.5"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.036"},
|
||||
{"Beta", "-0.026"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-22.218"},
|
||||
{"Tracking Error", "0.047"},
|
||||
{"Treynor Ratio", "-0.342"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$4200000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.003"},
|
||||
{"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", "e2718d95499fcbdb51cabc32d6e28202"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -88,22 +88,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "20"},
|
||||
{"Average Win", "0.62%"},
|
||||
{"Average Loss", "-0.19%"},
|
||||
{"Compounding Annual Return", "400.693%"},
|
||||
{"Compounding Annual Return", "399.082%"},
|
||||
{"Drawdown", "1.500%"},
|
||||
{"Expectancy", "1.402"},
|
||||
{"Net Profit", "2.081%"},
|
||||
{"Sharpe Ratio", "10.528"},
|
||||
{"Probabilistic Sharpe Ratio", "70.120%"},
|
||||
{"Expectancy", "1.396"},
|
||||
{"Net Profit", "2.077%"},
|
||||
{"Sharpe Ratio", "10.497"},
|
||||
{"Probabilistic Sharpe Ratio", "70.088%"},
|
||||
{"Loss Rate", "44%"},
|
||||
{"Win Rate", "56%"},
|
||||
{"Profit-Loss Ratio", "3.32"},
|
||||
{"Alpha", "0.541"},
|
||||
{"Beta", "1.116"},
|
||||
{"Annual Standard Deviation", "0.262"},
|
||||
{"Profit-Loss Ratio", "3.31"},
|
||||
{"Alpha", "0.533"},
|
||||
{"Beta", "1.115"},
|
||||
{"Annual Standard Deviation", "0.261"},
|
||||
{"Annual Variance", "0.068"},
|
||||
{"Information Ratio", "8.947"},
|
||||
{"Information Ratio", "8.85"},
|
||||
{"Tracking Error", "0.086"},
|
||||
{"Treynor Ratio", "2.468"},
|
||||
{"Treynor Ratio", "2.461"},
|
||||
{"Total Fees", "$41.65"},
|
||||
{"Estimated Strategy Capacity", "$2100000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
@@ -111,7 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Kelly Criterion Estimate", "34.359"},
|
||||
{"Kelly Criterion Probability Value", "0.442"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "439.243"},
|
||||
{"Return Over Maximum Drawdown", "437.491"},
|
||||
{"Portfolio Turnover", "1.083"},
|
||||
{"Total Insights Generated", "5"},
|
||||
{"Total Insights Closed", "3"},
|
||||
@@ -126,7 +126,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "100%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "d2cc8c2d0419fe5bafce7155db67286f"}
|
||||
{"OrderListHash", "ac25829306d9fb41b6fc8eebf438c505"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,11 +75,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "199"},
|
||||
{"Average Win", "0.04%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "1331.357%"},
|
||||
{"Compounding Annual Return", "1331.360%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "132.064"},
|
||||
{"Expectancy", "132.065"},
|
||||
{"Net Profit", "3.461%"},
|
||||
{"Sharpe Ratio", "38.701"},
|
||||
{"Sharpe Ratio", "38.704"},
|
||||
{"Probabilistic Sharpe Ratio", "99.757%"},
|
||||
{"Loss Rate", "1%"},
|
||||
{"Win Rate", "99%"},
|
||||
@@ -88,9 +88,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0.798"},
|
||||
{"Annual Standard Deviation", "0.198"},
|
||||
{"Annual Variance", "0.039"},
|
||||
{"Information Ratio", "58.002"},
|
||||
{"Information Ratio", "57.997"},
|
||||
{"Tracking Error", "0.098"},
|
||||
{"Treynor Ratio", "9.586"},
|
||||
{"Treynor Ratio", "9.587"},
|
||||
{"Total Fees", "$260.38"},
|
||||
{"Estimated Strategy Capacity", "$400000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
@@ -98,7 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Kelly Criterion Estimate", "34.359"},
|
||||
{"Kelly Criterion Probability Value", "0.442"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "30077.649"},
|
||||
{"Return Over Maximum Drawdown", "30277.012"},
|
||||
{"Portfolio Turnover", "0.621"},
|
||||
{"Total Insights Generated", "5"},
|
||||
{"Total Insights Closed", "3"},
|
||||
@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "100%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "5dd0ff1e4a7470b4fee9588b3200dab6"}
|
||||
{"OrderListHash", "1cb6986aa4193a8722b0a9d502776ebb"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data.Custom.TradingEconomics;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example algorithm shows how to import and use Trading Economics data.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="strategy example" />
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="tradingeconomics" />
|
||||
public class TradingEconomicsCalendarIndicatorAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 1, 1);
|
||||
SetEndDate(2019, 1, 1);
|
||||
|
||||
AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate);
|
||||
AddData<TradingEconomicsIndicator>(TradingEconomics.Indicator.UnitedStates.InterestRate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Trading Economics Calendar object</param>
|
||||
public void OnData(TradingEconomicsCalendar data)
|
||||
{
|
||||
Log($"{Time} - {data}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Trading Economics Indicator object</param>
|
||||
public void OnData(TradingEconomicsIndicator data)
|
||||
{
|
||||
Log($"{Time} - {data}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,34 +73,34 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "7"},
|
||||
{"Total Trades", "5"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.35%"},
|
||||
{"Compounding Annual Return", "239.778%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Average Loss", "-0.76%"},
|
||||
{"Compounding Annual Return", "280.877%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.576%"},
|
||||
{"Sharpe Ratio", "7.724"},
|
||||
{"Probabilistic Sharpe Ratio", "65.265%"},
|
||||
{"Net Profit", "1.724%"},
|
||||
{"Sharpe Ratio", "9.01"},
|
||||
{"Probabilistic Sharpe Ratio", "67.047%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.271"},
|
||||
{"Beta", "1.028"},
|
||||
{"Annual Standard Deviation", "0.229"},
|
||||
{"Annual Variance", "0.052"},
|
||||
{"Information Ratio", "-24.894"},
|
||||
{"Tracking Error", "0.009"},
|
||||
{"Treynor Ratio", "1.719"},
|
||||
{"Total Fees", "$24.08"},
|
||||
{"Estimated Strategy Capacity", "$18000000.00"},
|
||||
{"Alpha", "0.026"},
|
||||
{"Beta", "1.012"},
|
||||
{"Annual Standard Deviation", "0.226"},
|
||||
{"Annual Variance", "0.051"},
|
||||
{"Information Ratio", "3.929"},
|
||||
{"Tracking Error", "0.013"},
|
||||
{"Treynor Ratio", "2.008"},
|
||||
{"Total Fees", "$17.21"},
|
||||
{"Estimated Strategy Capacity", "$29000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.999"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "68.799"},
|
||||
{"Portfolio Turnover", "1.748"},
|
||||
{"Return Over Maximum Drawdown", "91.3"},
|
||||
{"Portfolio Turnover", "1.241"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
@@ -114,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "4e7e8421606feccde05e3fcd3aa6b459"}
|
||||
{"OrderListHash", "1d1c126b61eb07c291b0e451864a7481"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
using QuantConnect.Indicators;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example algorithm shows how to import and use Tiingo daily prices data.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="strategy example" />
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="tiingo" />
|
||||
public class USEnergyInformationAdministrationAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const string tiingoTicker = "AAPL";
|
||||
private const string energyTicker = "NUC_STATUS.OUT.US.D"; // US nuclear capacity outage (Daily)
|
||||
private Symbol _tiingoSymbol;
|
||||
private Symbol _energySymbol;
|
||||
|
||||
private ExponentialMovingAverage _emaFast;
|
||||
private ExponentialMovingAverage _emaSlow;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2017, 1, 1);
|
||||
SetEndDate(2017, 12, 31);
|
||||
SetCash(100000);
|
||||
|
||||
// Set your Tiingo API Token here
|
||||
Tiingo.SetAuthCode("my-tiingo-api-token");
|
||||
// Set your US Energy Information Administration (EIA) Token here
|
||||
USEnergyAPI.SetAuthCode("my-us-energy-information-api-token");
|
||||
|
||||
_tiingoSymbol = AddData<TiingoPrice>(tiingoTicker, Resolution.Daily).Symbol;
|
||||
_energySymbol = AddData<USEnergyAPI>(energyTicker, Resolution.Hour).Symbol;
|
||||
|
||||
_emaFast = EMA(_tiingoSymbol, 5);
|
||||
_emaSlow = EMA(_tiingoSymbol, 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// Extract Tiingo data from the slice
|
||||
var tiingoData = slice.Get<TiingoPrice>();
|
||||
foreach (var row in tiingoData.Values)
|
||||
{
|
||||
Log($"{Time} - {row.Symbol.Value} - {row.Close} {row.Value} {row.Price} - EmaFast:{_emaFast} - EmaSlow:{_emaSlow}");
|
||||
}
|
||||
|
||||
// Extract US EIA data from the slice
|
||||
var energyData = slice.Get<USEnergyAPI>();
|
||||
foreach (var row in energyData.Values)
|
||||
{
|
||||
Log($"{Time} - {row.Symbol.Value} - {row.Value} ");
|
||||
}
|
||||
|
||||
// Simple EMA cross
|
||||
if (!Portfolio.Invested && _emaFast > _emaSlow)
|
||||
{
|
||||
SetHoldings(_tiingoSymbol, 1);
|
||||
}
|
||||
else if (Portfolio.Invested && _emaFast < _emaSlow)
|
||||
{
|
||||
Liquidate(_tiingoSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstration algorithm showing how to use and access U.S. Treasury yield curve data
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="yield curve" />
|
||||
public class USTreasuryYieldCurveDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2017, 1, 1);
|
||||
SetEndDate(2019, 6, 30);
|
||||
SetCash(100000);
|
||||
|
||||
// Since yield data isn't associated with any ticker, we must put a placeholder ticker
|
||||
AddData<USTreasuryYieldCurveRate>("USTYC", Resolution.Daily);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var data = slice.Get<USTreasuryYieldCurveRate>();
|
||||
|
||||
foreach (var curve in data.Values)
|
||||
{
|
||||
Log($"{curve.Time} - 1M: {curve.OneMonth}, 2M: {curve.TwoMonth}, 3M: {curve.ThreeMonth}, 6M: {curve.SixMonth}, 1Y: {curve.OneYear}, 2Y: {curve.TwoYear}, 3Y: {curve.ThreeYear}, 5Y: {curve.FiveYear}, 10Y: {curve.TenYear}, 20Y: {curve.TwentyYear}, 30Y: {curve.ThirtyYear}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,16 +42,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(100*1000);
|
||||
|
||||
// add universe for the top 50 stocks by dollar volume
|
||||
AddUniverse(Universe.DollarVolume.Top(50));
|
||||
|
||||
// add universe for the bottom 50 stocks by dollar volume
|
||||
AddUniverse(Universe.DollarVolume.Bottom(50));
|
||||
|
||||
// add universe for the 90th dollar volume percentile
|
||||
AddUniverse(Universe.DollarVolume.Percentile(90));
|
||||
|
||||
// add universe for stocks between the 70th and 80th dollar volume percentile
|
||||
AddUniverse(Universe.DollarVolume.Percentile(70, 80));
|
||||
AddUniverse(Universe.Top(50));
|
||||
}
|
||||
|
||||
public void OnData(TradeBars data)
|
||||
|
||||
@@ -213,7 +213,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "698d53191e2d76ec4171026a68f4b73d"}
|
||||
{"OrderListHash", "bbc9f982183f74b34be4529acaa33fe8"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public override void Initialize()
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// Order margin value has to have a minimum of 0.5% of Portfolio value, allows filtering out small trades and reduce fees.
|
||||
// Commented so regression algorithm is more sensitive
|
||||
//Settings.MinimumOrderMarginPortfolioPercentage = 0.005m;
|
||||
|
||||
SetStartDate(2014, 03, 25);
|
||||
SetEndDate(2014, 04, 07);
|
||||
|
||||
@@ -100,33 +105,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "17"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Total Trades", "19"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-5.477%"},
|
||||
{"Compounding Annual Return", "-5.481%"},
|
||||
{"Drawdown", "2.100%"},
|
||||
{"Expectancy", "0.904"},
|
||||
{"Expectancy", "0.949"},
|
||||
{"Net Profit", "-0.216%"},
|
||||
{"Sharpe Ratio", "-0.262"},
|
||||
{"Probabilistic Sharpe Ratio", "39.643%"},
|
||||
{"Loss Rate", "43%"},
|
||||
{"Win Rate", "57%"},
|
||||
{"Profit-Loss Ratio", "2.33"},
|
||||
{"Sharpe Ratio", "-0.263"},
|
||||
{"Probabilistic Sharpe Ratio", "39.639%"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "1.92"},
|
||||
{"Alpha", "-0.049"},
|
||||
{"Beta", "-0.067"},
|
||||
{"Annual Standard Deviation", "0.138"},
|
||||
{"Annual Standard Deviation", "0.137"},
|
||||
{"Annual Variance", "0.019"},
|
||||
{"Information Ratio", "0.914"},
|
||||
{"Tracking Error", "0.175"},
|
||||
{"Treynor Ratio", "0.537"},
|
||||
{"Total Fees", "$31.21"},
|
||||
{"Estimated Strategy Capacity", "$68000000.00"},
|
||||
{"Treynor Ratio", "0.536"},
|
||||
{"Total Fees", "$33.21"},
|
||||
{"Estimated Strategy Capacity", "$57000000.00"},
|
||||
{"Lowest Capacity Asset", "IBM R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.023"},
|
||||
{"Kelly Criterion Estimate", "-1.72"},
|
||||
{"Kelly Criterion Probability Value", "0.534"},
|
||||
{"Sortino Ratio", "-0.808"},
|
||||
{"Return Over Maximum Drawdown", "-2.585"},
|
||||
{"Sortino Ratio", "-0.81"},
|
||||
{"Return Over Maximum Drawdown", "-2.587"},
|
||||
{"Portfolio Turnover", "0.084"},
|
||||
{"Total Insights Generated", "22"},
|
||||
{"Total Insights Closed", "20"},
|
||||
@@ -141,7 +146,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "30%"},
|
||||
{"Rolling Averaged Population Direction", "42.9939%"},
|
||||
{"Rolling Averaged Population Magnitude", "42.9939%"},
|
||||
{"OrderListHash", "c68844a544a6046ef01d7ff92cd83f4f"}
|
||||
{"OrderListHash", "0b0afe138397f324a48170acb2ec6ebf"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "8d76366ca3ee70abc907723b4583d56e"}
|
||||
{"OrderListHash", "308c3da05b4bd6f294158736c998ef36"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,33 +74,33 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "238"},
|
||||
{"Total Trades", "239"},
|
||||
{"Average Win", "0.05%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "435.039%"},
|
||||
{"Compounding Annual Return", "434.243%"},
|
||||
{"Drawdown", "1.300%"},
|
||||
{"Expectancy", "1.892"},
|
||||
{"Net Profit", "2.167%"},
|
||||
{"Sharpe Ratio", "11.686"},
|
||||
{"Probabilistic Sharpe Ratio", "70.333%"},
|
||||
{"Loss Rate", "30%"},
|
||||
{"Win Rate", "70%"},
|
||||
{"Profit-Loss Ratio", "3.15"},
|
||||
{"Alpha", "0.854"},
|
||||
{"Expectancy", "1.938"},
|
||||
{"Net Profit", "2.166%"},
|
||||
{"Sharpe Ratio", "11.667"},
|
||||
{"Probabilistic Sharpe Ratio", "70.318%"},
|
||||
{"Loss Rate", "31%"},
|
||||
{"Win Rate", "69%"},
|
||||
{"Profit-Loss Ratio", "3.26"},
|
||||
{"Alpha", "0.849"},
|
||||
{"Beta", "1.059"},
|
||||
{"Annual Standard Deviation", "0.253"},
|
||||
{"Annual Variance", "0.064"},
|
||||
{"Information Ratio", "10.503"},
|
||||
{"Information Ratio", "10.465"},
|
||||
{"Tracking Error", "0.092"},
|
||||
{"Treynor Ratio", "2.79"},
|
||||
{"Total Fees", "$398.15"},
|
||||
{"Treynor Ratio", "2.785"},
|
||||
{"Total Fees", "$399.15"},
|
||||
{"Estimated Strategy Capacity", "$470000.00"},
|
||||
{"Lowest Capacity Asset", "AIG R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.938"},
|
||||
{"Kelly Criterion Estimate", "34.359"},
|
||||
{"Kelly Criterion Probability Value", "0.442"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "484.391"},
|
||||
{"Return Over Maximum Drawdown", "482.497"},
|
||||
{"Portfolio Turnover", "0.938"},
|
||||
{"Total Insights Generated", "5"},
|
||||
{"Total Insights Closed", "3"},
|
||||
@@ -115,7 +115,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "100%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "ac1e67937bb446ec0ad41acfa481dd85"}
|
||||
{"OrderListHash", "d661c77833be41c963b94944b00889ff"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "8e9ea215681a3faf227b9908a7235884"}
|
||||
{"OrderListHash", "c585658b51441b4600ec32166af3754c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "184d77b052ceb9b340c3154aea460b34"}
|
||||
{"OrderListHash", "f409be3a7c63d9c1394c2e6c005a15ee"}
|
||||
};
|
||||
|
||||
internal class TestBrokerageModel : DefaultBrokerageModel
|
||||
|
||||
@@ -11,18 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from clr import AddReference
|
||||
AddReference("QuantConnect.Common")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
AddReference("QuantConnect.Algorithm.Framework")
|
||||
AddReference("QuantConnect.Indicators")
|
||||
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Indicators import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Algorithm.Framework import *
|
||||
from QuantConnect.Algorithm.Framework.Alphas import *
|
||||
from datetime import timedelta
|
||||
from AlgorithmImports import *
|
||||
from enum import Enum
|
||||
|
||||
class BasePairsTradingAlphaModel(AlphaModel):
|
||||
@@ -182,4 +171,4 @@ class BasePairsTradingAlphaModel(AlphaModel):
|
||||
# creates a group id and set the GroupId property on each insight object
|
||||
return Insight.Group(longAsset1, shortAsset2)
|
||||
|
||||
return []
|
||||
return []
|
||||
|
||||
@@ -11,16 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from clr import AddReference
|
||||
AddReference("QuantConnect.Common")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
AddReference("QuantConnect.Algorithm.Framework")
|
||||
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Algorithm.Framework import *
|
||||
from QuantConnect.Algorithm.Framework.Alphas import AlphaModel, Insight, InsightType, InsightDirection
|
||||
|
||||
from AlgorithmImports import *
|
||||
|
||||
class ConstantAlphaModel(AlphaModel):
|
||||
''' Provides an implementation of IAlphaModel that always returns the same insight for each security'''
|
||||
@@ -50,7 +41,7 @@ class ConstantAlphaModel(AlphaModel):
|
||||
if confidence is not None:
|
||||
self.Name += ',{}'.format(confidence)
|
||||
|
||||
self.Name += ')';
|
||||
self.Name += ')'
|
||||
|
||||
|
||||
def Update(self, algorithm, data):
|
||||
@@ -106,4 +97,4 @@ def strfdelta(tdelta):
|
||||
d = tdelta.days
|
||||
h, rem = divmod(tdelta.seconds, 3600)
|
||||
m, s = divmod(rem, 60)
|
||||
return "{}.{:02d}:{:02d}:{:02d}".format(d,h,m,s)
|
||||
return "{}.{:02d}:{:02d}:{:02d}".format(d,h,m,s)
|
||||
|
||||
@@ -11,18 +11,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from clr import AddReference
|
||||
AddReference("QuantConnect.Common")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
AddReference("QuantConnect.Algorithm.Framework")
|
||||
AddReference("QuantConnect.Indicators")
|
||||
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Indicators import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Algorithm.Framework import *
|
||||
from QuantConnect.Algorithm.Framework.Alphas import *
|
||||
|
||||
from AlgorithmImports import *
|
||||
|
||||
class EmaCrossAlphaModel(AlphaModel):
|
||||
'''Alpha model that uses an EMA cross to create insights'''
|
||||
@@ -102,4 +91,4 @@ class SymbolData:
|
||||
|
||||
@property
|
||||
def SlowIsOverFast(self):
|
||||
return not self.FastIsOverSlow
|
||||
return not self.FastIsOverSlow
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user