Compare commits
71 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d94a1d09a4 | ||
|
|
2c843cae9e | ||
|
|
039fdf7e4a | ||
|
|
2c63546c37 | ||
|
|
58682e1bbd | ||
|
|
d11a375fdb | ||
|
|
6ab91a13e1 | ||
|
|
beaa705646 | ||
|
|
4c830c8235 | ||
|
|
395c1123da | ||
|
|
8e50645640 | ||
|
|
68ca504d3a | ||
|
|
12df1c9a31 | ||
|
|
4de25b6cd4 | ||
|
|
cdef9e709a | ||
|
|
3579fecc58 | ||
|
|
3a390cfa9f | ||
|
|
58dae061e7 | ||
|
|
3f2479393f | ||
|
|
4849588c3b | ||
|
|
3d84c76abb | ||
|
|
1c3d849ad5 | ||
|
|
271220083b | ||
|
|
b29d0cbfaf | ||
|
|
27a25cd663 | ||
|
|
5ed61db2bb | ||
|
|
4a1485a291 | ||
|
|
d6072c88a5 | ||
|
|
20910ca2dc | ||
|
|
c333ccdc4a | ||
|
|
88c4a332bc | ||
|
|
5d762d16b2 | ||
|
|
e2a0873b7c | ||
|
|
31ebaaeaa9 | ||
|
|
7625e232f4 | ||
|
|
63f3af7afe | ||
|
|
87b42f6fb5 | ||
|
|
f9dc38efab | ||
|
|
5587efaadd | ||
|
|
a642d53bf9 | ||
|
|
002151eab2 | ||
|
|
4c085ff853 | ||
|
|
3aa76d4289 | ||
|
|
5236fc202d | ||
|
|
1ca4389ed2 | ||
|
|
b8397db0b7 | ||
|
|
d4ea5f7b04 | ||
|
|
458272b2ea | ||
|
|
6c7353d09a | ||
|
|
834d4a4d58 | ||
|
|
561aa3cf25 | ||
|
|
e4af2ef856 | ||
|
|
3f8158a5be | ||
|
|
0c4a641590 | ||
|
|
20986059a9 | ||
|
|
c22a538bad | ||
|
|
5dcda56a73 | ||
|
|
8076782ea6 | ||
|
|
e869765759 | ||
|
|
c7fb6165e2 | ||
|
|
d9d02bc2d0 | ||
|
|
caedddddf0 | ||
|
|
4e00324b57 | ||
|
|
1b6301d813 | ||
|
|
d24695856d | ||
|
|
17e13665eb | ||
|
|
8c6aa6a3b3 | ||
|
|
83da0affc5 | ||
|
|
60798df64c | ||
|
|
bb20f9d9df | ||
|
|
32686db739 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -196,6 +196,7 @@ publish/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
!LocalPackages/*
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
@@ -204,6 +205,7 @@ publish/
|
||||
#!**/packages/repositories.config
|
||||
# ignore sln level nuget
|
||||
.nuget/
|
||||
!.nuget/NuGet.config
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx/
|
||||
|
||||
10
.nuget/NuGet.config
Normal file
10
.nuget/NuGet.config
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageRestore>
|
||||
<add key="enabled" value="true" />
|
||||
<add key="automatic" value="true" />
|
||||
</packageRestore>
|
||||
<packageSources>
|
||||
<add key="LocalPackages" value="../LocalPackages" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -6,6 +6,7 @@ mono:
|
||||
solution: QuantConnect.Lean.sln
|
||||
before_install:
|
||||
- export PATH="$HOME/miniconda3/bin:$PATH"
|
||||
- export PYTHONNET_PYDLL="$HOME/miniconda3/lib/libpython3.6m.so"
|
||||
- wget -q https://cdn.quantconnect.com/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh
|
||||
- bash Miniconda3-4.5.12-Linux-x86_64.sh -b
|
||||
- rm -rf Miniconda3-4.5.12-Linux-x86_64.sh
|
||||
@@ -20,6 +21,7 @@ before_install:
|
||||
install:
|
||||
- nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
|
||||
script:
|
||||
- dotnet nuget add source $TRAVIS_BUILD_DIR/LocalPackages
|
||||
- dotnet build /p:Configuration=Release /p:VbcToolExe=vbnc.exe /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
- mono ./testrunner/NUnit.ConsoleRunner.3.11.1/tools/nunit3-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --where "cat != TravisExclude" --labels=Off --params:log-handler=ConsoleErrorLogHandler
|
||||
- chmod +x ci_build_stubs.sh
|
||||
|
||||
4
.vscode/readme.md
vendored
4
.vscode/readme.md
vendored
@@ -67,7 +67,7 @@ Before we can use this method with Windows or Mac OS we need to share the Lean d
|
||||
|
||||
Next we need to be sure that our Lean configuration at **.\Launcher\config.json** is properly set. Just like running lean locally the config must reflect what we want Lean to run.
|
||||
|
||||
You configuration file should look something like this for the following languages:
|
||||
Your configuration file should look something like this for the following languages:
|
||||
|
||||
<h3>Python:</h3>
|
||||
|
||||
@@ -203,4 +203,4 @@ Here we will cover some common issues with setting this up. This section will ex
|
||||
|
||||
* Any error messages about building in VSCode that point to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.
|
||||
* `Errors exist after running preLaunchTask 'run-docker'`This VSCode error appears to warn you of CSharp errors when trying to use `Debug in Container` select "Debug Anyway" as the errors are false flags for JSON comments as well as `QuantConnect.csx` not finding references. Neither of these will impact your debugging.
|
||||
* `The container name "/LeanEngine" is already in use by container "****"` This Docker error implies that another instance of lean is already running under the container name /LeanEngine. If this error appears either use Docker Desktop to delete the container or use `docker kill LeanEngine` from the command line.
|
||||
* `The container name "/LeanEngine" is already in use by container "****"` This Docker error implies that another instance of lean is already running under the container name /LeanEngine. If this error appears either use Docker Desktop to delete the container or use `docker kill LeanEngine` from the command line.
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.212"},
|
||||
{"Treynor Ratio", "-2.13"},
|
||||
{"Total Fees", "$199.00"},
|
||||
{"Estimated Strategy Capacity", "$23000000.00"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
|
||||
@@ -130,6 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.367"},
|
||||
{"Treynor Ratio", "-4.079"},
|
||||
{"Total Fees", "$14.33"},
|
||||
{"Estimated Strategy Capacity", "$38000000.00"},
|
||||
{"Fitness Score", "0.408"},
|
||||
{"Kelly Criterion Estimate", "16.447"},
|
||||
{"Kelly Criterion Probability Value", "0.315"},
|
||||
|
||||
@@ -185,6 +185,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.043"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Estimated Strategy Capacity", "$28000000.00"},
|
||||
{"Fitness Score", "1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -219,6 +219,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.044"},
|
||||
{"Treynor Ratio", "0.479"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Estimated Strategy Capacity", "$12000.00"},
|
||||
{"Fitness Score", "0.41"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -139,6 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.058"},
|
||||
{"Treynor Ratio", "2.133"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$45000000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -191,6 +191,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.042"},
|
||||
{"Treynor Ratio", "0.286"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$2800000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -79,19 +79,19 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// things like manually added, auto added, internal, and any other boolean state we need to track against a single security)
|
||||
throw new Exception("The underlying equity data should NEVER be removed in this algorithm because it was manually added");
|
||||
}
|
||||
if (_expectedSecurities.AreDifferent(LinqExtensions.ToHashSet(Securities.Keys)))
|
||||
if (_expectedSecurities.AreDifferent(Securities.Keys.ToHashSet()))
|
||||
{
|
||||
var expected = string.Join(Environment.NewLine, _expectedSecurities.OrderBy(s => s.ToString()));
|
||||
var actual = string.Join(Environment.NewLine, Securities.Keys.OrderBy(s => s.ToString()));
|
||||
throw new Exception($"{Time}:: Detected differences in expected and actual securities{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
|
||||
}
|
||||
if (_expectedUniverses.AreDifferent(LinqExtensions.ToHashSet(UniverseManager.Keys)))
|
||||
if (_expectedUniverses.AreDifferent(Securities.Keys.ToHashSet()))
|
||||
{
|
||||
var expected = string.Join(Environment.NewLine, _expectedUniverses.OrderBy(s => s.ToString()));
|
||||
var actual = string.Join(Environment.NewLine, UniverseManager.Keys.OrderBy(s => s.ToString()));
|
||||
throw new Exception($"{Time}:: Detected differences in expected and actual universes{Environment.NewLine}Expected:{Environment.NewLine}{expected}{Environment.NewLine}Actual:{Environment.NewLine}{actual}");
|
||||
}
|
||||
if (_expectedData.AreDifferent(LinqExtensions.ToHashSet(data.Keys)))
|
||||
if (_expectedData.AreDifferent(Securities.Keys.ToHashSet()))
|
||||
{
|
||||
var expected = string.Join(Environment.NewLine, _expectedData.OrderBy(s => s.ToString()));
|
||||
var actual = string.Join(Environment.NewLine, data.Keys.OrderBy(s => s.ToString()));
|
||||
@@ -183,7 +183,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
if (changes.RemovedSecurities
|
||||
.Where(x => x.Symbol.SecurityType == SecurityType.Option)
|
||||
.ToHashSet(s => s.Symbol)
|
||||
.AreDifferent(LinqExtensions.ToHashSet(_expectedContracts)))
|
||||
.AreDifferent(_expectedContracts.ToHashSet()))
|
||||
{
|
||||
throw new Exception("Expected removed securities to equal expected contracts added");
|
||||
}
|
||||
@@ -230,6 +230,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Estimated Strategy Capacity", "$1500.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.072"},
|
||||
{"Treynor Ratio", "2.933"},
|
||||
{"Total Fees", "$26.39"},
|
||||
{"Estimated Strategy Capacity", "$4400000.00"},
|
||||
{"Fitness Score", "0.374"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -84,6 +84,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.006"},
|
||||
{"Treynor Ratio", "2.029"},
|
||||
{"Total Fees", "$9.77"},
|
||||
{"Estimated Strategy Capacity", "$37000000.00"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.376"},
|
||||
{"Treynor Ratio", "-0.084"},
|
||||
{"Total Fees", "$13.98"},
|
||||
{"Estimated Strategy Capacity", "$61000000.00"},
|
||||
{"Fitness Score", "0.146"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
|
||||
@@ -110,6 +110,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.194"},
|
||||
{"Treynor Ratio", "-0.962"},
|
||||
{"Total Fees", "$25.92"},
|
||||
{"Estimated Strategy Capacity", "$69000000.00"},
|
||||
{"Fitness Score", "0.004"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
|
||||
@@ -211,6 +211,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.068"},
|
||||
{"Treynor Ratio", "1.722"},
|
||||
{"Total Fees", "$307.50"},
|
||||
{"Estimated Strategy Capacity", "$2800000.00"},
|
||||
{"Fitness Score", "0.173"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -98,6 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.099"},
|
||||
{"Treynor Ratio", "-5.187"},
|
||||
{"Total Fees", "$65.00"},
|
||||
{"Estimated Strategy Capacity", "$16000000000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -168,6 +168,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.441"},
|
||||
{"Treynor Ratio", "-0.008"},
|
||||
{"Total Fees", "$20.35"},
|
||||
{"Estimated Strategy Capacity", "$19000000.00"},
|
||||
{"Fitness Score", "0.138"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -130,6 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.001"},
|
||||
{"Treynor Ratio", "1.922"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Estimated Strategy Capacity", "$58000000.00"},
|
||||
{"Fitness Score", "0.248"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -316,6 +316,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.019"},
|
||||
{"Treynor Ratio", "-0.23"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.213"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -88,6 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$85000.00"},
|
||||
{"Fitness Score", "0.506"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.001"},
|
||||
{"Treynor Ratio", "1.922"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Estimated Strategy Capacity", "$58000000.00"},
|
||||
{"Fitness Score", "0.248"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -223,6 +223,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$85.34"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.5"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -88,6 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.221"},
|
||||
{"Treynor Ratio", "-13.568"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Estimated Strategy Capacity", "$890000000.00"},
|
||||
{"Fitness Score", "0.111"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -109,6 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.002"},
|
||||
{"Treynor Ratio", "1.839"},
|
||||
{"Total Fees", "$9.77"},
|
||||
{"Estimated Strategy Capacity", "$27000000.00"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
|
||||
@@ -147,6 +147,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.504"},
|
||||
{"Treynor Ratio", "1.011"},
|
||||
{"Total Fees", "$15207.00"},
|
||||
{"Estimated Strategy Capacity", "$7700.00"},
|
||||
{"Fitness Score", "0.033"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -155,6 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.188"},
|
||||
{"Treynor Ratio", "-3.318"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Estimated Strategy Capacity", "$52000000.00"},
|
||||
{"Fitness Score", "0.009"},
|
||||
{"Kelly Criterion Estimate", "-112.972"},
|
||||
{"Kelly Criterion Probability Value", "0.671"},
|
||||
|
||||
@@ -160,6 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
157
Algorithm.CSharp/BasicTemplateIndexAlgorithm.cs
Normal file
157
Algorithm.CSharp/BasicTemplateIndexAlgorithm.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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 System.Collections.Generic;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to add index asset types.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
/// <meta name="tag" content="indexes" />
|
||||
public class BasicTemplateIndexAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spx;
|
||||
private Symbol _spxOption;
|
||||
private ExponentialMovingAverage _emaSlow;
|
||||
private ExponentialMovingAverage _emaFast;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 4);
|
||||
SetEndDate(2021, 1, 15);
|
||||
SetCash(1000000);
|
||||
|
||||
// Use indicator for signal; but it cannot be traded
|
||||
_spx = AddIndex("SPX", Resolution.Minute).Symbol;
|
||||
|
||||
// Trade on SPX ITM calls
|
||||
_spxOption = QuantConnect.Symbol.CreateOption(
|
||||
_spx,
|
||||
Market.USA,
|
||||
OptionStyle.European,
|
||||
OptionRight.Call,
|
||||
3200m,
|
||||
new DateTime(2021, 1, 15));
|
||||
|
||||
AddIndexOptionContract(_spxOption, Resolution.Minute);
|
||||
|
||||
_emaSlow = EMA(_spx, 80);
|
||||
_emaFast = EMA(_spx, 200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index EMA Cross trading underlying.
|
||||
/// </summary>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (!slice.Bars.ContainsKey(_spx) || !slice.Bars.ContainsKey(_spxOption))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Warm up indicators
|
||||
if (!_emaSlow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_emaFast > _emaSlow)
|
||||
{
|
||||
SetHoldings(_spxOption, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (Portfolio[_spx].TotalSaleVolume > 0)
|
||||
{
|
||||
throw new Exception("Index is not tradable.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "-53.10%"},
|
||||
{"Compounding Annual Return", "-96.172%"},
|
||||
{"Drawdown", "10.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-9.915%"},
|
||||
{"Sharpe Ratio", "-4.217"},
|
||||
{"Probabilistic Sharpe Ratio", "0.052%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0.139"},
|
||||
{"Annual Variance", "0.019"},
|
||||
{"Information Ratio", "-4.217"},
|
||||
{"Tracking Error", "0.139"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$14000000.00"},
|
||||
{"Fitness Score", "0.044"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.96"},
|
||||
{"Return Over Maximum Drawdown", "-10.171"},
|
||||
{"Portfolio Turnover", "0.34"},
|
||||
{"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", "52521ab779446daf4d38a7c9bbbdd893"}
|
||||
};
|
||||
}
|
||||
}
|
||||
180
Algorithm.CSharp/BasicTemplateIndexOptionsAlgorithm.cs
Normal file
180
Algorithm.CSharp/BasicTemplateIndexOptionsAlgorithm.cs
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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 System.Collections.Generic;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to add index asset types and trade index options on SPX.
|
||||
/// </summary>
|
||||
public class BasicTemplateIndexOptionsAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spx;
|
||||
private ExponentialMovingAverage _emaSlow;
|
||||
private ExponentialMovingAverage _emaFast;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 4);
|
||||
SetEndDate(2021, 2, 1);
|
||||
SetCash(1000000);
|
||||
|
||||
// Use indicator for signal; but it cannot be traded.
|
||||
// We will instead trade on SPX options
|
||||
_spx = AddIndex("SPX", Resolution.Minute).Symbol;
|
||||
var spxOptions = AddIndexOption(_spx, Resolution.Minute);
|
||||
spxOptions.SetFilter(filterFunc => filterFunc.CallsOnly());
|
||||
|
||||
_emaSlow = EMA(_spx, 80);
|
||||
_emaFast = EMA(_spx, 200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index EMA Cross trading index options of the index.
|
||||
/// </summary>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (!slice.Bars.ContainsKey(_spx))
|
||||
{
|
||||
Debug($"No SPX on {Time}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Warm up indicators
|
||||
if (!_emaSlow.IsReady)
|
||||
{
|
||||
Debug($"EMA slow not ready on {Time}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var chain in slice.OptionChains.Values)
|
||||
{
|
||||
foreach (var contract in chain.Contracts.Values)
|
||||
{
|
||||
if (contract.Expiry.Month == 3 && contract.Symbol.ID.StrikePrice == 3700m && contract.Right == OptionRight.Call && slice.QuoteBars.ContainsKey(contract.Symbol))
|
||||
{
|
||||
Log($"{Time} {contract.Strike}{(contract.Right == OptionRight.Call ? 'C' : 'P')} -- {slice.QuoteBars[contract.Symbol]}");
|
||||
}
|
||||
|
||||
if (Portfolio.Invested)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_emaFast > _emaSlow && contract.Right == OptionRight.Call)
|
||||
{
|
||||
Liquidate(InvertOption(contract.Symbol));
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
}
|
||||
else if (_emaFast < _emaSlow && contract.Right == OptionRight.Put)
|
||||
{
|
||||
Liquidate(InvertOption(contract.Symbol));
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (Portfolio[_spx].TotalSaleVolume > 0)
|
||||
{
|
||||
throw new Exception("Index is not tradable.");
|
||||
}
|
||||
if (Portfolio.TotalSaleVolume == 0)
|
||||
{
|
||||
throw new Exception("Trade volume should be greater than zero by the end of this algorithm");
|
||||
}
|
||||
}
|
||||
|
||||
public Symbol InvertOption(Symbol symbol)
|
||||
{
|
||||
return QuantConnect.Symbol.CreateOption(
|
||||
symbol.Underlying,
|
||||
symbol.ID.Market,
|
||||
symbol.ID.OptionStyle,
|
||||
symbol.ID.OptionRight == OptionRight.Call ? OptionRight.Put : OptionRight.Call,
|
||||
symbol.ID.StrikePrice,
|
||||
symbol.ID.Date);
|
||||
}
|
||||
|
||||
/// <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, 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", "8220"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "13.500%"},
|
||||
{"Expectancy", "-0.818"},
|
||||
{"Net Profit", "-13.517%"},
|
||||
{"Sharpe Ratio", "-2.678"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "89%"},
|
||||
{"Win Rate", "11%"},
|
||||
{"Profit-Loss Ratio", "0.69"},
|
||||
{"Alpha", "4.398"},
|
||||
{"Beta", "-0.989"},
|
||||
{"Annual Standard Deviation", "0.373"},
|
||||
{"Annual Variance", "0.139"},
|
||||
{"Information Ratio", "-12.816"},
|
||||
{"Tracking Error", "0.504"},
|
||||
{"Treynor Ratio", "1.011"},
|
||||
{"Total Fees", "$15207.00"},
|
||||
{"Estimated Strategy Capacity", "$8800000.00"},
|
||||
{"Fitness Score", "0.033"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-8.62"},
|
||||
{"Return Over Maximum Drawdown", "-7.81"},
|
||||
{"Portfolio Turnover", "302.321"},
|
||||
{"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", "35b3f4b7a225468d42ca085386a2383e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -134,6 +134,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$778.00"},
|
||||
{"Estimated Strategy Capacity", "$720.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$1300000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -161,6 +161,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$3.00"},
|
||||
{"Estimated Strategy Capacity", "$74000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0.327"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
|
||||
@@ -28,11 +28,11 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
_symbol = AddEquity("SPY").Symbol;
|
||||
}
|
||||
|
||||
public override void OnEndOfDay()
|
||||
public override void OnEndOfDay(Symbol symbol)
|
||||
{
|
||||
var minuteHistory = History(_symbol, 60, Resolution.Minute);
|
||||
var minuteHistory = History(symbol, 60, Resolution.Minute);
|
||||
var lastHourHigh = minuteHistory.Select(minuteBar => minuteBar.High).DefaultIfEmpty(0).Max();
|
||||
var dailyHistory = History(_symbol, 1, Resolution.Daily).First();
|
||||
var dailyHistory = History(symbol, 1, Resolution.Daily).First();
|
||||
var dailyHigh = dailyHistory.High;
|
||||
var dailyLow = dailyHistory.Low;
|
||||
var dailyOpen = dailyHistory.Open;
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.09"},
|
||||
{"Treynor Ratio", "0.82"},
|
||||
{"Total Fees", "$41.70"},
|
||||
{"Estimated Strategy Capacity", "$3000000.00"},
|
||||
{"Fitness Score", "0.634"},
|
||||
{"Kelly Criterion Estimate", "13.656"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
|
||||
@@ -155,6 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Treynor Ratio", "7.887"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -147,6 +147,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$370000.00"},
|
||||
{"Fitness Score", "0.501"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
102
Algorithm.CSharp/CapacityTests/BeastVsPenny.cs
Normal file
102
Algorithm.CSharp/CapacityTests/BeastVsPenny.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests capacity by trading SPY (beast) alongside a small cap stock ABUS (penny)
|
||||
/// </summary>
|
||||
public class BeastVsPenny : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 3, 31);
|
||||
SetCash(10000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
var penny = AddEquity("ABUS", Resolution.Hour).Symbol;
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
|
||||
{
|
||||
SetHoldings(_spy, 0.5m);
|
||||
SetHoldings(penny, 0.5m);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "70"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.51%"},
|
||||
{"Compounding Annual Return", "-89.548%"},
|
||||
{"Drawdown", "49.900%"},
|
||||
{"Expectancy", "-0.514"},
|
||||
{"Net Profit", "-42.920%"},
|
||||
{"Sharpe Ratio", "-0.797"},
|
||||
{"Probabilistic Sharpe Ratio", "9.019%"},
|
||||
{"Loss Rate", "57%"},
|
||||
{"Win Rate", "43%"},
|
||||
{"Profit-Loss Ratio", "0.13"},
|
||||
{"Alpha", "-0.24"},
|
||||
{"Beta", "1.101"},
|
||||
{"Annual Standard Deviation", "1.031"},
|
||||
{"Annual Variance", "1.063"},
|
||||
{"Information Ratio", "-0.351"},
|
||||
{"Tracking Error", "0.836"},
|
||||
{"Treynor Ratio", "-0.747"},
|
||||
{"Total Fees", "$81.45"},
|
||||
{"Estimated Strategy Capacity", "$21000.00"},
|
||||
{"Fitness Score", "0.01"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.284"},
|
||||
{"Return Over Maximum Drawdown", "-1.789"},
|
||||
{"Portfolio Turnover", "0.038"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "67c9083f604ed16fb68481e7c26878dc"}
|
||||
};
|
||||
}
|
||||
}
|
||||
147
Algorithm.CSharp/CapacityTests/CheeseMilkHourlyRebalance.cs
Normal file
147
Algorithm.CSharp/CapacityTests/CheeseMilkHourlyRebalance.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.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests an illiquid asset that has bursts of liquidity around 11:00 A.M. Central Time
|
||||
/// with an hourly in and out strategy.
|
||||
/// </summary>
|
||||
public class CheeseMilkHourlyRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
private Symbol _contract;
|
||||
private DateTime _lastTrade;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 2, 17);
|
||||
SetTimeZone(TimeZones.Chicago);
|
||||
SetCash(100000);
|
||||
SetWarmup(1000);
|
||||
|
||||
var dc = AddFuture("DC", Resolution.Minute, Market.CME);
|
||||
dc.SetFilter(0, 10000);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var contract = data.FutureChains.Values.SelectMany(c => c.Contracts.Values)
|
||||
.OrderBy(c => c.Symbol.ID.Date)
|
||||
.FirstOrDefault()?
|
||||
.Symbol;
|
||||
|
||||
if (contract == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_contract != contract || (_fast == null && _slow == null))
|
||||
{
|
||||
_fast = EMA(contract, 600);
|
||||
_slow = EMA(contract, 1200);
|
||||
_contract = contract;
|
||||
}
|
||||
|
||||
if (!_fast.IsReady || !_slow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Time - _lastTrade <= TimeSpan.FromHours(1) || Time.TimeOfDay <= new TimeSpan(10, 50, 0) || Time.TimeOfDay >= new TimeSpan(12, 30, 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
|
||||
{
|
||||
SetHoldings(contract, 0.5);
|
||||
_lastTrade = Time;
|
||||
}
|
||||
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(contract, -0.5);
|
||||
_lastTrade = Time;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "19"},
|
||||
{"Average Win", "39.16%"},
|
||||
{"Average Loss", "-8.81%"},
|
||||
{"Compounding Annual Return", "-99.857%"},
|
||||
{"Drawdown", "82.900%"},
|
||||
{"Expectancy", "-0.359"},
|
||||
{"Net Profit", "-57.725%"},
|
||||
{"Sharpe Ratio", "-0.555"},
|
||||
{"Probabilistic Sharpe Ratio", "10.606%"},
|
||||
{"Loss Rate", "88%"},
|
||||
{"Win Rate", "12%"},
|
||||
{"Profit-Loss Ratio", "4.45"},
|
||||
{"Alpha", "-1.188"},
|
||||
{"Beta", "0.603"},
|
||||
{"Annual Standard Deviation", "1.754"},
|
||||
{"Annual Variance", "3.075"},
|
||||
{"Information Ratio", "-0.759"},
|
||||
{"Tracking Error", "1.753"},
|
||||
{"Treynor Ratio", "-1.612"},
|
||||
{"Total Fees", "$2558.55"},
|
||||
{"Estimated Strategy Capacity", "$20000.00"},
|
||||
{"Fitness Score", "0.351"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.602"},
|
||||
{"Return Over Maximum Drawdown", "-1.415"},
|
||||
{"Portfolio Turnover", "14.226"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4f5fd2fb25e957bd0cb7cb6d275ddb97"}
|
||||
};
|
||||
}
|
||||
}
|
||||
231
Algorithm.CSharp/CapacityTests/EmaPortfolioRebalance100.cs
Normal file
231
Algorithm.CSharp/CapacityTests/EmaPortfolioRebalance100.cs
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests a wide variety of liquid and illiquid stocks together, with bins
|
||||
/// of 20 ranging from micro-cap to mega-cap stocks.
|
||||
/// </summary>
|
||||
public class EmaPortfolioRebalance100 : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public List<SymbolData> Data;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 2, 5);
|
||||
SetWarmup(1000);
|
||||
SetCash(100000);
|
||||
|
||||
Data = new List<SymbolData> {
|
||||
new SymbolData(this, AddEquity("AADR", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAMC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAU", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABDC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABIO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACER", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACES", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACGLO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACH", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACHV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIU", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACNB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACRS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACSI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACTG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZYNE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZYME", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZUO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZUMZ", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZTR", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZSL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZSAN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZROZ", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZLAB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIXI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZIOP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZGNX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZEUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZAGG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YYY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YRD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YRCW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YPF", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAXN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ABC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACAD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACGL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACIW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACWV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ACWX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADPT", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADUS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AEP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ZTS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("YUM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLV", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLRE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLP", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLNX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLF", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XLB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XEL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("XBI", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("X", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WYNN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WW", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WORK", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WMB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WELL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("WEC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AAPL", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("ADBE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AGG", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AMD", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("AMZN", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BABA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BAC", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("BMY", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("C", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CMCSA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CRM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("CSCO", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("DIS", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("EEM", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("EFA", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("FB", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("GDX", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("GE", Resolution.Minute).Symbol),
|
||||
new SymbolData(this, AddEquity("SPY", Resolution.Minute).Symbol)
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var fastFactor = 0.005m;
|
||||
|
||||
foreach (var sd in Data)
|
||||
{
|
||||
if (!Portfolio.Invested && sd.Fast * (1 + fastFactor) > sd.Slow)
|
||||
{
|
||||
SetHoldings(sd.Symbol, 0.01);
|
||||
}
|
||||
else if (Portfolio.Invested && sd.Fast * (1 - fastFactor) < sd.Slow)
|
||||
{
|
||||
Liquidate(sd.Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SymbolData
|
||||
{
|
||||
public Symbol Symbol;
|
||||
public ExponentialMovingAverage Fast;
|
||||
public ExponentialMovingAverage Slow;
|
||||
public bool IsCrossed => Fast > Slow;
|
||||
|
||||
public SymbolData(QCAlgorithm algorithm, Symbol symbol) {
|
||||
Symbol = symbol;
|
||||
Fast = algorithm.EMA(symbol, 20);
|
||||
Slow = algorithm.EMA(symbol, 300);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "1015"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-12.674%"},
|
||||
{"Drawdown", "1.400%"},
|
||||
{"Expectancy", "-0.761"},
|
||||
{"Net Profit", "-1.328%"},
|
||||
{"Sharpe Ratio", "-12.258"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "95%"},
|
||||
{"Win Rate", "5%"},
|
||||
{"Profit-Loss Ratio", "3.67"},
|
||||
{"Alpha", "-0.142"},
|
||||
{"Beta", "0.038"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-4.389"},
|
||||
{"Tracking Error", "0.123"},
|
||||
{"Treynor Ratio", "-3.359"},
|
||||
{"Total Fees", "$1125.52"},
|
||||
{"Estimated Strategy Capacity", "$300.00"},
|
||||
{"Fitness Score", "0.007"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-14.315"},
|
||||
{"Return Over Maximum Drawdown", "-9.589"},
|
||||
{"Portfolio Turnover", "0.406"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4c165e8d648d54a85bb7b564050a6f85"}
|
||||
};
|
||||
}
|
||||
}
|
||||
117
Algorithm.CSharp/CapacityTests/IntradayMinuteScalping.cs
Normal file
117
Algorithm.CSharp/CapacityTests/IntradayMinuteScalping.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps SPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests equity strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalping : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Minute).Symbol;
|
||||
_fast = EMA(_spy, 20);
|
||||
_slow = EMA(_spy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Portfolio[_spy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_spy, 1);
|
||||
}
|
||||
else if (Portfolio[_spy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_spy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "150"},
|
||||
{"Average Win", "0.16%"},
|
||||
{"Average Loss", "-0.11%"},
|
||||
{"Compounding Annual Return", "-19.320%"},
|
||||
{"Drawdown", "3.900%"},
|
||||
{"Expectancy", "-0.193"},
|
||||
{"Net Profit", "-1.730%"},
|
||||
{"Sharpe Ratio", "-1.606"},
|
||||
{"Probabilistic Sharpe Ratio", "21.397%"},
|
||||
{"Loss Rate", "67%"},
|
||||
{"Win Rate", "33%"},
|
||||
{"Profit-Loss Ratio", "1.45"},
|
||||
{"Alpha", "-0.357"},
|
||||
{"Beta", "0.635"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "-4.249"},
|
||||
{"Tracking Error", "0.106"},
|
||||
{"Treynor Ratio", "-0.302"},
|
||||
{"Total Fees", "$449.14"},
|
||||
{"Estimated Strategy Capacity", "$27000000.00"},
|
||||
{"Fitness Score", "0.088"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-3.259"},
|
||||
{"Return Over Maximum Drawdown", "-7.992"},
|
||||
{"Portfolio Turnover", "14.605"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f5a0e9547f7455004fa6c3eb136534e9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
123
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingBTCETH.cs
Normal file
123
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingBTCETH.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps BTCETH using an EMA cross strategy at minute resolution.
|
||||
/// This tests crypto strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This also tests
|
||||
/// that currency conversions are handled properly in the strategy capacity
|
||||
/// calculation class.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingBTCETH : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _ethbtc;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
var ethbtc = AddCrypto("ETHBTC", Resolution.Minute, Market.GDAX);
|
||||
ethbtc.BuyingPowerModel = new BuyingPowerModel();
|
||||
_ethbtc = ethbtc.Symbol;
|
||||
|
||||
_fast = EMA(_ethbtc, 20);
|
||||
_slow = EMA(_ethbtc, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Portfolio[_ethbtc].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_ethbtc, 1);
|
||||
}
|
||||
else if (Portfolio[_ethbtc].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_ethbtc, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "1005"},
|
||||
{"Average Win", "0.96%"},
|
||||
{"Average Loss", "-0.33%"},
|
||||
{"Compounding Annual Return", "76.267%"},
|
||||
{"Drawdown", "77.100%"},
|
||||
{"Expectancy", "-0.012"},
|
||||
{"Net Profit", "4.768%"},
|
||||
{"Sharpe Ratio", "1.01909630017278E+24"},
|
||||
{"Probabilistic Sharpe Ratio", "93.814%"},
|
||||
{"Loss Rate", "75%"},
|
||||
{"Win Rate", "25%"},
|
||||
{"Profit-Loss Ratio", "2.95"},
|
||||
{"Alpha", "1.3466330963256E+25"},
|
||||
{"Beta", "25.59"},
|
||||
{"Annual Standard Deviation", "13.214"},
|
||||
{"Annual Variance", "174.61"},
|
||||
{"Information Ratio", "1.02164274756513E+24"},
|
||||
{"Tracking Error", "13.181"},
|
||||
{"Treynor Ratio", "5.2622435344112E+23"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$1300000.00"},
|
||||
{"Fitness Score", "0.38"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.239"},
|
||||
{"Return Over Maximum Drawdown", "-1.385"},
|
||||
{"Portfolio Turnover", "81.433"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6a779e7a8d12b4808845c75b88d43b3a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
117
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingEURUSD.cs
Normal file
117
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingEURUSD.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps EURUSD using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingEURUSD : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _eurusd;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_eurusd = AddForex("EURUSD", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_eurusd, 20);
|
||||
_slow = EMA(_eurusd, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Portfolio[_eurusd].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_eurusd, 1);
|
||||
}
|
||||
else if (Portfolio[_eurusd].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_eurusd, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "671"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.04%"},
|
||||
{"Compounding Annual Return", "-80.820%"},
|
||||
{"Drawdown", "12.200%"},
|
||||
{"Expectancy", "-0.447"},
|
||||
{"Net Profit", "-12.180%"},
|
||||
{"Sharpe Ratio", "-13.121"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "79%"},
|
||||
{"Win Rate", "21%"},
|
||||
{"Profit-Loss Ratio", "1.61"},
|
||||
{"Alpha", "-0.746"},
|
||||
{"Beta", "-0.02"},
|
||||
{"Annual Standard Deviation", "0.057"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-4.046"},
|
||||
{"Tracking Error", "0.161"},
|
||||
{"Treynor Ratio", "37.346"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$44000000.00"},
|
||||
{"Fitness Score", "0.025"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-16.609"},
|
||||
{"Return Over Maximum Drawdown", "-7.115"},
|
||||
{"Portfolio Turnover", "52.476"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "74ee44736b9300c0262dc75c0cd140e1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps ES futures contracts (E-mini SP500) using an EMA cross strategy at minute resolution.
|
||||
/// This tests futures strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The insanely high capacity estimate of this strategy is realistic.
|
||||
/// ES notional contract value traded is around $600 Billion USD per day (!!!), which
|
||||
/// is what the capacity is set to.
|
||||
/// </remarks>
|
||||
public class IntradayMinuteScalpingFuturesES : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
private Symbol _contract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 31);
|
||||
SetCash(100000);
|
||||
SetWarmup(1000);
|
||||
|
||||
var a = AddFuture("ES", Resolution.Minute, Market.CME);
|
||||
a.SetFilter(0, 10000);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var contract = data.FutureChains.Values.SelectMany(c => c.Contracts.Values)
|
||||
.OrderBy(c => c.Symbol.ID.Date)
|
||||
.FirstOrDefault()?
|
||||
.Symbol;
|
||||
|
||||
if (contract == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_contract != contract || (_fast == null && _slow == null))
|
||||
{
|
||||
_fast = EMA(contract, 10);
|
||||
_slow = EMA(contract, 20);
|
||||
_contract = contract;
|
||||
}
|
||||
|
||||
if (!_fast.IsReady || !_slow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Portfolio.ContainsKey(contract) || (Portfolio[contract].Quantity <= 0 && _fast > _slow))
|
||||
{
|
||||
SetHoldings(contract, 1);
|
||||
}
|
||||
else if (Portfolio.ContainsKey(contract) && Portfolio[contract].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(contract, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "1217"},
|
||||
{"Average Win", "2.69%"},
|
||||
{"Average Loss", "-0.93%"},
|
||||
{"Compounding Annual Return", "-99.756%"},
|
||||
{"Drawdown", "77.200%"},
|
||||
{"Expectancy", "-0.047"},
|
||||
{"Net Profit", "-40.013%"},
|
||||
{"Sharpe Ratio", "-0.52"},
|
||||
{"Probabilistic Sharpe Ratio", "19.865%"},
|
||||
{"Loss Rate", "75%"},
|
||||
{"Win Rate", "25%"},
|
||||
{"Profit-Loss Ratio", "2.88"},
|
||||
{"Alpha", "-1.279"},
|
||||
{"Beta", "-3.686"},
|
||||
{"Annual Standard Deviation", "1.85"},
|
||||
{"Annual Variance", "3.422"},
|
||||
{"Information Ratio", "-0.463"},
|
||||
{"Tracking Error", "1.895"},
|
||||
{"Treynor Ratio", "0.261"},
|
||||
{"Total Fees", "$19843.10"},
|
||||
{"Estimated Strategy Capacity", "$560000000.00"},
|
||||
{"Fitness Score", "0.334"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.837"},
|
||||
{"Return Over Maximum Drawdown", "-1.402"},
|
||||
{"Portfolio Turnover", "1174.125"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f353843132df7b0604eff3a37b134ca2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
118
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingGBPJPY.cs
Normal file
118
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingGBPJPY.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps GBPJPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This test also
|
||||
/// tests that currency conversion rates are applied and calculated correctly.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingGBPJPY : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _gbpjpy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_gbpjpy = AddForex("GBPJPY", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_gbpjpy, 20);
|
||||
_slow = EMA(_gbpjpy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Portfolio[_gbpjpy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_gbpjpy, 1);
|
||||
}
|
||||
else if (Portfolio[_gbpjpy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_gbpjpy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "735"},
|
||||
{"Average Win", "0.08%"},
|
||||
{"Average Loss", "-0.05%"},
|
||||
{"Compounding Annual Return", "-93.946%"},
|
||||
{"Drawdown", "19.900%"},
|
||||
{"Expectancy", "-0.592"},
|
||||
{"Net Profit", "-19.794%"},
|
||||
{"Sharpe Ratio", "-10.054"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "84%"},
|
||||
{"Win Rate", "16%"},
|
||||
{"Profit-Loss Ratio", "1.56"},
|
||||
{"Alpha", "-0.895"},
|
||||
{"Beta", "0.068"},
|
||||
{"Annual Standard Deviation", "0.09"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "-4.929"},
|
||||
{"Tracking Error", "0.164"},
|
||||
{"Treynor Ratio", "-13.276"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$49000000.00"},
|
||||
{"Fitness Score", "0.049"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-10.846"},
|
||||
{"Return Over Maximum Drawdown", "-4.904"},
|
||||
{"Portfolio Turnover", "58.921"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "66f04c9622ab242993c8ce951418e6d9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
118
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingTRYJPY.cs
Normal file
118
Algorithm.CSharp/CapacityTests/IntradayMinuteScalpingTRYJPY.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Scalps TRYJPY using an EMA cross strategy at minute resolution.
|
||||
/// This tests FOREX strategies that trade at a higher frequency, which
|
||||
/// should have a reduced capacity estimate as a result. This tests that
|
||||
/// currency conversions are applied properly to the capacity estimate calculation.
|
||||
/// </summary>
|
||||
public class IntradayMinuteScalpingTRYJPY : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _tryjpy;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2021, 1, 1);
|
||||
SetEndDate(2021, 1, 30);
|
||||
SetCash(100000);
|
||||
SetWarmup(100);
|
||||
|
||||
_tryjpy = AddForex("TRYJPY", Resolution.Minute, Market.Oanda).Symbol;
|
||||
_fast = EMA(_tryjpy, 20);
|
||||
_slow = EMA(_tryjpy, 40);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Portfolio[_tryjpy].Quantity <= 0 && _fast > _slow)
|
||||
{
|
||||
SetHoldings(_tryjpy, 1);
|
||||
}
|
||||
else if (Portfolio[_tryjpy].Quantity >= 0 && _fast < _slow)
|
||||
{
|
||||
SetHoldings(_tryjpy, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "603"},
|
||||
{"Average Win", "0.20%"},
|
||||
{"Average Loss", "-0.26%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "73.200%"},
|
||||
{"Expectancy", "-0.849"},
|
||||
{"Net Profit", "-73.118%"},
|
||||
{"Sharpe Ratio", "-2.046"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "91%"},
|
||||
{"Win Rate", "9%"},
|
||||
{"Profit-Loss Ratio", "0.75"},
|
||||
{"Alpha", "-0.95"},
|
||||
{"Beta", "0.541"},
|
||||
{"Annual Standard Deviation", "0.489"},
|
||||
{"Annual Variance", "0.239"},
|
||||
{"Information Ratio", "-1.863"},
|
||||
{"Tracking Error", "0.487"},
|
||||
{"Treynor Ratio", "-1.849"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$4400000.00"},
|
||||
{"Fitness Score", "0.259"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.135"},
|
||||
{"Return Over Maximum Drawdown", "-1.389"},
|
||||
{"Portfolio Turnover", "49.501"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4eb4d703a9f200b6bb3d8b0ebbc9db7f"}
|
||||
};
|
||||
}
|
||||
}
|
||||
111
Algorithm.CSharp/CapacityTests/MonthlyRebalanceDaily.cs
Normal file
111
Algorithm.CSharp/CapacityTests/MonthlyRebalanceDaily.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 System.Collections.Generic;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances ultra-liquid stocks monthly, testing
|
||||
/// bursts of orders centered around the start of the month at Daily resolution
|
||||
/// </summary>
|
||||
public class MonthlyRebalanceDaily : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 12, 31);
|
||||
SetEndDate(2020, 4, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var spy = AddEquity("SPY", Resolution.Daily).Symbol;
|
||||
AddEquity("GE", Resolution.Daily);
|
||||
AddEquity("FB", Resolution.Daily);
|
||||
AddEquity("DIS", Resolution.Daily);
|
||||
AddEquity("CSCO", Resolution.Daily);
|
||||
AddEquity("CRM", Resolution.Daily);
|
||||
AddEquity("C", Resolution.Daily);
|
||||
AddEquity("BAC", Resolution.Daily);
|
||||
AddEquity("BABA", Resolution.Daily);
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
|
||||
{
|
||||
foreach (var symbol in Securities.Keys)
|
||||
{
|
||||
SetHoldings(symbol, 0.10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "35"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.07%"},
|
||||
{"Compounding Annual Return", "-68.407%"},
|
||||
{"Drawdown", "32.400%"},
|
||||
{"Expectancy", "-0.309"},
|
||||
{"Net Profit", "-25.901%"},
|
||||
{"Sharpe Ratio", "-1.503"},
|
||||
{"Probabilistic Sharpe Ratio", "2.878%"},
|
||||
{"Loss Rate", "64%"},
|
||||
{"Win Rate", "36%"},
|
||||
{"Profit-Loss Ratio", "0.90"},
|
||||
{"Alpha", "-0.7"},
|
||||
{"Beta", "-0.238"},
|
||||
{"Annual Standard Deviation", "0.386"},
|
||||
{"Annual Variance", "0.149"},
|
||||
{"Information Ratio", "-0.11"},
|
||||
{"Tracking Error", "0.712"},
|
||||
{"Treynor Ratio", "2.442"},
|
||||
{"Total Fees", "$38.99"},
|
||||
{"Estimated Strategy Capacity", "$19000000.00"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.021"},
|
||||
{"Return Over Maximum Drawdown", "-2.113"},
|
||||
{"Portfolio Turnover", "0.014"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "76d8164a3c0d4a7d45e94367c4ba5be1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
111
Algorithm.CSharp/CapacityTests/MonthlyRebalanceHourly.cs
Normal file
111
Algorithm.CSharp/CapacityTests/MonthlyRebalanceHourly.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 System.Collections.Generic;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances ultra-liquid stocks monthly, testing
|
||||
/// bursts of orders centered around the start of the month at Hourly resolution
|
||||
/// </summary>
|
||||
public class MonthlyRebalanceHourly : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 12, 31);
|
||||
SetEndDate(2020, 4, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
AddEquity("GE", Resolution.Hour);
|
||||
AddEquity("FB", Resolution.Hour);
|
||||
AddEquity("DIS", Resolution.Hour);
|
||||
AddEquity("CSCO", Resolution.Hour);
|
||||
AddEquity("CRM", Resolution.Hour);
|
||||
AddEquity("C", Resolution.Hour);
|
||||
AddEquity("BAC", Resolution.Hour);
|
||||
AddEquity("BABA", Resolution.Hour);
|
||||
AddEquity("AAPL", Resolution.Hour);
|
||||
|
||||
Schedule.On(DateRules.MonthStart(spy), TimeRules.Noon, () =>
|
||||
{
|
||||
foreach (var symbol in Securities.Keys)
|
||||
{
|
||||
SetHoldings(symbol, 0.10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "35"},
|
||||
{"Average Win", "0.05%"},
|
||||
{"Average Loss", "-0.10%"},
|
||||
{"Compounding Annual Return", "-72.444%"},
|
||||
{"Drawdown", "36.500%"},
|
||||
{"Expectancy", "-0.449"},
|
||||
{"Net Profit", "-28.406%"},
|
||||
{"Sharpe Ratio", "-1.369"},
|
||||
{"Probabilistic Sharpe Ratio", "4.398%"},
|
||||
{"Loss Rate", "64%"},
|
||||
{"Win Rate", "36%"},
|
||||
{"Profit-Loss Ratio", "0.51"},
|
||||
{"Alpha", "-0.175"},
|
||||
{"Beta", "0.892"},
|
||||
{"Annual Standard Deviation", "0.503"},
|
||||
{"Annual Variance", "0.253"},
|
||||
{"Information Ratio", "-0.822"},
|
||||
{"Tracking Error", "0.138"},
|
||||
{"Treynor Ratio", "-0.772"},
|
||||
{"Total Fees", "$38.83"},
|
||||
{"Estimated Strategy Capacity", "$6000000.00"},
|
||||
{"Fitness Score", "0.004"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.033"},
|
||||
{"Return Over Maximum Drawdown", "-2.079"},
|
||||
{"Portfolio Turnover", "0.018"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1de9bcf6cda0945af6ba1f74c4dcb22c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
112
Algorithm.CSharp/CapacityTests/SplitTestingStrategy.cs
Normal file
112
Algorithm.CSharp/CapacityTests/SplitTestingStrategy.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that splits do not cause the algorithm to report capacity estimates
|
||||
/// above or below the actual capacity due to splits. The stock HTGM is illiquid,
|
||||
/// trading only $1.2 Million per day on average with sparse trade frequencies.
|
||||
/// </summary>
|
||||
public class SplitTestingStrategy : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _htgm;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 11, 1);
|
||||
SetEndDate(2020, 12, 5);
|
||||
SetCash(100000);
|
||||
|
||||
var htgm = AddEquity("HTGM", Resolution.Hour);
|
||||
htgm.SetDataNormalizationMode(DataNormalizationMode.Raw);
|
||||
_htgm = htgm.Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_htgm, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetHoldings(_htgm, -1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "162"},
|
||||
{"Average Win", "0.10%"},
|
||||
{"Average Loss", "-0.35%"},
|
||||
{"Compounding Annual Return", "-94.432%"},
|
||||
{"Drawdown", "30.400%"},
|
||||
{"Expectancy", "-0.564"},
|
||||
{"Net Profit", "-23.412%"},
|
||||
{"Sharpe Ratio", "-1.041"},
|
||||
{"Probabilistic Sharpe Ratio", "12.971%"},
|
||||
{"Loss Rate", "66%"},
|
||||
{"Win Rate", "34%"},
|
||||
{"Profit-Loss Ratio", "0.29"},
|
||||
{"Alpha", "-4.827"},
|
||||
{"Beta", "1.43"},
|
||||
{"Annual Standard Deviation", "0.876"},
|
||||
{"Annual Variance", "0.767"},
|
||||
{"Information Ratio", "-4.288"},
|
||||
{"Tracking Error", "0.851"},
|
||||
{"Treynor Ratio", "-0.637"},
|
||||
{"Total Fees", "$2655.91"},
|
||||
{"Estimated Strategy Capacity", "$11000.00"},
|
||||
{"Fitness Score", "0.052"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.2"},
|
||||
{"Return Over Maximum Drawdown", "-3.481"},
|
||||
{"Portfolio Turnover", "0.307"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "54f571c11525656e9b383e235e77002e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
103
Algorithm.CSharp/CapacityTests/SpyBondPortfolioRebalance.cs
Normal file
103
Algorithm.CSharp/CapacityTests/SpyBondPortfolioRebalance.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Rebalances between SPY and BND. Tests capacity of the weakest link, which in this
|
||||
/// case is BND, dragging down the capacity estimate.
|
||||
/// </summary>
|
||||
public class SpyBondPortfolioRebalance : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 1);
|
||||
SetEndDate(2020, 3, 31);
|
||||
SetCash(10000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
var bnd = AddEquity("BND", Resolution.Hour).Symbol;
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 1, false), () =>
|
||||
{
|
||||
SetHoldings(_spy, 0.5m);
|
||||
SetHoldings(bnd, 0.5m);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public 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", "21"},
|
||||
{"Average Win", "0.02%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "-33.564%"},
|
||||
{"Drawdown", "19.700%"},
|
||||
{"Expectancy", "-0.140"},
|
||||
{"Net Profit", "-9.655%"},
|
||||
{"Sharpe Ratio", "-0.99"},
|
||||
{"Probabilistic Sharpe Ratio", "13.754%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.72"},
|
||||
{"Alpha", "-0.022"},
|
||||
{"Beta", "0.538"},
|
||||
{"Annual Standard Deviation", "0.309"},
|
||||
{"Annual Variance", "0.096"},
|
||||
{"Information Ratio", "0.826"},
|
||||
{"Tracking Error", "0.269"},
|
||||
{"Treynor Ratio", "-0.569"},
|
||||
{"Total Fees", "$21.00"},
|
||||
{"Estimated Strategy Capacity", "$1100000.00"},
|
||||
{"Fitness Score", "0.005"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.524"},
|
||||
{"Return Over Maximum Drawdown", "-1.688"},
|
||||
{"Portfolio Turnover", "0.02"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "95a130426900aaf227a08a5d1c617b2b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.5"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -181,6 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.149"},
|
||||
{"Treynor Ratio", "-1.405"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$42000000.00"},
|
||||
{"Fitness Score", "0.076"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -164,6 +164,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "3.579"},
|
||||
{"Treynor Ratio", "383485597312030"},
|
||||
{"Total Fees", "$13.00"},
|
||||
{"Estimated Strategy Capacity", "$3000000.00"},
|
||||
{"Fitness Score", "0.232"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -136,6 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.126"},
|
||||
{"Treynor Ratio", "-0.607"},
|
||||
{"Total Fees", "$11.63"},
|
||||
{"Estimated Strategy Capacity", "$46000000.00"},
|
||||
{"Fitness Score", "0.013"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -114,6 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.096"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.105"},
|
||||
{"Treynor Ratio", "1.667"},
|
||||
{"Total Fees", "$2.91"},
|
||||
{"Estimated Strategy Capacity", "$670000000.00"},
|
||||
{"Fitness Score", "0.141"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -91,6 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.101"},
|
||||
{"Treynor Ratio", "5.409"},
|
||||
{"Total Fees", "$67.00"},
|
||||
{"Estimated Strategy Capacity", "$3200000.00"},
|
||||
{"Fitness Score", "0.501"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -85,6 +85,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.009"},
|
||||
{"Treynor Ratio", "1.575"},
|
||||
{"Total Fees", "$22.77"},
|
||||
{"Estimated Strategy Capacity", "$22000000.00"},
|
||||
{"Fitness Score", "0.999"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.165"},
|
||||
{"Treynor Ratio", "1.212"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Estimated Strategy Capacity", "$42000000.00"},
|
||||
{"Fitness Score", "0.063"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
|
||||
@@ -164,6 +164,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.441"},
|
||||
{"Treynor Ratio", "-0.008"},
|
||||
{"Total Fees", "$20.35"},
|
||||
{"Estimated Strategy Capacity", "$19000000.00"},
|
||||
{"Fitness Score", "0.138"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -190,6 +190,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "-1.46"},
|
||||
{"Total Fees", "$7.82"},
|
||||
{"Estimated Strategy Capacity", "$12000000.00"},
|
||||
{"Fitness Score", "0.1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -146,6 +146,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.239"},
|
||||
{"Treynor Ratio", "-1.435"},
|
||||
{"Total Fees", "$755.29"},
|
||||
{"Estimated Strategy Capacity", "$1100000000.00"},
|
||||
{"Fitness Score", "0.024"},
|
||||
{"Kelly Criterion Estimate", "-0.84"},
|
||||
{"Kelly Criterion Probability Value", "0.53"},
|
||||
|
||||
@@ -99,6 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.168"},
|
||||
{"Treynor Ratio", "2.38"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Estimated Strategy Capacity", "$300000000.00"},
|
||||
{"Fitness Score", "0.245"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -96,6 +96,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0.988"},
|
||||
{"Total Fees", "$7.78"},
|
||||
{"Estimated Strategy Capacity", "$8700000.00"},
|
||||
{"Fitness Score", "0.031"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
security.SetBuyingPowerModel(new CustomBuyingPowerModel());
|
||||
}
|
||||
|
||||
public void OnData(Slice slice)
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (Portfolio.Invested)
|
||||
{
|
||||
@@ -113,6 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "1.04"},
|
||||
{"Treynor Ratio", "5.073"},
|
||||
{"Total Fees", "$30.00"},
|
||||
{"Estimated Strategy Capacity", "$20000000.00"},
|
||||
{"Fitness Score", "0.418"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// OnEndOfDay Event Handler - At the end of each trading day we fire this code.
|
||||
/// To avoid flooding, we recommend running your plotting at the end of each day.
|
||||
/// </summary>
|
||||
public override void OnEndOfDay()
|
||||
public override void OnEndOfDay(Symbol symbol)
|
||||
{
|
||||
//Log the end of day prices:
|
||||
Plot("Trade Plot", "Price", _lastPrice);
|
||||
|
||||
@@ -119,6 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "-6.121"},
|
||||
{"Total Fees", "$3.50"},
|
||||
{"Estimated Strategy Capacity", "$48000000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -124,6 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "-6.121"},
|
||||
{"Total Fees", "$3.50"},
|
||||
{"Estimated Strategy Capacity", "$48000000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.19"},
|
||||
{"Treynor Ratio", "2.159"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Estimated Strategy Capacity", "$58000000.00"},
|
||||
{"Fitness Score", "0.1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -58,7 +58,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
//Weather used as a tradable asset, like stocks, futures etc.
|
||||
if (data.Close != 0)
|
||||
{
|
||||
Order("BTC", (Portfolio.MarginRemaining / Math.Abs(data.Close + 1)));
|
||||
// It's only OK to use SetHoldings with crypto when using custom data. When trading with built-in crypto data,
|
||||
// use the cashbook. Reference https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/BasicTemplateCryptoAlgorithm.py
|
||||
SetHoldings("BTC", 1);
|
||||
}
|
||||
Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close);
|
||||
}
|
||||
@@ -117,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
//return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip";
|
||||
// OR simply return a fixed small data file. Large files will slow down your backtest
|
||||
return new SubscriptionDataSource("https://www.quandl.com/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc", SubscriptionTransportMedium.RemoteFile);
|
||||
return new SubscriptionDataSource("https://www.quantconnect.com/api/v2/proxy/quandl/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc&api_key=WyAazVXnq7ATy_fefTqm", SubscriptionTransportMedium.RemoteFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,6 +156,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
string[] data = line.Split(',');
|
||||
coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
coin.EndTime = coin.Time.AddDays(1);
|
||||
coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
|
||||
coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// "Nifty" type below and fired into this event handler.
|
||||
/// </summary>
|
||||
/// <param name="data">One(1) Nifty Object, streamed into our algorithm synchronised in time with our other data streams</param>
|
||||
public void OnData(Slice data)
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.ContainsKey("USDINR"))
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
|
||||
_today.NiftyPrice = Convert.ToDouble(data["NIFTY"].Close);
|
||||
if (_today.Date == data["NIFTY"].EndTime)
|
||||
if (_today.Date == data["NIFTY"].Time)
|
||||
{
|
||||
_prices.Add(_today);
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var quantity = (int)(Portfolio.MarginRemaining * 0.9m / data["NIFTY"].Close);
|
||||
var highestNifty = (from pair in _prices select pair.NiftyPrice).Max();
|
||||
var lowestNifty = (from pair in _prices select pair.NiftyPrice).Min();
|
||||
|
||||
|
||||
if (Time.DayOfWeek == DayOfWeek.Wednesday) //prices.Count >= minimumCorrelationHistory &&
|
||||
{
|
||||
//List<double> niftyPrices = (from pair in prices select pair.NiftyPrice).ToList();
|
||||
@@ -121,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// End of a trading day event handler. This method is called at the end of the algorithm day (or multiple times if trading multiple assets).
|
||||
/// </summary>
|
||||
/// <remarks>Method is called 10 minutes before closing to allow user to close out position.</remarks>
|
||||
public override void OnEndOfDay()
|
||||
public override void OnEndOfDay(Symbol symbol)
|
||||
{
|
||||
Plot("Nifty Closing Price", _today.NiftyPrice);
|
||||
}
|
||||
@@ -181,6 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
//2011-09-13 7792.9 7799.9 7722.65 7748.7 116534670 6107.78
|
||||
var data = line.Split(',');
|
||||
index.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
index.EndTime = index.Time.AddDays(1);
|
||||
index.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
index.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
|
||||
index.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
|
||||
@@ -247,6 +248,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
var data = line.Split(',');
|
||||
currency.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
currency.EndTime = currency.Time.AddDays(1);
|
||||
currency.Close = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
currency.Symbol = "USDINR";
|
||||
currency.Value = currency.Close;
|
||||
|
||||
@@ -114,28 +114,29 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "155.262%"},
|
||||
{"Compounding Annual Return", "157.498%"},
|
||||
{"Drawdown", "84.800%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "5123.242%"},
|
||||
{"Sharpe Ratio", "2.067"},
|
||||
{"Probabilistic Sharpe Ratio", "68.833%"},
|
||||
{"Net Profit", "5319.081%"},
|
||||
{"Sharpe Ratio", "2.086"},
|
||||
{"Probabilistic Sharpe Ratio", "69.456%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.732"},
|
||||
{"Beta", "0.037"},
|
||||
{"Annual Standard Deviation", "0.841"},
|
||||
{"Annual Variance", "0.707"},
|
||||
{"Information Ratio", "1.902"},
|
||||
{"Tracking Error", "0.848"},
|
||||
{"Treynor Ratio", "46.992"},
|
||||
{"Alpha", "1.736"},
|
||||
{"Beta", "0.136"},
|
||||
{"Annual Standard Deviation", "0.84"},
|
||||
{"Annual Variance", "0.706"},
|
||||
{"Information Ratio", "1.925"},
|
||||
{"Tracking Error", "0.846"},
|
||||
{"Treynor Ratio", "12.904"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "2.238"},
|
||||
{"Return Over Maximum Drawdown", "1.832"},
|
||||
{"Sortino Ratio", "2.269"},
|
||||
{"Return Over Maximum Drawdown", "1.858"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -150,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1f54fb75ebcc0daafa5d45bfbaa4fbcb"}
|
||||
{"OrderListHash", "0d80bb47bd16b5bc6989a4c1c7aa8349"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -242,6 +243,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
string[] data = line.Split(',');
|
||||
coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
coin.EndTime = coin.Time.AddDays(1);
|
||||
coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
|
||||
coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
|
||||
@@ -257,4 +259,4 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,28 +84,29 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "155.262%"},
|
||||
{"Compounding Annual Return", "157.497%"},
|
||||
{"Drawdown", "84.800%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "5123.170%"},
|
||||
{"Sharpe Ratio", "2.066"},
|
||||
{"Probabilistic Sharpe Ratio", "68.832%"},
|
||||
{"Net Profit", "5319.007%"},
|
||||
{"Sharpe Ratio", "2.086"},
|
||||
{"Probabilistic Sharpe Ratio", "69.456%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.732"},
|
||||
{"Beta", "0.037"},
|
||||
{"Annual Standard Deviation", "0.841"},
|
||||
{"Annual Variance", "0.707"},
|
||||
{"Information Ratio", "1.902"},
|
||||
{"Tracking Error", "0.848"},
|
||||
{"Treynor Ratio", "46.996"},
|
||||
{"Alpha", "1.736"},
|
||||
{"Beta", "0.136"},
|
||||
{"Annual Standard Deviation", "0.84"},
|
||||
{"Annual Variance", "0.706"},
|
||||
{"Information Ratio", "1.925"},
|
||||
{"Tracking Error", "0.846"},
|
||||
{"Treynor Ratio", "12.903"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "2.238"},
|
||||
{"Return Over Maximum Drawdown", "1.832"},
|
||||
{"Sortino Ratio", "2.269"},
|
||||
{"Return Over Maximum Drawdown", "1.858"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -120,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "0e7d560d0db2829adb19d3e403c30d97"}
|
||||
{"OrderListHash", "50faa37f15732bf5c24ad1eeaa335bc7"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -212,6 +213,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
string[] data = line.Split(',');
|
||||
coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
coin.EndTime = coin.Time.AddDays(1);
|
||||
coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
|
||||
coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
|
||||
@@ -227,4 +229,4 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.726"},
|
||||
{"Treynor Ratio", "0.142"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.127"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -212,6 +212,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.118"},
|
||||
{"Treynor Ratio", "-0.591"},
|
||||
{"Total Fees", "$62.24"},
|
||||
{"Estimated Strategy Capacity", "$49000000.00"},
|
||||
{"Fitness Score", "0.147"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.251"},
|
||||
{"Treynor Ratio", "9.323"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Estimated Strategy Capacity", "$890000000.00"},
|
||||
{"Fitness Score", "0.201"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -193,6 +193,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.211"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -118,6 +118,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.183"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -118,6 +118,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.212"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -136,6 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.08"},
|
||||
{"Treynor Ratio", "0.517"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Estimated Strategy Capacity", "$270000000.00"},
|
||||
{"Fitness Score", "0.019"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -160,6 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.155"},
|
||||
{"Treynor Ratio", "1.589"},
|
||||
{"Total Fees", "$55.05"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -123,6 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.115"},
|
||||
{"Treynor Ratio", "1.545"},
|
||||
{"Total Fees", "$37.00"},
|
||||
{"Estimated Strategy Capacity", "$400000.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -186,6 +186,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.204"},
|
||||
{"Treynor Ratio", "-8.165"},
|
||||
{"Total Fees", "$46.75"},
|
||||
{"Estimated Strategy Capacity", "$670000000.00"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -204,6 +204,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-1.761"},
|
||||
{"Total Fees", "$8669.41"},
|
||||
{"Estimated Strategy Capacity", "$320000.00"},
|
||||
{"Fitness Score", "0.675"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -177,6 +177,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-1.971"},
|
||||
{"Total Fees", "$6806.67"},
|
||||
{"Estimated Strategy Capacity", "$320000.00"},
|
||||
{"Fitness Score", "0.694"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -110,6 +110,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -91,6 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$14.92"},
|
||||
{"Estimated Strategy Capacity", "$85000.00"},
|
||||
{"Fitness Score", "0.258"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.29"},
|
||||
{"Treynor Ratio", "4.005"},
|
||||
{"Total Fees", "$18.28"},
|
||||
{"Estimated Strategy Capacity", "$500000000.00"},
|
||||
{"Fitness Score", "0.052"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -127,6 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.204"},
|
||||
{"Treynor Ratio", "-1.424"},
|
||||
{"Total Fees", "$16.26"},
|
||||
{"Estimated Strategy Capacity", "$590000000.00"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "12.539"},
|
||||
{"Kelly Criterion Probability Value", "0.367"},
|
||||
|
||||
@@ -148,6 +148,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "1.441"},
|
||||
{"Treynor Ratio", "-0.15"},
|
||||
{"Total Fees", "$33.30"},
|
||||
{"Estimated Strategy Capacity", "$17000000.00"},
|
||||
{"Fitness Score", "0.079"},
|
||||
{"Kelly Criterion Estimate", "-9.366"},
|
||||
{"Kelly Criterion Probability Value", "0.607"},
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.22"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$6.41"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0.249"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -184,6 +184,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.123"},
|
||||
{"Treynor Ratio", "-1.288"},
|
||||
{"Total Fees", "$669.76"},
|
||||
{"Estimated Strategy Capacity", "$210000.00"},
|
||||
{"Fitness Score", "0.021"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -147,6 +147,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.049"},
|
||||
{"Treynor Ratio", "-0.934"},
|
||||
{"Total Fees", "$22.26"},
|
||||
{"Estimated Strategy Capacity", "$360000.00"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.186"},
|
||||
{"Treynor Ratio", "1.557"},
|
||||
{"Total Fees", "$4.00"},
|
||||
{"Estimated Strategy Capacity", "$5200000.00"},
|
||||
{"Fitness Score", "0.012"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -174,6 +174,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$804.33"},
|
||||
{"Estimated Strategy Capacity", "$11000.00"},
|
||||
{"Fitness Score", "0.504"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -98,6 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$5.93"},
|
||||
{"Estimated Strategy Capacity", "$590000.00"},
|
||||
{"Fitness Score", "0.499"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
@@ -144,6 +144,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user