Compare commits
7 Commits
8728
...
feature-op
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4151c40b39 | ||
|
|
0f942149a0 | ||
|
|
e86155c117 | ||
|
|
1e8fdba3d9 | ||
|
|
66a3f2e1d2 | ||
|
|
5a2adf2065 | ||
|
|
2dd94f3687 |
@@ -1,6 +1,4 @@
|
||||
packages/*
|
||||
.git/*
|
||||
.github/*
|
||||
.vs/*
|
||||
.nuget/*
|
||||
Tests/*
|
||||
*/packages/*
|
||||
*/.git/*
|
||||
*/.vs/*
|
||||
*/.nuget/*
|
||||
4
.github/funding.yml
vendored
4
.github/funding.yml
vendored
@@ -1,4 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: quantconnect
|
||||
#custom: ['https://github.com/sponsors/QuantConnect']
|
||||
4
.github/pull_request_template.md
vendored
4
.github/pull_request_template.md
vendored
@@ -24,8 +24,6 @@
|
||||
#### Types of changes
|
||||
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] Refactor (non-breaking change which improves implementation)
|
||||
- [ ] Performance (non-breaking change which improves performance. Please add associated performance test and results)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
- [ ] Non-functional change (xml comments/documentation/etc)
|
||||
@@ -39,4 +37,4 @@
|
||||
- [ ] All new and existing tests passed.
|
||||
- [ ] My branch follows the naming convention `bug-<issue#>-<description>` or `feature-<issue#>-<description>`
|
||||
|
||||
<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->
|
||||
<!--- Template inspired by https://www.talater.com/open-source-templates/#/page/99 -->
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -34,8 +34,6 @@
|
||||
|
||||
# QC Cloud Setup Bash Files
|
||||
*.sh
|
||||
# Include docker build scripts for Mac/Linux
|
||||
!run_docker.sh
|
||||
|
||||
# QC Config Files:
|
||||
# config.json
|
||||
@@ -168,9 +166,6 @@ AutoTest.Net/
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
|
||||
21
.travis.yml
21
.travis.yml
@@ -1,24 +1,21 @@
|
||||
sudo: required
|
||||
language: csharp
|
||||
mono:
|
||||
- 5.12.0
|
||||
- 5.8.0
|
||||
solution: QuantConnect.Lean.sln
|
||||
before_install:
|
||||
- export PATH="$HOME/miniconda3/bin:$PATH"
|
||||
- wget 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
|
||||
- wget https://cdn.quantconnect.com/miniconda/Miniconda3-4.3.31-Linux-x86_64.sh
|
||||
- bash Miniconda3-4.3.31-Linux-x86_64.sh -b
|
||||
- rm -rf Miniconda3-4.3.31-Linux-x86_64.sh
|
||||
- sudo ln -s $HOME/miniconda3/lib/libpython3.6m.so /usr/lib/libpython3.6m.so
|
||||
- conda update -y python conda pip
|
||||
- conda install -y python=3.6.8
|
||||
- conda install -y numpy=1.18.1
|
||||
- conda install -y pandas=0.25.3
|
||||
- conda install -y cython=0.29.15
|
||||
- conda install -y scipy=1.4.1
|
||||
- conda install -y wrapt=1.12.1
|
||||
- conda install -y cython pandas scipy
|
||||
install:
|
||||
- nuget restore QuantConnect.Lean.sln
|
||||
- nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
|
||||
- nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner
|
||||
script:
|
||||
- msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe 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
|
||||
- mono ./testrunner/NUnit.Runners.2.6.4/tools/nunit-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --exclude:TravisExclude --labels
|
||||
after_success:
|
||||
- coveralls
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Test algorithm using <see cref="AccumulativeInsightPortfolioConstructionModel"/> and <see cref="ConstantAlphaModel"/>
|
||||
/// generating a constant <see cref="Insight"/> with a 0.25 confidence
|
||||
/// </summary>
|
||||
public class AccumulativeInsightPortfolioRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
// set algorithm framework models
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
|
||||
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, 0.25));
|
||||
SetPortfolioConstruction(new AccumulativeInsightPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (// holdings value should be 0.03 - to avoid price fluctuation issue we compare with 0.06 and 0.01
|
||||
Portfolio.TotalHoldingsValue > Portfolio.TotalPortfolioValue * 0.06m
|
||||
||
|
||||
Portfolio.TotalHoldingsValue < Portfolio.TotalPortfolioValue * 0.01m)
|
||||
{
|
||||
throw new Exception($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "199"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-12.472%"},
|
||||
{"Drawdown", "0.200%"},
|
||||
{"Expectancy", "-0.586"},
|
||||
{"Net Profit", "-0.170%"},
|
||||
{"Sharpe Ratio", "-9.693"},
|
||||
{"Probabilistic Sharpe Ratio", "12.704%"},
|
||||
{"Loss Rate", "79%"},
|
||||
{"Win Rate", "21%"},
|
||||
{"Profit-Loss Ratio", "0.95"},
|
||||
{"Alpha", "-0.149"},
|
||||
{"Beta", "0.037"},
|
||||
{"Annual Standard Deviation", "0.008"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-9.471"},
|
||||
{"Tracking Error", "0.212"},
|
||||
{"Treynor Ratio", "-2.13"},
|
||||
{"Total Fees", "$199.00"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
{"Sortino Ratio", "-21.545"},
|
||||
{"Return Over Maximum Drawdown", "-77.972"},
|
||||
{"Portfolio Turnover", "1.135"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$126657.6305"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
|
||||
{"Mean Population Estimated Insight Value", "$206.1207"},
|
||||
{"Mean Population Direction", "54.5455%"},
|
||||
{"Mean Population Magnitude", "54.5455%"},
|
||||
{"Rolling Averaged Population Direction", "59.8056%"},
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"},
|
||||
{"OrderListHash", "1256341962"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -110,46 +110,38 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "9"},
|
||||
{"Average Win", "0.89%"},
|
||||
{"Average Loss", "-0.27%"},
|
||||
{"Compounding Annual Return", "196.104%"},
|
||||
{"Drawdown", "1.700%"},
|
||||
{"Expectancy", "1.853"},
|
||||
{"Net Profit", "1.498%"},
|
||||
{"Sharpe Ratio", "4.275"},
|
||||
{"Probabilistic Sharpe Ratio", "60.462%"},
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0.91%"},
|
||||
{"Average Loss", "-0.23%"},
|
||||
{"Compounding Annual Return", "214.278%"},
|
||||
{"Drawdown", "1.600%"},
|
||||
{"Expectancy", "2.248"},
|
||||
{"Net Profit", "1.581%"},
|
||||
{"Sharpe Ratio", "2.803"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "3.28"},
|
||||
{"Alpha", "1.574"},
|
||||
{"Beta", "-0.289"},
|
||||
{"Annual Standard Deviation", "0.276"},
|
||||
{"Annual Variance", "0.076"},
|
||||
{"Information Ratio", "-0.495"},
|
||||
{"Tracking Error", "0.367"},
|
||||
{"Treynor Ratio", "-4.079"},
|
||||
{"Total Fees", "$14.33"},
|
||||
{"Fitness Score", "0.408"},
|
||||
{"Kelly Criterion Estimate", "16.447"},
|
||||
{"Kelly Criterion Probability Value", "0.315"},
|
||||
{"Sortino Ratio", "13.611"},
|
||||
{"Return Over Maximum Drawdown", "117.635"},
|
||||
{"Portfolio Turnover", "0.411"},
|
||||
{"Profit-Loss Ratio", "3.87"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "59.491"},
|
||||
{"Annual Standard Deviation", "0.244"},
|
||||
{"Annual Variance", "0.06"},
|
||||
{"Information Ratio", "2.756"},
|
||||
{"Tracking Error", "0.244"},
|
||||
{"Treynor Ratio", "0.012"},
|
||||
{"Total Fees", "$10.88"},
|
||||
{"Total Insights Generated", "3"},
|
||||
{"Total Insights Closed", "3"},
|
||||
{"Total Insights Analysis Completed", "3"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "3"},
|
||||
{"Long/Short Ratio", "0%"},
|
||||
{"Estimated Monthly Alpha Value", "$19868365.6628"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$3421774.0864"},
|
||||
{"Mean Population Estimated Insight Value", "$1140591.3621"},
|
||||
{"Estimated Monthly Alpha Value", "$13262182.1037"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$2284042.4734"},
|
||||
{"Mean Population Estimated Insight Value", "$761347.4911"},
|
||||
{"Mean Population Direction", "100%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "100%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-887015098"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
private int _expectedContractIndex;
|
||||
private readonly List<Symbol> _expectedContracts = new List<Symbol>
|
||||
{
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00747500"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00752500")
|
||||
};
|
||||
|
||||
@@ -212,14 +212,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Average Loss", "-0.21%"},
|
||||
{"Compounding Annual Return", "-98.595%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.631%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
@@ -229,27 +228,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Return Over Maximum Drawdown", "0"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "731140098"}
|
||||
{"Total Fees", "$6.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
else if (Time.DayOfWeek == DayOfWeek.Thursday)
|
||||
{
|
||||
RemoveSecurity(_aig);
|
||||
RemoveSecurity(_bac);
|
||||
RemoveSecurity(_aig);
|
||||
lastAction = Time;
|
||||
}
|
||||
}
|
||||
@@ -112,45 +112,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "5"},
|
||||
{"Average Win", "0.47%"},
|
||||
{"Average Win", "0.49%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "293.067%"},
|
||||
{"Compounding Annual Return", "305.340%"},
|
||||
{"Drawdown", "1.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.765%"},
|
||||
{"Sharpe Ratio", "13.11"},
|
||||
{"Probabilistic Sharpe Ratio", "80.231%"},
|
||||
{"Net Profit", "1.805%"},
|
||||
{"Sharpe Ratio", "6.475"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.705"},
|
||||
{"Beta", "0.7"},
|
||||
{"Annual Standard Deviation", "0.157"},
|
||||
{"Annual Variance", "0.025"},
|
||||
{"Information Ratio", "1.76"},
|
||||
{"Tracking Error", "0.072"},
|
||||
{"Treynor Ratio", "2.933"},
|
||||
{"Total Fees", "$26.39"},
|
||||
{"Fitness Score", "0.374"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "373.973"},
|
||||
{"Portfolio Turnover", "0.374"},
|
||||
{"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", "1779055144"}
|
||||
{"Alpha", "0.003"},
|
||||
{"Beta", "82.247"},
|
||||
{"Annual Standard Deviation", "0.141"},
|
||||
{"Annual Variance", "0.02"},
|
||||
{"Information Ratio", "6.401"},
|
||||
{"Tracking Error", "0.141"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$26.40"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -67,43 +67,35 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "1.02%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "289.119%"},
|
||||
{"Compounding Annual Return", "289.117%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.752%"},
|
||||
{"Sharpe Ratio", "9.235"},
|
||||
{"Probabilistic Sharpe Ratio", "68.013%"},
|
||||
{"Sharpe Ratio", "4.52"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.105"},
|
||||
{"Beta", "1.022"},
|
||||
{"Annual Standard Deviation", "0.224"},
|
||||
{"Annual Variance", "0.05"},
|
||||
{"Information Ratio", "24.59"},
|
||||
{"Tracking Error", "0.006"},
|
||||
{"Treynor Ratio", "2.029"},
|
||||
{"Alpha", "0.007"},
|
||||
{"Beta", "80.237"},
|
||||
{"Annual Standard Deviation", "0.197"},
|
||||
{"Annual Variance", "0.039"},
|
||||
{"Information Ratio", "4.466"},
|
||||
{"Tracking Error", "0.197"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$9.77"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "107.109"},
|
||||
{"Portfolio Turnover", "0.747"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$126657.6305"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
|
||||
{"Mean Population Estimated Insight Value", "$206.1207"},
|
||||
{"Estimated Monthly Alpha Value", "$158418.3850"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
|
||||
{"Mean Population Estimated Insight Value", "$257.8077"},
|
||||
{"Mean Population Direction", "54.5455%"},
|
||||
{"Mean Population Magnitude", "54.5455%"},
|
||||
{"Rolling Averaged Population Direction", "59.8056%"},
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"},
|
||||
{"OrderListHash", "-887190565"}
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -86,43 +86,35 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "10"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-14.333%"},
|
||||
{"Compounding Annual Return", "-14.943%"},
|
||||
{"Drawdown", "3.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.169%"},
|
||||
{"Sharpe Ratio", "-0.131"},
|
||||
{"Probabilistic Sharpe Ratio", "45.057%"},
|
||||
{"Net Profit", "-0.177%"},
|
||||
{"Sharpe Ratio", "-0.136"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-3.068"},
|
||||
{"Beta", "0.595"},
|
||||
{"Annual Standard Deviation", "0.382"},
|
||||
{"Annual Variance", "0.146"},
|
||||
{"Information Ratio", "-13.618"},
|
||||
{"Tracking Error", "0.376"},
|
||||
{"Treynor Ratio", "-0.084"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "-4.084"},
|
||||
{"Annual Standard Deviation", "0.332"},
|
||||
{"Annual Variance", "0.11"},
|
||||
{"Information Ratio", "-0.169"},
|
||||
{"Tracking Error", "0.332"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$13.98"},
|
||||
{"Fitness Score", "0.146"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-4.398"},
|
||||
{"Portfolio Turnover", "0.268"},
|
||||
{"Total Insights Generated", "15"},
|
||||
{"Total Insights Closed", "12"},
|
||||
{"Total Insights Analysis Completed", "12"},
|
||||
{"Long Insight Count", "15"},
|
||||
{"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", "1917702312"}
|
||||
{"Estimated Monthly Alpha Value", "$33015795.7342"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$4585527.1853"},
|
||||
{"Mean Population Estimated Insight Value", "$382127.2654"},
|
||||
{"Mean Population Direction", "66.6667%"},
|
||||
{"Mean Population Magnitude", "66.6667%"},
|
||||
{"Rolling Averaged Population Direction", "34.3681%"},
|
||||
{"Rolling Averaged Population Magnitude", "34.3681%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -93,43 +93,35 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "23"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-75.307%"},
|
||||
{"Compounding Annual Return", "-75.360%"},
|
||||
{"Drawdown", "5.800%"},
|
||||
{"Expectancy", "-0.859"},
|
||||
{"Net Profit", "-5.586%"},
|
||||
{"Sharpe Ratio", "-3.257"},
|
||||
{"Probabilistic Sharpe Ratio", "5.931%"},
|
||||
{"Net Profit", "-5.594%"},
|
||||
{"Sharpe Ratio", "-5.582"},
|
||||
{"Loss Rate", "92%"},
|
||||
{"Win Rate", "8%"},
|
||||
{"Profit-Loss Ratio", "0.70"},
|
||||
{"Alpha", "-0.593"},
|
||||
{"Beta", "0.692"},
|
||||
{"Annual Standard Deviation", "0.204"},
|
||||
{"Annual Variance", "0.042"},
|
||||
{"Information Ratio", "-2.884"},
|
||||
{"Tracking Error", "0.194"},
|
||||
{"Treynor Ratio", "-0.962"},
|
||||
{"Alpha", "-1.454"},
|
||||
{"Beta", "15.578"},
|
||||
{"Annual Standard Deviation", "0.212"},
|
||||
{"Annual Variance", "0.045"},
|
||||
{"Information Ratio", "-5.664"},
|
||||
{"Tracking Error", "0.212"},
|
||||
{"Treynor Ratio", "-0.076"},
|
||||
{"Total Fees", "$25.92"},
|
||||
{"Fitness Score", "0.004"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "-4.462"},
|
||||
{"Return Over Maximum Drawdown", "-13.032"},
|
||||
{"Portfolio Turnover", "0.083"},
|
||||
{"Total Insights Generated", "33"},
|
||||
{"Total Insights Closed", "30"},
|
||||
{"Total Insights Analysis Completed", "30"},
|
||||
{"Long Insight Count", "33"},
|
||||
{"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", "-1674230481"}
|
||||
{"Estimated Monthly Alpha Value", "$-7788114"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-3937325"},
|
||||
{"Mean Population Estimated Insight Value", "$-131244.2"},
|
||||
{"Mean Population Direction", "46.6667%"},
|
||||
{"Mean Population Magnitude", "46.6667%"},
|
||||
{"Rolling Averaged Population Direction", "61.4247%"},
|
||||
{"Rolling Averaged Population Magnitude", "61.4247%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Benzinga;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
/// <summary>
|
||||
/// Benzinga is a provider of news data. Their news is made in-house
|
||||
/// and covers stock related news such as corporate events.
|
||||
/// </summary>
|
||||
public class BenzingaNewsAlgorithm : QCAlgorithm
|
||||
{
|
||||
// Predefine a dictionary of words with scores to scan for in the description
|
||||
// of the Benzinga news article
|
||||
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
|
||||
{
|
||||
{"bad", -0.5}, {"good", 0.5},
|
||||
{"negative", -0.5}, {"great", 0.5},
|
||||
{"growth", 0.5}, {"fail", -0.5},
|
||||
{"failed", -0.5}, {"success", 0.5},
|
||||
{"nailed", 0.5}, {"beat", 0.5},
|
||||
{"missed", -0.5}
|
||||
};
|
||||
|
||||
// Trade only every 5 days
|
||||
private DateTime _lastTrade = DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 6, 5);
|
||||
SetEndDate(2018, 8, 4);
|
||||
SetCash(100000);
|
||||
|
||||
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
|
||||
var ibm = AddEquity("IBM", Resolution.Hour).Symbol;
|
||||
|
||||
AddData<BenzingaNews>(aapl);
|
||||
AddData<BenzingaNews>(ibm);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if ((Time - _lastTrade) < TimeSpan.FromDays(5))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get rid of our holdings after 5 days, and start fresh
|
||||
Liquidate();
|
||||
|
||||
// Get all Benzinga data and loop over it
|
||||
foreach (var article in data.Get<BenzingaNews>().Values)
|
||||
{
|
||||
// Select the same Symbol we're getting a data point for
|
||||
// from the articles list so that we can get the sentiment of the article.
|
||||
// We use the underlying Symbol because the Symbols included in the `Symbols` property
|
||||
// are equity Symbols.
|
||||
var selectedSymbol = article.Symbols.SingleOrDefault(s => s == article.Symbol.Underlying);
|
||||
if (selectedSymbol == null)
|
||||
{
|
||||
throw new Exception($"Could not find current Symbol {article.Symbol.Underlying} even though it should exist");
|
||||
}
|
||||
|
||||
// The intersection of the article contents and the pre-defined words are the words that are included in both collections
|
||||
var intersection = article.Contents.ToLowerInvariant().Split(' ').Intersect(_words.Keys);
|
||||
// Get the words, then get the aggregate sentiment
|
||||
var sentimentSum = intersection.Select(x => _words[x]).Sum();
|
||||
|
||||
if (sentimentSum >= 0.5)
|
||||
{
|
||||
Log($"Longing {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
|
||||
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
|
||||
|
||||
_lastTrade = Time;
|
||||
}
|
||||
if (sentimentSum <= -0.5)
|
||||
{
|
||||
Log($"Shorting {article.Symbol.Underlying} with sentiment score of {sentimentSum}");
|
||||
SetHoldings(article.Symbol.Underlying, sentimentSum / 5);
|
||||
|
||||
_lastTrade = Time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(BenzingaNews), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Data.Custom.Fred;
|
||||
using QuantConnect.Data.Custom.USEnergy;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
public class CachedAlternativeDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _cboeVix;
|
||||
private Symbol _usEnergy;
|
||||
private Symbol _fredPeakToTrough;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2003, 1, 1);
|
||||
SetEndDate(2019, 10, 11);
|
||||
SetCash(100000);
|
||||
|
||||
// QuantConnect caches a small subset of alternative data for easy consumption for the community.
|
||||
// You can use this in your algorithm as demonstrated below:
|
||||
|
||||
_cboeVix = AddData<CBOE>("VIX", Resolution.Daily).Symbol;
|
||||
// United States EIA data: https://eia.gov/
|
||||
_usEnergy = AddData<USEnergy>(USEnergy.Petroleum.UnitedStates.WeeklyGrossInputsIntoRefineries, Resolution.Daily).Symbol;
|
||||
// FRED data
|
||||
_fredPeakToTrough = AddData<Fred>(Fred.OECDRecessionIndicators.UnitedStatesFromPeakThroughTheTrough, Resolution.Daily).Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.ContainsKey(_cboeVix))
|
||||
{
|
||||
var vix = data.Get<CBOE>(_cboeVix);
|
||||
Log($"VIX: {vix}");
|
||||
}
|
||||
|
||||
if (data.ContainsKey(_usEnergy))
|
||||
{
|
||||
var inputIntoRefineries = data.Get<USEnergy>(_usEnergy);
|
||||
Log($"U.S. Input Into Refineries: {Time}, {inputIntoRefineries.Value}");
|
||||
}
|
||||
|
||||
if (data.ContainsKey(_fredPeakToTrough))
|
||||
{
|
||||
var peakToTrough = data.Get<Fred>(_fredPeakToTrough);
|
||||
Log($"OECD based Recession Indicator for the United States from the Peak through the Trough: {peakToTrough}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Robintrack;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.AltData
|
||||
{
|
||||
/// <summary>
|
||||
/// Looks at users holding the stock AAPL at a given point in time
|
||||
/// and keeps track of changes in retail investor sentiment.
|
||||
///
|
||||
/// We go long if the sentiment increases by 0.5%, and short if it decreases by -0.5%
|
||||
/// </summary>
|
||||
public class RobintrackHoldingsAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _aapl;
|
||||
private Symbol _aaplHoldings;
|
||||
private decimal _lastValue;
|
||||
private bool _isLong;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 5, 1);
|
||||
SetEndDate(2020, 5, 5);
|
||||
SetCash(100000);
|
||||
|
||||
_aapl = AddEquity("AAPL", Resolution.Daily).Symbol;
|
||||
_aaplHoldings = AddData<RobintrackHoldings>(_aapl).Symbol;
|
||||
_isLong = false;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var kvp in data.Get<RobintrackHoldings>())
|
||||
{
|
||||
var holdings = kvp.Value;
|
||||
|
||||
if (_lastValue != 0)
|
||||
{
|
||||
var percentChange = (holdings.UsersHolding - _lastValue) / _lastValue;
|
||||
var holdingInfo = $"There are {holdings.UsersHolding} unique users holding {kvp.Key.Underlying} - users holding % of U.S. equities universe: {holdings.UniverseHoldingPercent * 100m}%";
|
||||
|
||||
if (percentChange >= 0.005m && !_isLong)
|
||||
{
|
||||
Log($"{UtcTime} - Buying AAPL - {holdingInfo}");
|
||||
SetHoldings(_aapl, 0.5);
|
||||
_isLong = true;
|
||||
}
|
||||
else if (percentChange <= -0.005m && _isLong)
|
||||
{
|
||||
Log($"{UtcTime} - Shorting AAPL - {holdingInfo}");
|
||||
SetHoldings(_aapl, -0.5);
|
||||
_isLong = false;
|
||||
}
|
||||
}
|
||||
|
||||
_lastValue = holdings.UsersHolding;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class SECReport8KAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 1, 1);
|
||||
SetEndDate(2019, 8, 21);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
|
||||
|
||||
// Request underlying equity data.
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add SEC report 10-Q data for the underlying IBM asset
|
||||
var earningsFiling = AddData<SECReport10Q>(ibm, Resolution.Daily).Symbol;
|
||||
// Request 120 days of history with the SECReport10Q IBM custom data Symbol.
|
||||
var history = History<SECReport10Q>(earningsFiling, 120, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
// Add SEC data from the filtered coarse selection
|
||||
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
|
||||
.Select(x => x.Symbol)
|
||||
.Take(10);
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
AddData<SECReport8K>(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Store the symbols we want to long in a list
|
||||
// so that we can have an equal-weighted portfolio
|
||||
var longEquitySymbols = new List<Symbol>();
|
||||
|
||||
// Get all SEC data and loop over it
|
||||
foreach (var report in data.Get<SECReport8K>().Values)
|
||||
{
|
||||
// Get the length of all contents contained within the report
|
||||
var reportTextLength = report.Report.Documents.Select(x => x.Text.Length).Sum();
|
||||
|
||||
if (reportTextLength > 20000)
|
||||
{
|
||||
longEquitySymbols.Add(report.Symbol.Underlying);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var equitySymbol in longEquitySymbols)
|
||||
{
|
||||
SetHoldings(equitySymbol, 1m / longEquitySymbols.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SECReport8K), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SmartInsider;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class SmartInsiderTransactionAlgorithm : QCAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 3, 1);
|
||||
SetEndDate(2019, 7, 4);
|
||||
SetCash(1000000);
|
||||
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseUniverse));
|
||||
|
||||
// Request underlying equity data.
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add Smart Insider stock buyback transaction data for the underlying IBM asset
|
||||
var si = AddData<SmartInsiderTransaction>(ibm).Symbol;
|
||||
// Request 60 days of history with the SmartInsiderTransaction IBM Custom Data Symbol.
|
||||
var history = History<SmartInsiderTransaction>(si, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseUniverse(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
var symbols = coarse.Where(x => x.HasFundamentalData && x.DollarVolume > 50000000)
|
||||
.Select(x => x.Symbol)
|
||||
.Take(10);
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
AddData<SmartInsiderTransaction>(symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Get all SmartInsider data available
|
||||
var transactions = data.Get<SmartInsiderTransaction>();
|
||||
|
||||
foreach (var transaction in transactions.Values)
|
||||
{
|
||||
if (transaction.VolumePercentage == null || transaction.EventType == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Using the Smart Insider transaction information, buy when company does a stock buyback
|
||||
if (transaction.EventType == SmartInsiderEventType.Transaction && transaction.VolumePercentage > 5)
|
||||
{
|
||||
SetHoldings(transaction.Symbol.Underlying, (decimal)transaction.VolumePercentage / 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var r in changes.RemovedSecurities)
|
||||
{
|
||||
// If removed from the universe, liquidate and remove the custom data from the algorithm
|
||||
Liquidate(r.Symbol);
|
||||
RemoveSecurity(QuantConnect.Symbol.CreateBase(typeof(SmartInsiderTransaction), r.Symbol, Market.USA));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Look for positive and negative words in the news article description
|
||||
/// and trade based on the sum of the sentiment
|
||||
/// </summary>
|
||||
public class TiingoNewsAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _tiingoSymbol;
|
||||
|
||||
// Predefine a dictionary of words with scores to scan for in the description
|
||||
// of the Tiingo news article
|
||||
private readonly Dictionary<string, double> _words = new Dictionary<string, double>()
|
||||
{
|
||||
{"bad", -0.5}, {"good", 0.5},
|
||||
{ "negative", -0.5}, {"great", 0.5},
|
||||
{"growth", 0.5}, {"fail", -0.5},
|
||||
{"failed", -0.5}, {"success", 0.5},
|
||||
{"nailed", 0.5}, {"beat", 0.5},
|
||||
{"missed", -0.5}
|
||||
};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 6, 10);
|
||||
SetEndDate(2019, 10, 3);
|
||||
SetCash(100000);
|
||||
|
||||
var aapl = AddEquity("AAPL", Resolution.Hour).Symbol;
|
||||
_tiingoSymbol = AddData<TiingoNews>(aapl).Symbol;
|
||||
|
||||
// Request underlying equity data
|
||||
var ibm = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
// Add news data for the underlying IBM asset
|
||||
var news = AddData<TiingoNews>(ibm).Symbol;
|
||||
// Request 60 days of history with the TiingoNews IBM Custom Data Symbol.
|
||||
var history = History<TiingoNews>(news, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
//Confirm that the data is in the collection
|
||||
if (!data.ContainsKey(_tiingoSymbol)) return;
|
||||
|
||||
// Gets the first piece of data from the Slice
|
||||
var article = data.Get<TiingoNews>(_tiingoSymbol);
|
||||
|
||||
// Article descriptions come in all caps. Lower and split by word
|
||||
var descriptionWords = article.Description.ToLowerInvariant().Split(' ');
|
||||
|
||||
// Take the intersection of predefined words and the words in the
|
||||
// description to get a list of matching words
|
||||
var intersection = _words.Keys.Intersect(descriptionWords);
|
||||
|
||||
// Get the sum of the article's sentiment, and go long or short
|
||||
// depending if it's a positive or negative description
|
||||
var sentiment = intersection.Select(x => _words[x]).Sum();
|
||||
|
||||
SetHoldings(article.Symbol.Underlying, sentiment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.TradingEconomics;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Trades on interest rate announcements from data provided by Trading Economics
|
||||
/// </summary>
|
||||
public class TradingEconomicsAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _interestRate;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 11, 1);
|
||||
SetEndDate(2019, 10, 3);
|
||||
SetCash(100000);
|
||||
|
||||
AddEquity("AGG", Resolution.Hour);
|
||||
AddEquity("SPY", Resolution.Hour);
|
||||
|
||||
_interestRate = AddData<TradingEconomicsCalendar>(TradingEconomics.Calendar.UnitedStates.InterestRate).Symbol;
|
||||
|
||||
// Request 365 days of interest rate history with the TradingEconomicsCalendar custom data Symbol.
|
||||
// We should expect no historical data because 2013-11-01 is before the absolute first point of data
|
||||
var history = History<TradingEconomicsCalendar>(_interestRate, 365, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request (should be zero)
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// Make sure we have an interest rate calendar event
|
||||
if (!data.ContainsKey(_interestRate))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var announcement = data.Get<TradingEconomicsCalendar>(_interestRate);
|
||||
|
||||
// Confirm it's a FED Rate Decision
|
||||
if (announcement.Event != TradingEconomics.Event.UnitedStates.FedInterestRateDecision)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// In the event of a rate increase, rebalance 50% to Bonds.
|
||||
var interestRateDecreased = announcement.Actual <= announcement.Previous;
|
||||
|
||||
if (interestRateDecreased)
|
||||
{
|
||||
SetHoldings("SPY", 1);
|
||||
SetHoldings("AGG", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetHoldings("SPY", 0.5);
|
||||
SetHoldings("AGG", 0.5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class USTreasuryYieldCurveRateAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _yieldCurve;
|
||||
private Symbol _spy;
|
||||
private DateTime _lastInversion = DateTime.MinValue;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2000, 3, 1);
|
||||
SetEndDate(2019, 9, 15);
|
||||
SetCash(100000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
_yieldCurve = AddData<USTreasuryYieldCurveRate>("USTYCR", Resolution.Daily).Symbol;
|
||||
|
||||
// Request 60 days of history with the USTreasuryYieldCurveRate custom data Symbol.
|
||||
var history = History<USTreasuryYieldCurveRate>(_yieldCurve, 60, Resolution.Daily);
|
||||
|
||||
// Count the number of items we get from our history request
|
||||
Debug($"We got {history.Count()} items from our history request");
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!data.ContainsKey(_yieldCurve))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Preserve null values by getting the data with `slice.Get<T>`
|
||||
// Accessing the data using `data[_yieldCurve]` results in null
|
||||
// values becoming `default(decimal)` which is equal to 0
|
||||
var rates = data.Get<USTreasuryYieldCurveRate>().Values.First();
|
||||
|
||||
// Check for null before using the values
|
||||
if (!rates.TenYear.HasValue || !rates.TwoYear.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Only advance if a year has gone by
|
||||
if (Time - _lastInversion < TimeSpan.FromDays(365))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if there is a yield curve inversion after not having one for a year, short SPY for two years
|
||||
if (!Portfolio.Invested && rates.TwoYear > rates.TenYear)
|
||||
{
|
||||
Debug($"{Time} - Yield curve inversion! Shorting the market for two years");
|
||||
SetHoldings(_spy, -0.5);
|
||||
|
||||
_lastInversion = Time;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If two years have passed, liquidate our position in SPY
|
||||
if (Time - _lastInversion >= TimeSpan.FromDays(365 * 2))
|
||||
{
|
||||
Liquidate(_spy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm which tests indicator warm up using different data types, related to GH issue 4205
|
||||
/// </summary>
|
||||
public class AutomaticIndicatorWarmupDataTypeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _symbol;
|
||||
public override void Initialize()
|
||||
{
|
||||
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
|
||||
EnableAutomaticIndicatorWarmUp = true;
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 09);
|
||||
|
||||
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
|
||||
|
||||
// Test case: custom IndicatorBase<QuoteBar> indicator using Future unsubscribed symbol
|
||||
var indicator1 = new CustomIndicator();
|
||||
AssertIndicatorState(indicator1, isReady: false);
|
||||
WarmUpIndicator(_symbol, indicator1);
|
||||
AssertIndicatorState(indicator1, isReady: true);
|
||||
|
||||
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Future unsubscribed symbol (should use TradeBar)
|
||||
var sma1 = new SimpleMovingAverage(10);
|
||||
AssertIndicatorState(sma1, isReady: false);
|
||||
WarmUpIndicator(_symbol, sma1);
|
||||
AssertIndicatorState(sma1, isReady: true);
|
||||
|
||||
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Equity unsubscribed symbol
|
||||
var spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
var sma = new SimpleMovingAverage(10);
|
||||
AssertIndicatorState(sma, isReady: false);
|
||||
WarmUpIndicator(spy, sma);
|
||||
AssertIndicatorState(sma, isReady: true);
|
||||
|
||||
// We add the symbol
|
||||
AddFutureContract(_symbol);
|
||||
AddEquity("SPY");
|
||||
// force spy for use Raw data mode so that it matches the used when unsubscribed which uses the universe settings
|
||||
SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(spy).SetDataNormalizationMode(DataNormalizationMode.Raw);
|
||||
|
||||
// Test case: custom IndicatorBase<QuoteBar> indicator using Future subscribed symbol
|
||||
var indicator = new CustomIndicator();
|
||||
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(1), typeof(QuoteBar));
|
||||
RegisterIndicator(_symbol, indicator, consolidator);
|
||||
|
||||
AssertIndicatorState(indicator, isReady: false);
|
||||
WarmUpIndicator(_symbol, indicator);
|
||||
AssertIndicatorState(indicator, isReady: true);
|
||||
|
||||
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Future Subscribed symbol (should use TradeBar)
|
||||
var sma11 = new SimpleMovingAverage(10);
|
||||
AssertIndicatorState(sma11, isReady: false);
|
||||
WarmUpIndicator(_symbol, sma11);
|
||||
AssertIndicatorState(sma11, isReady: true);
|
||||
|
||||
if (!sma11.Current.Equals(sma1.Current))
|
||||
{
|
||||
throw new Exception("Expected SMAs warmed up before and after adding the Future to the algorithm to have the same current value. " +
|
||||
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
|
||||
}
|
||||
|
||||
// Test case: SimpleMovingAverage<IndicatorDataPoint> using Equity unsubscribed symbol
|
||||
var smaSpy = new SimpleMovingAverage(10);
|
||||
AssertIndicatorState(smaSpy, isReady: false);
|
||||
WarmUpIndicator(spy, smaSpy);
|
||||
AssertIndicatorState(smaSpy, isReady: true);
|
||||
|
||||
if (!smaSpy.Current.Equals(sma.Current))
|
||||
{
|
||||
throw new Exception("Expected SMAs warmed up before and after adding the Equity to the algorithm to have the same current value. " +
|
||||
"The result of 'WarmUpIndicator' shouldn't change if the symbol is or isn't subscribed");
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertIndicatorState(IIndicator indicator, bool isReady)
|
||||
{
|
||||
if (indicator.IsReady != isReady)
|
||||
{
|
||||
throw new Exception($"Expected indicator state, expected {isReady} but was {indicator.IsReady}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_symbol, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomIndicator : IndicatorBase<QuoteBar>, IIndicatorWarmUpPeriodProvider
|
||||
{
|
||||
private bool _isReady;
|
||||
public int WarmUpPeriod => 1;
|
||||
public override bool IsReady => _isReady;
|
||||
public CustomIndicator() : base("Pepe")
|
||||
{ }
|
||||
protected override decimal ComputeNextValue(QuoteBar input)
|
||||
{
|
||||
_isReady = true;
|
||||
return input.Ask.High;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-99.999%"},
|
||||
{"Drawdown", "16.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-6.366%"},
|
||||
{"Sharpe Ratio", "1.194"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "5.579"},
|
||||
{"Beta", "-63.972"},
|
||||
{"Annual Standard Deviation", "0.434"},
|
||||
{"Annual Variance", "0.188"},
|
||||
{"Information Ratio", "0.996"},
|
||||
{"Tracking Error", "0.441"},
|
||||
{"Treynor Ratio", "-0.008"},
|
||||
{"Total Fees", "$20.35"},
|
||||
{"Fitness Score", "0.138"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.727"},
|
||||
{"Return Over Maximum Drawdown", "-12.061"},
|
||||
{"Portfolio Turnover", "4.916"},
|
||||
{"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", "-1453269600"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm which reproduces GH issue 3861, where in some cases 2 consolidators were added when
|
||||
/// using the automatic indicator warmup feature
|
||||
/// </summary>
|
||||
public class AutomaticIndicatorWarmupRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
EnableAutomaticIndicatorWarmUp = true;
|
||||
|
||||
// Test case 1
|
||||
_spy = AddEquity("SPY").Symbol;
|
||||
var sma = SMA(_spy, 10);
|
||||
if (!sma.IsReady)
|
||||
{
|
||||
throw new Exception("Expected SMA to be warmed up");
|
||||
}
|
||||
|
||||
// Test case 2
|
||||
var indicator = new CustomIndicator(10);
|
||||
RegisterIndicator(_spy, indicator, Resolution.Minute, (Func<IBaseData, decimal>) null);
|
||||
|
||||
if (indicator.IsReady)
|
||||
{
|
||||
throw new Exception("Expected CustomIndicator Not to be warmed up");
|
||||
}
|
||||
WarmUpIndicator(_spy, indicator);
|
||||
if (!indicator.IsReady)
|
||||
{
|
||||
throw new Exception("Expected CustomIndicator to be warmed up");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var subscription = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_spy).First(config => config.TickType == TickType.Trade);
|
||||
|
||||
// we expect 1 consolidator per indicator
|
||||
if (subscription.Consolidators.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected consolidator count for subscription: {subscription.Consolidators.Count}");
|
||||
}
|
||||
SetHoldings(_spy, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private class CustomIndicator : SimpleMovingAverage
|
||||
{
|
||||
private IndicatorDataPoint _previous;
|
||||
public CustomIndicator(int period) : base(period)
|
||||
{
|
||||
}
|
||||
protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
|
||||
{
|
||||
if (_previous != null && input.EndTime == _previous.EndTime)
|
||||
{
|
||||
throw new Exception($"Unexpected indicator double data point call: {_previous}");
|
||||
}
|
||||
_previous = input;
|
||||
return base.ComputeNextValue(window, input);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "264.819%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.668%"},
|
||||
{"Sharpe Ratio", "8.749"},
|
||||
{"Probabilistic Sharpe Ratio", "67.311%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.005"},
|
||||
{"Beta", "0.996"},
|
||||
{"Annual Standard Deviation", "0.219"},
|
||||
{"Annual Variance", "0.048"},
|
||||
{"Information Ratio", "-14.189"},
|
||||
{"Tracking Error", "0.001"},
|
||||
{"Treynor Ratio", "1.922"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.248"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "93.761"},
|
||||
{"Portfolio Turnover", "0.248"},
|
||||
{"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", "491919591"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -71,43 +71,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "11.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "-7.328%"},
|
||||
{"Sharpe Ratio", "-12.15"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0.506"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-14.148"},
|
||||
{"Portfolio Turnover", "1.073"},
|
||||
{"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", "498372354"}
|
||||
{"Alpha", "-17.811"},
|
||||
{"Beta", "1239.638"},
|
||||
{"Annual Standard Deviation", "0.762"},
|
||||
{"Annual Variance", "0.581"},
|
||||
{"Information Ratio", "-12.169"},
|
||||
{"Tracking Error", "0.761"},
|
||||
{"Treynor Ratio", "-0.007"},
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,43 +80,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "264.819%"},
|
||||
{"Compounding Annual Return", "263.153%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.668%"},
|
||||
{"Sharpe Ratio", "8.749"},
|
||||
{"Probabilistic Sharpe Ratio", "67.311%"},
|
||||
{"Net Profit", "1.663%"},
|
||||
{"Sharpe Ratio", "4.41"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.005"},
|
||||
{"Beta", "0.996"},
|
||||
{"Annual Standard Deviation", "0.219"},
|
||||
{"Annual Variance", "0.048"},
|
||||
{"Information Ratio", "-14.189"},
|
||||
{"Tracking Error", "0.001"},
|
||||
{"Treynor Ratio", "1.922"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.248"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "93.761"},
|
||||
{"Portfolio Turnover", "0.248"},
|
||||
{"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", "491919591"}
|
||||
{"Alpha", "0.007"},
|
||||
{"Beta", "76.118"},
|
||||
{"Annual Standard Deviation", "0.192"},
|
||||
{"Annual Variance", "0.037"},
|
||||
{"Information Ratio", "4.354"},
|
||||
{"Tracking Error", "0.192"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$3.26"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template algorithm which showcases <see cref="ConstituentsUniverse"/> simple use case
|
||||
/// </summary>
|
||||
public class BasicTemplateConstituentUniverseAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
// by default will use algorithms UniverseSettings
|
||||
AddUniverse(Universe.Constituent.Steel());
|
||||
|
||||
// we specify the UniverseSettings it should use
|
||||
AddUniverse(Universe.Constituent.AggressiveGrowth(
|
||||
new UniverseSettings(Resolution.Hour,
|
||||
2,
|
||||
false,
|
||||
false,
|
||||
UniverseSettings.MinimumTimeInUniverse)));
|
||||
|
||||
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,44 +205,23 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "10"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Average Loss", "-0.13%"},
|
||||
{"Compounding Annual Return", "-99.979%"},
|
||||
{"Drawdown", "3.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-2.288%"},
|
||||
{"Sharpe Ratio", "-11.335"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$85.33"},
|
||||
{"Fitness Score", "0.5"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-43.917"},
|
||||
{"Portfolio Turnover", "1.028"},
|
||||
{"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", "1073240275"}
|
||||
{"Alpha", "-5.739"},
|
||||
{"Beta", "413.859"},
|
||||
{"Annual Standard Deviation", "0.254"},
|
||||
{"Annual Variance", "0.065"},
|
||||
{"Information Ratio", "-11.39"},
|
||||
{"Tracking Error", "0.254"},
|
||||
{"Treynor Ratio", "-0.007"},
|
||||
{"Total Fees", "$85.34"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,39 +75,18 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "3.459%"},
|
||||
{"Sharpe Ratio", "10.11"},
|
||||
{"Probabilistic Sharpe Ratio", "83.150%"},
|
||||
{"Sharpe Ratio", "6.033"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.935"},
|
||||
{"Beta", "-0.119"},
|
||||
{"Alpha", "0.696"},
|
||||
{"Beta", "17.597"},
|
||||
{"Annual Standard Deviation", "0.16"},
|
||||
{"Annual Variance", "0.026"},
|
||||
{"Information Ratio", "-4.556"},
|
||||
{"Tracking Error", "0.221"},
|
||||
{"Treynor Ratio", "-13.568"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.111"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "52.533"},
|
||||
{"Return Over Maximum Drawdown", "214.75"},
|
||||
{"Portfolio Turnover", "0.111"},
|
||||
{"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", "1268340653"}
|
||||
{"Information Ratio", "5.939"},
|
||||
{"Tracking Error", "0.16"},
|
||||
{"Treynor Ratio", "0.055"},
|
||||
{"Total Fees", "$3.26"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,15 +53,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// set algorithm framework models
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
|
||||
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, null));
|
||||
|
||||
// We can define who often the EWPCM will rebalance if no new insight is submitted using:
|
||||
// Resolution Enum:
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Resolution.Daily));
|
||||
// TimeSpan
|
||||
// SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(TimeSpan.FromDays(2)));
|
||||
// A Func<DateTime, DateTime>. In this case, we can use the pre-defined func at Expiry helper class
|
||||
// SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel(Expiry.EndOfWeek));
|
||||
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
SetRiskManagement(new MaximumDrawdownPercentPerSecurity(0.01m));
|
||||
}
|
||||
@@ -91,44 +83,37 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-1.01%"},
|
||||
{"Compounding Annual Return", "254.782%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Average Loss", "-1.03%"},
|
||||
{"Compounding Annual Return", "245.167%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.632%"},
|
||||
{"Sharpe Ratio", "8.371"},
|
||||
{"Probabilistic Sharpe Ratio", "66.555%"},
|
||||
{"Net Profit", "1.597%"},
|
||||
{"Sharpe Ratio", "4.169"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.088"},
|
||||
{"Beta", "1.006"},
|
||||
{"Annual Standard Deviation", "0.221"},
|
||||
{"Annual Variance", "0.049"},
|
||||
{"Information Ratio", "-32.586"},
|
||||
{"Tracking Error", "0.002"},
|
||||
{"Treynor Ratio", "1.839"},
|
||||
{"Alpha", "0.007"},
|
||||
{"Beta", "73.191"},
|
||||
{"Annual Standard Deviation", "0.195"},
|
||||
{"Annual Variance", "0.038"},
|
||||
{"Information Ratio", "4.113"},
|
||||
{"Tracking Error", "0.195"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$9.77"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "85.209"},
|
||||
{"Portfolio Turnover", "0.747"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$126657.6305"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
|
||||
{"Mean Population Estimated Insight Value", "$206.1207"},
|
||||
{"Estimated Monthly Alpha Value", "$158418.3850"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
|
||||
{"Mean Population Estimated Insight Value", "$257.8077"},
|
||||
{"Mean Population Direction", "54.5455%"},
|
||||
{"Mean Population Magnitude", "54.5455%"},
|
||||
{"Rolling Averaged Population Direction", "59.8056%"},
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"},
|
||||
{"OrderListHash", "951346025"}
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -20,7 +20,6 @@ using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -34,15 +33,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contractSymbol;
|
||||
|
||||
// S&P 500 EMini futures
|
||||
private const string RootSP500 = Futures.Indices.SP500EMini;
|
||||
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
|
||||
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.USA);
|
||||
|
||||
// Gold futures
|
||||
private const string RootGold = Futures.Metals.Gold;
|
||||
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.COMEX);
|
||||
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.USA);
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
@@ -57,10 +54,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var futureGold = AddFuture(RootGold);
|
||||
|
||||
// set our expiry filter for this futures chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
futureGold.SetFilter(0, 182);
|
||||
futureGold.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
|
||||
var benchmark = AddEquity("SPY");
|
||||
SetBenchmark(benchmark.Symbol);
|
||||
@@ -86,8 +81,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// if found, trade it
|
||||
if (contract != null)
|
||||
{
|
||||
_contractSymbol = contract.Symbol;
|
||||
MarketOrder(_contractSymbol, 1);
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,21 +91,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
// Get the margin requirements
|
||||
var buyingPowerModel = Securities[_contractSymbol].BuyingPowerModel;
|
||||
var futureMarginModel = buyingPowerModel as FutureMarginModel;
|
||||
if (buyingPowerModel == null)
|
||||
{
|
||||
throw new Exception($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
|
||||
}
|
||||
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
|
||||
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
|
||||
var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;
|
||||
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@@ -134,39 +113,19 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "13.500%"},
|
||||
{"Expectancy", "-0.818"},
|
||||
{"Net Profit", "-13.517%"},
|
||||
{"Sharpe Ratio", "-2.678"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Sharpe Ratio", "-29.354"},
|
||||
{"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"},
|
||||
{"Alpha", "-7.746"},
|
||||
{"Beta", "-0.859"},
|
||||
{"Annual Standard Deviation", "0.305"},
|
||||
{"Annual Variance", "0.093"},
|
||||
{"Information Ratio", "-24.985"},
|
||||
{"Tracking Error", "0.414"},
|
||||
{"Treynor Ratio", "10.413"},
|
||||
{"Total Fees", "$15207.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", "-1197265007"}
|
||||
{"Fitness Score", "0.033"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public class BasicTemplateFuturesConsolidationAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const string RootSP500 = Futures.Indices.SP500EMini;
|
||||
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
|
||||
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.USA);
|
||||
private HashSet<Symbol> _futureContracts = new HashSet<Symbol>();
|
||||
|
||||
public override void Initialize()
|
||||
@@ -43,11 +43,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(1000000);
|
||||
|
||||
var futureSP500 = AddFuture(RootSP500);
|
||||
// set our expiry filter for this future chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(0, 182);
|
||||
// futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
|
||||
SetBenchmark(x => 0);
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var newYorkTime = utcTime.ConvertFromUtc(TimeZones.NewYork);
|
||||
if (newYorkTime.Date < new DateTime(2013, 10, 09))
|
||||
{
|
||||
yield return QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
yield return QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.USA);
|
||||
}
|
||||
|
||||
if (newYorkTime.Date >= new DateTime(2013, 10, 09))
|
||||
{
|
||||
yield return QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX);
|
||||
yield return QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.USA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,25 +142,18 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "5.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-3.312%"},
|
||||
{"Sharpe Ratio", "-7.795"},
|
||||
{"Probabilistic Sharpe Ratio", "0.164%"},
|
||||
{"Sharpe Ratio", "-16.986"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-1.347"},
|
||||
{"Beta", "0.257"},
|
||||
{"Annual Standard Deviation", "0.109"},
|
||||
{"Annual Variance", "0.012"},
|
||||
{"Information Ratio", "-14.763"},
|
||||
{"Tracking Error", "0.188"},
|
||||
{"Treynor Ratio", "-3.318"},
|
||||
{"Alpha", "-0.828"},
|
||||
{"Beta", "-77.873"},
|
||||
{"Annual Standard Deviation", "0.099"},
|
||||
{"Annual Variance", "0.01"},
|
||||
{"Information Ratio", "-17.076"},
|
||||
{"Tracking Error", "0.099"},
|
||||
{"Treynor Ratio", "0.022"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0.009"},
|
||||
{"Kelly Criterion Estimate", "-112.972"},
|
||||
{"Kelly Criterion Probability Value", "0.671"},
|
||||
{"Sortino Ratio", "-8.425"},
|
||||
{"Return Over Maximum Drawdown", "-35.219"},
|
||||
{"Portfolio Turnover", "0.548"},
|
||||
{"Total Insights Generated", "6"},
|
||||
{"Total Insights Closed", "5"},
|
||||
{"Total Insights Analysis Completed", "5"},
|
||||
@@ -173,8 +166,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1624258832"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -34,7 +32,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="history and warm up" />
|
||||
/// <meta name="tag" content="history" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm
|
||||
{
|
||||
// S&P 500 EMini futures
|
||||
private string [] roots = new []
|
||||
@@ -43,8 +41,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Futures.Metals.Gold,
|
||||
};
|
||||
|
||||
private int _successCount = 0;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 8);
|
||||
@@ -58,26 +54,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
|
||||
SetBenchmark(d => 1000000);
|
||||
|
||||
Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);
|
||||
}
|
||||
|
||||
private void MakeHistoryCall()
|
||||
{
|
||||
var history = History(10, Resolution.Minute);
|
||||
if (history.Count() < 10)
|
||||
{
|
||||
throw new Exception($"Empty history at {Time}");
|
||||
}
|
||||
_successCount++;
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_successCount < 49)
|
||||
{
|
||||
throw new Exception($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,12 +68,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
foreach (var contract in chain.Value)
|
||||
{
|
||||
Log($"{contract.Symbol.Value}," +
|
||||
$"Bid={contract.BidPrice.ToStringInvariant()} " +
|
||||
$"Ask={contract.AskPrice.ToStringInvariant()} " +
|
||||
$"Last={contract.LastPrice.ToStringInvariant()} " +
|
||||
$"OI={contract.OpenInterest.ToStringInvariant()}"
|
||||
);
|
||||
Log(String.Format("{0},Bid={1} Ask={2} Last={3} OI={4}",
|
||||
contract.Symbol.Value,
|
||||
contract.BidPrice,
|
||||
contract.AskPrice,
|
||||
contract.LastPrice,
|
||||
contract.OpenInterest));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,62 +100,5 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
Log(orderEvent.ToString());
|
||||
}
|
||||
|
||||
/// <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", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -56,12 +56,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// setting up S&P 500 EMini futures
|
||||
var futureSP500 = AddFuture(Futures.Indices.SP500EMini);
|
||||
_futureSymbol = futureSP500.Symbol;
|
||||
|
||||
|
||||
// set our expiry filter for this futures chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(10, 182);
|
||||
// futureSP500.SetFilter(TimeSpan.FromDays(10), TimeSpan.FromDays(182));
|
||||
futureSP500.SetFilter(TimeSpan.FromDays(10), TimeSpan.FromDays(182));
|
||||
|
||||
// setting up Dow Jones ETF Options
|
||||
var option = AddOption("DIA");
|
||||
@@ -69,11 +66,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
option.PriceModel = OptionPriceModels.BinomialCoxRossRubinstein();
|
||||
// option.EnableGreekApproximation = true;
|
||||
// set our strike/expiry filter for this option chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
option.SetFilter(-2, +2, 0, 180);
|
||||
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
// set our expiry filter for this option chain
|
||||
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
|
||||
// specifying zero benchmark
|
||||
SetBenchmark(date => 0m);
|
||||
@@ -137,26 +131,26 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
if (_barCount % 20 == 1)
|
||||
{
|
||||
Log($"P/L:{Portfolio.TotalUnrealisedProfit.ToStringInvariant("0.00")}, " +
|
||||
$"Fees:{Portfolio.TotalFees.ToStringInvariant("0.00")}, " +
|
||||
$"Profit:{Portfolio.TotalProfit.ToStringInvariant("0.00")}, " +
|
||||
$"Eq:{Portfolio.TotalPortfolioValue.ToStringInvariant("0.00")}, " +
|
||||
$"Holdings:{Portfolio.TotalHoldingsValue.ToStringInvariant("0.00")}, " +
|
||||
$"Vol: {Portfolio.TotalSaleVolume.ToStringInvariant("0.00")}, " +
|
||||
$"Margin: {Portfolio.TotalMarginUsed.ToStringInvariant("0.00")}"
|
||||
);
|
||||
Log(String.Format("P/L:{0:0.00}, Fees:{1:0.00}, Profit:{2:0.00}, Eq:{3:0.00}, Holdings:{4:0.00}, Vol: {5:0.00}, Margin: {6:0.00}",
|
||||
Portfolio.TotalUnrealisedProfit,
|
||||
Portfolio.TotalFees,
|
||||
Portfolio.TotalProfit,
|
||||
Portfolio.TotalPortfolioValue,
|
||||
Portfolio.TotalHoldingsValue,
|
||||
Portfolio.TotalSaleVolume,
|
||||
Portfolio.TotalMarginUsed));
|
||||
|
||||
foreach (var holding in Securities.Values.OrderByDescending(x => x.Holdings.AbsoluteQuantity))
|
||||
{
|
||||
Log($" - {holding.Symbol.Value}, " +
|
||||
$"Avg Prc:{holding.Holdings.AveragePrice.ToStringInvariant("0.00")}, " +
|
||||
$"Qty:{holding.Holdings.Quantity.ToStringInvariant("0.00")}, " +
|
||||
$"Mkt Prc:{holding.Holdings.Price.ToStringInvariant("0.00")}, " +
|
||||
$"Mkt Val:{holding.Holdings.HoldingsValue.ToStringInvariant("0.00")}, " +
|
||||
$"Unreal P/L: {holding.Holdings.UnrealizedProfit.ToStringInvariant("0.00")}, " +
|
||||
$"Fees: {holding.Holdings.TotalFees.ToStringInvariant("0.00")}, " +
|
||||
$"Vol: {holding.Holdings.TotalSaleVolume.ToStringInvariant("0.00")}"
|
||||
);
|
||||
Log(String.Format(" - {0}, Avg Prc:{1:0.00}, Qty:{2:0.00}, Mkt Prc:{3:0.00}, Mkt Val:{4:0.00}, Unreal P/L: {5:0.00}, Fees: {6:0.00}, Vol: {7:0.00}",
|
||||
holding.Symbol.Value,
|
||||
holding.Holdings.AveragePrice,
|
||||
holding.Holdings.Quantity,
|
||||
holding.Holdings.Price,
|
||||
holding.Holdings.HoldingsValue,
|
||||
holding.Holdings.UnrealizedProfit,
|
||||
holding.Holdings.TotalFees,
|
||||
holding.Holdings.TotalSaleVolume));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,20 +161,21 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var underlying = Securities[chain.Key.Underlying];
|
||||
foreach (var contract in chain.Value)
|
||||
{
|
||||
Log($"{Time.ToStringInvariant()} {contract.Symbol.Value}," +
|
||||
$"B={contract.BidPrice.ToStringInvariant()} " +
|
||||
$"A={contract.AskPrice.ToStringInvariant()} " +
|
||||
$"L={contract.LastPrice.ToStringInvariant()} " +
|
||||
$"OI={contract.OpenInterest.ToStringInvariant()} " +
|
||||
$"σ={underlying.VolatilityModel.Volatility:0.00} " +
|
||||
$"NPV={contract.TheoreticalPrice.ToStringInvariant("0.00")} " +
|
||||
$"Δ={contract.Greeks.Delta.ToStringInvariant("0.00")} " +
|
||||
$"Γ={contract.Greeks.Gamma.ToStringInvariant("0.00")} " +
|
||||
$"ν={contract.Greeks.Vega.ToStringInvariant("0.00")} " +
|
||||
$"ρ={contract.Greeks.Rho.ToStringInvariant("0.00")} " +
|
||||
$"Θ={(contract.Greeks.Theta / 365.0m).ToStringInvariant("0.00")} " +
|
||||
$"IV={contract.ImpliedVolatility.ToStringInvariant("0.00")}"
|
||||
);
|
||||
Log(String.Format(@"{0} {1},B={2} A={3} L={4} OI={5} σ={6:0.00} NPV={7:0.00} Δ={8:0.00} Γ={9:0.00} ν={10:0.00} ρ={11:0.00} Θ={12:0.00} IV={13:0.00}",
|
||||
Time.ToString(),
|
||||
contract.Symbol.Value,
|
||||
contract.BidPrice,
|
||||
contract.AskPrice,
|
||||
contract.LastPrice,
|
||||
contract.OpenInterest,
|
||||
underlying.VolatilityModel.Volatility,
|
||||
contract.TheoreticalPrice,
|
||||
contract.Greeks.Delta,
|
||||
contract.Greeks.Gamma,
|
||||
contract.Greeks.Vega,
|
||||
contract.Greeks.Rho,
|
||||
contract.Greeks.Theta / 365.0m,
|
||||
contract.ImpliedVolatility));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,12 +183,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
foreach (var contract in chain.Value)
|
||||
{
|
||||
Log($"{contract.Symbol.Value}, {Time}, " +
|
||||
$"B={contract.BidPrice} " +
|
||||
$"A={contract.AskPrice} " +
|
||||
$"L={contract.LastPrice} " +
|
||||
$"OI={contract.OpenInterest}"
|
||||
);
|
||||
Log(String.Format("{0}, {1}, B={2} A={3} L={4} OI={5}",
|
||||
contract.Symbol.Value,
|
||||
Time,
|
||||
contract.BidPrice,
|
||||
contract.AskPrice,
|
||||
contract.LastPrice,
|
||||
contract.OpenInterest));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,7 +201,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
foreach (var kpv in slice.Bars)
|
||||
{
|
||||
Log($"---> Bar: {Time}, {kpv.Key.Value}, {kpv.Value.Close.ToStringInvariant("0.0000")}");
|
||||
Log($"---> Bar: {Time}, {kpv.Key.Value}, {kpv.Value.Close:0.0000}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -48,10 +48,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
_optionSymbol = option.Symbol;
|
||||
|
||||
// set our strike/expiry filter for this option chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
option.SetFilter(-2, +2, 0, 180);
|
||||
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
|
||||
// Adding this to reproduce GH issue #2314
|
||||
SetWarmup(TimeSpan.FromMinutes(1));
|
||||
@@ -116,14 +113,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "778"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-100%"},
|
||||
{"Drawdown", "6.900%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-6.860%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
@@ -133,27 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$778.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Return Over Maximum Drawdown", "0"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-702975961"}
|
||||
{"Total Fees", "$778.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
_optionSymbol = option.Symbol;
|
||||
|
||||
// set our strike/expiry filter for this option chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yields the same filtering criteria
|
||||
option.SetFilter(-2, +2, 0, 10);
|
||||
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(10));
|
||||
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(10));
|
||||
|
||||
// use the underlying equity as the benchmark
|
||||
SetBenchmark("GOOG");
|
||||
|
||||
@@ -35,7 +35,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public class BasicTemplateOptionsAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private const string UnderlyingTicker = "GOOG";
|
||||
public Symbol OptionSymbol;
|
||||
public readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
|
||||
public readonly Symbol OptionSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -45,14 +46,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
var equity = AddEquity(UnderlyingTicker);
|
||||
var option = AddOption(UnderlyingTicker);
|
||||
OptionSymbol = option.Symbol;
|
||||
|
||||
// set our strike/expiry filter for this option chain
|
||||
option.SetFilter(u => u.Strikes(-2, +2)
|
||||
// Expiration method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
.Expiration(0, 180));
|
||||
// .Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
|
||||
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(180)));
|
||||
|
||||
// use the underlying equity as the benchmark
|
||||
SetBenchmark(equity.Symbol);
|
||||
@@ -113,14 +110,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Average Loss", "-0.28%"},
|
||||
{"Compounding Annual Return", "-78.282%"},
|
||||
{"Drawdown", "0.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.282%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
@@ -130,27 +126,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Return Over Maximum Drawdown", "0"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1130102123"}
|
||||
{"Total Fees", "$2.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public class BasicTemplateOptionsFilterUniverseAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const string UnderlyingTicker = "GOOG";
|
||||
public Symbol OptionSymbol;
|
||||
public readonly Symbol Underlying = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Equity, Market.USA);
|
||||
public readonly Symbol OptionSymbol = QuantConnect.Symbol.Create(UnderlyingTicker, SecurityType.Option, Market.USA);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -48,10 +49,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// set our custom filter for this option chain
|
||||
option.SetFilter(universe => from symbol in universe
|
||||
.WeeklysOnly()
|
||||
// Expiration method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
.Expiration(0, 10)
|
||||
// .Expiration(TimeSpan.Zero, TimeSpan.FromDays(10))
|
||||
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(10))
|
||||
where symbol.ID.OptionRight != OptionRight.Put &&
|
||||
universe.Underlying.Price - symbol.ID.StrikePrice < 60
|
||||
select symbol);
|
||||
|
||||
@@ -80,10 +80,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
return filter
|
||||
.Strikes(+1, +1)
|
||||
// Expiration method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
.Expiration(0, 7)
|
||||
//.Expiration(TimeSpan.Zero, TimeSpan.FromDays(7))
|
||||
.Expiration(TimeSpan.Zero, TimeSpan.FromDays(7))
|
||||
.WeeklysOnly()
|
||||
.PutsOnly()
|
||||
.OnlyApplyFilterAtMarketOpen();
|
||||
@@ -142,45 +139,37 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Win", "0.14%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Compounding Annual Return", "71.396%"},
|
||||
{"Drawdown", "0.700%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "0.271%"},
|
||||
{"Sharpe Ratio", "9.165"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Beta", "24.746"},
|
||||
{"Annual Standard Deviation", "0.025"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "8.883"},
|
||||
{"Tracking Error", "0.025"},
|
||||
{"Treynor Ratio", "0.009"},
|
||||
{"Total Fees", "$4.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0.327"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "26"},
|
||||
{"Total Insights Closed", "24"},
|
||||
{"Total Insights Analysis Completed", "24"},
|
||||
{"Long Insight Count", "26"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$31.01809"},
|
||||
{"Estimated Monthly Alpha Value", "$28.43325"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$1.89555"},
|
||||
{"Mean Population Estimated Insight Value", "$0.07898125"},
|
||||
{"Mean Population Direction", "50%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "50.0482%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "352959406"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(1000000);
|
||||
|
||||
var option = AddOption("GOOG");
|
||||
// add the initial contract filter
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
option.SetFilter(-2, +2, 0, 180);
|
||||
// option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
// add the initial contract filter
|
||||
option.SetFilter(-2, +2, TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
|
||||
// set the pricing model for Greeks and volatility
|
||||
// find more pricing models https://www.quantconnect.com/lean/documentation/topic27704.html
|
||||
@@ -68,20 +65,20 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var underlying = Securities[chain.Key.Underlying];
|
||||
foreach (var contract in chain.Value)
|
||||
{
|
||||
Log($"{contract.Symbol.Value}," +
|
||||
$"Bid={contract.BidPrice.ToStringInvariant()} " +
|
||||
$"Ask={contract.AskPrice.ToStringInvariant()} " +
|
||||
$"Last={contract.LastPrice.ToStringInvariant()} " +
|
||||
$"OI={contract.OpenInterest.ToStringInvariant()} " +
|
||||
$"σ={underlying.VolatilityModel.Volatility.ToStringInvariant("0.000")} " +
|
||||
$"NPV={contract.TheoreticalPrice.ToStringInvariant("0.000")} " +
|
||||
$"Δ={contract.Greeks.Delta.ToStringInvariant("0.000")} " +
|
||||
$"Γ={contract.Greeks.Gamma.ToStringInvariant("0.000")} " +
|
||||
$"ν={contract.Greeks.Vega.ToStringInvariant("0.000")} " +
|
||||
$"ρ={contract.Greeks.Rho.ToStringInvariant("0.00")} " +
|
||||
$"Θ={(contract.Greeks.Theta / 365.0m).ToStringInvariant("0.00")} " +
|
||||
$"IV={contract.ImpliedVolatility.ToStringInvariant("0.000")}"
|
||||
);
|
||||
Log(String.Format(@"{0},Bid={1} Ask={2} Last={3} OI={4} σ={5:0.000} NPV={6:0.000} Δ={7:0.000} Γ={8:0.000} ν={9:0.000} ρ={10:0.00} Θ={11:0.00} IV={12:0.000}",
|
||||
contract.Symbol.Value,
|
||||
contract.BidPrice,
|
||||
contract.AskPrice,
|
||||
contract.LastPrice,
|
||||
contract.OpenInterest,
|
||||
underlying.VolatilityModel.Volatility,
|
||||
contract.TheoreticalPrice,
|
||||
contract.Greeks.Delta,
|
||||
contract.Greeks.Gamma,
|
||||
contract.Greeks.Vega,
|
||||
contract.Greeks.Rho,
|
||||
contract.Greeks.Theta / 365.0m,
|
||||
contract.ImpliedVolatility));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
public class SECReportBenchmarkAlgorithm : QCAlgorithm
|
||||
{
|
||||
private List<Security> _securities;
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2018, 1, 1);
|
||||
SetEndDate(2019, 1, 1);
|
||||
|
||||
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
|
||||
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
|
||||
_securities = new List<Security>();
|
||||
|
||||
foreach (var ticker in tickers)
|
||||
{
|
||||
var equity = AddEquity(ticker);
|
||||
_securities.Add(equity);
|
||||
|
||||
AddData<SECReport8K>(equity.Symbol, Resolution.Daily);
|
||||
AddData<SECReport10K>(equity.Symbol, Resolution.Daily);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var security in _securities)
|
||||
{
|
||||
SECReport8K report8K = security.Data.Get<SECReport8K>();
|
||||
SECReport10K report10K = security.Data.Get<SECReport10K>();
|
||||
|
||||
if (!security.HoldStock && report8K != null && report10K != null)
|
||||
{
|
||||
SetHoldings(security.Symbol, 1d / _securities.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SmartInsider;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
public class SmartInsiderEventBenchmarkAlgorithm : QCAlgorithm
|
||||
{
|
||||
private List<Security> _securities;
|
||||
private List<Symbol> _customSymbols;
|
||||
private int _historySymbolCount;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2010, 1, 1);
|
||||
SetEndDate(2019, 1, 1);
|
||||
|
||||
var tickers = new List<string> {"AAPL", "AMZN", "MSFT", "IBM", "FB", "QQQ",
|
||||
"IWM", "BAC", "BNO", "AIG", "UW", "WM" };
|
||||
_securities = new List<Security>();
|
||||
_customSymbols = new List<Symbol>();
|
||||
|
||||
foreach (var ticker in tickers)
|
||||
{
|
||||
var equity = AddEquity(ticker, Resolution.Hour);
|
||||
_securities.Add(equity);
|
||||
|
||||
_customSymbols.Add(
|
||||
AddData<SmartInsiderIntention>(equity.Symbol, Resolution.Daily).Symbol);
|
||||
_customSymbols.Add(
|
||||
AddData<SmartInsiderTransaction>(equity.Symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
|
||||
Schedule.On(DateRules.EveryDay(), TimeRules.At(16, 0), () =>
|
||||
{
|
||||
foreach (var slice in History(_customSymbols, TimeSpan.FromDays(5)))
|
||||
{
|
||||
_historySymbolCount += slice.Count;
|
||||
}
|
||||
|
||||
foreach (var security in _securities)
|
||||
{
|
||||
SmartInsiderIntention intention = security.Data.Get<SmartInsiderIntention>();
|
||||
SmartInsiderTransaction transaction = security.Data.Get<SmartInsiderTransaction>();
|
||||
|
||||
if (!security.HoldStock && intention != null && transaction != null)
|
||||
{
|
||||
SetHoldings(security.Symbol, 1d / _securities.Count);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var intentions = data.Get<SmartInsiderIntention>();
|
||||
var transactions = data.Get<SmartInsiderTransaction>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,46 +74,38 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "18"},
|
||||
{"Total Trades", "21"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.16%"},
|
||||
{"Compounding Annual Return", "72.164%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Average Loss", "-0.38%"},
|
||||
{"Compounding Annual Return", "-82.823%"},
|
||||
{"Drawdown", "4.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "0.747%"},
|
||||
{"Sharpe Ratio", "4.086"},
|
||||
{"Probabilistic Sharpe Ratio", "61.091%"},
|
||||
{"Net Profit", "-2.384%"},
|
||||
{"Sharpe Ratio", "-6.465"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.305"},
|
||||
{"Beta", "0.564"},
|
||||
{"Annual Standard Deviation", "0.113"},
|
||||
{"Annual Variance", "0.013"},
|
||||
{"Information Ratio", "-10.007"},
|
||||
{"Tracking Error", "0.09"},
|
||||
{"Treynor Ratio", "0.82"},
|
||||
{"Total Fees", "$41.70"},
|
||||
{"Fitness Score", "0.634"},
|
||||
{"Kelly Criterion Estimate", "13.656"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "80.05"},
|
||||
{"Portfolio Turnover", "0.634"},
|
||||
{"Total Insights Generated", "17"},
|
||||
{"Total Insights Closed", "14"},
|
||||
{"Total Insights Analysis Completed", "14"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "-87.084"},
|
||||
{"Annual Standard Deviation", "0.155"},
|
||||
{"Annual Variance", "0.024"},
|
||||
{"Information Ratio", "-6.536"},
|
||||
{"Tracking Error", "0.155"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$72.41"},
|
||||
{"Total Insights Generated", "14"},
|
||||
{"Total Insights Closed", "11"},
|
||||
{"Total Insights Analysis Completed", "11"},
|
||||
{"Long Insight Count", "6"},
|
||||
{"Short Insight Count", "7"},
|
||||
{"Long/Short Ratio", "85.71%"},
|
||||
{"Estimated Monthly Alpha Value", "$72447.6813"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$12477.1007"},
|
||||
{"Mean Population Estimated Insight Value", "$891.2215"},
|
||||
{"Mean Population Direction", "50%"},
|
||||
{"Mean Population Magnitude", "50%"},
|
||||
{"Rolling Averaged Population Direction", "12.6429%"},
|
||||
{"Rolling Averaged Population Magnitude", "12.6429%"},
|
||||
{"OrderListHash", "-2004493274"}
|
||||
{"Short Insight Count", "4"},
|
||||
{"Long/Short Ratio", "150.0%"},
|
||||
{"Estimated Monthly Alpha Value", "$-85612.32"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-14744.34"},
|
||||
{"Mean Population Estimated Insight Value", "$-1340.395"},
|
||||
{"Mean Population Direction", "27.2727%"},
|
||||
{"Mean Population Magnitude", "27.2727%"},
|
||||
{"Rolling Averaged Population Direction", "5.8237%"},
|
||||
{"Rolling Averaged Population Magnitude", "5.8237%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +108,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
// return a message describing why we're not allowing this order
|
||||
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "InsufficientRemainingCapital",
|
||||
$"Account must maintain a minimum of ${_minimumAccountBalance.ToStringInvariant()} USD at all times. " +
|
||||
$"Order ID: {order.Id.ToStringInvariant()}"
|
||||
);
|
||||
string.Format("Account must maintain a minimum of ${0} USD at all times. Order ID: {1}", _minimumAccountBalance, order.Id)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -130,43 +130,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "5.600%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "-4.431%"},
|
||||
{"Sharpe Ratio", "-23.129"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0.501"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-30.28"},
|
||||
{"Portfolio Turnover", "1.029"},
|
||||
{"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", "-1708974186"}
|
||||
{"Alpha", "-8.364"},
|
||||
{"Beta", "395.811"},
|
||||
{"Annual Standard Deviation", "0.243"},
|
||||
{"Annual Variance", "0.059"},
|
||||
{"Information Ratio", "-23.216"},
|
||||
{"Tracking Error", "0.243"},
|
||||
{"Treynor Ratio", "-0.014"},
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,45 +76,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "167"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-16.316%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-0.121"},
|
||||
{"Net Profit", "-0.081%"},
|
||||
{"Sharpe Ratio", "-87.066"},
|
||||
{"Loss Rate", "49%"},
|
||||
{"Win Rate", "51%"},
|
||||
{"Profit-Loss Ratio", "0.74"},
|
||||
{"Alpha", "-0.116"},
|
||||
{"Beta", "-0.092"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0.5"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-325.922"},
|
||||
{"Portfolio Turnover", "9.561"},
|
||||
{"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", "1456907343"}
|
||||
{"Information Ratio", "2.962"},
|
||||
{"Tracking Error", "0.014"},
|
||||
{"Treynor Ratio", "1.116"},
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +74,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
};
|
||||
}
|
||||
|
||||
// sort the data by market capitalization and take the top 'NumberOfSymbolsFine'
|
||||
// sort the data by P/E ratio and take the top 'NumberOfSymbolsFine'
|
||||
public IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> fine)
|
||||
{
|
||||
// sort descending by market capitalization
|
||||
var sortedByMarketCap = fine.OrderByDescending(x => x.MarketCap);
|
||||
// sort descending by P/E ratio
|
||||
var sortedByPeRatio = fine.OrderByDescending(x => x.ValuationRatios.PERatio);
|
||||
|
||||
// take the top entries from our sorted collection
|
||||
var topFine = sortedByMarketCap.Take(NumberOfSymbolsFine);
|
||||
var topFine = sortedByPeRatio.Take(NumberOfSymbolsFine);
|
||||
|
||||
// we need to return only the symbol objects
|
||||
return topFine.Select(x => x.Symbol);
|
||||
@@ -162,45 +162,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "1.16%"},
|
||||
{"Average Win", "1.39%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "32.515%"},
|
||||
{"Compounding Annual Return", "40.038%"},
|
||||
{"Drawdown", "1.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.164%"},
|
||||
{"Sharpe Ratio", "2.857"},
|
||||
{"Probabilistic Sharpe Ratio", "64.822%"},
|
||||
{"Net Profit", "1.394%"},
|
||||
{"Sharpe Ratio", "3.081"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.237"},
|
||||
{"Beta", "-0.182"},
|
||||
{"Annual Standard Deviation", "0.09"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "2.425"},
|
||||
{"Tracking Error", "0.149"},
|
||||
{"Treynor Ratio", "-1.405"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Fitness Score", "0.076"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "27.329"},
|
||||
{"Return Over Maximum Drawdown", "24.003"},
|
||||
{"Portfolio Turnover", "0.076"},
|
||||
{"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", "-1465929889"}
|
||||
{"Alpha", "-0.033"},
|
||||
{"Beta", "19.023"},
|
||||
{"Annual Standard Deviation", "0.096"},
|
||||
{"Annual Variance", "0.009"},
|
||||
{"Information Ratio", "2.904"},
|
||||
{"Tracking Error", "0.096"},
|
||||
{"Treynor Ratio", "0.016"},
|
||||
{"Total Fees", "$2.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,43 +119,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "11"},
|
||||
{"Average Win", "0.51%"},
|
||||
{"Average Loss", "-0.33%"},
|
||||
{"Compounding Annual Return", "-31.082%"},
|
||||
{"Compounding Annual Return", "-31.051%"},
|
||||
{"Drawdown", "2.700%"},
|
||||
{"Expectancy", "0.263"},
|
||||
{"Net Profit", "-1.518%"},
|
||||
{"Sharpe Ratio", "-2.118"},
|
||||
{"Probabilistic Sharpe Ratio", "23.259%"},
|
||||
{"Net Profit", "-1.516%"},
|
||||
{"Sharpe Ratio", "-2.526"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "1.53"},
|
||||
{"Alpha", "-0.208"},
|
||||
{"Beta", "0.415"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "-1.167"},
|
||||
{"Tracking Error", "0.126"},
|
||||
{"Treynor Ratio", "-0.607"},
|
||||
{"Total Fees", "$11.63"},
|
||||
{"Fitness Score", "0.013"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-5.1"},
|
||||
{"Return Over Maximum Drawdown", "-11.717"},
|
||||
{"Portfolio Turnover", "0.282"},
|
||||
{"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", "-1623759093"}
|
||||
{"Alpha", "-0.556"},
|
||||
{"Beta", "14.058"},
|
||||
{"Annual Standard Deviation", "0.124"},
|
||||
{"Annual Variance", "0.015"},
|
||||
{"Information Ratio", "-2.666"},
|
||||
{"Tracking Error", "0.124"},
|
||||
{"Treynor Ratio", "-0.022"},
|
||||
{"Total Fees", "$11.63"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -110,30 +109,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.383"},
|
||||
{"Tracking Error", "0.096"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Test algorithm that reproduces GH issues 3410 and 3409.
|
||||
/// Coarse universe selection should start from the algorithm start date.
|
||||
/// Data returned by history requests performed from the selection method should be up to date.
|
||||
/// </summary>
|
||||
public class CoarseSelectionTimeRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
private decimal _historyCoarseSpyPrice;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 03, 25);
|
||||
SetEndDate(2014, 04, 01);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Daily).Symbol;
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
AddUniverse(CoarseSelectionFunction);
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
|
||||
var top = sortedByDollarVolume
|
||||
.Where(fundamental => fundamental.Symbol != _spy) // ignore spy
|
||||
.Take(1);
|
||||
|
||||
_historyCoarseSpyPrice = History(_spy, 1).First().Close;
|
||||
|
||||
return top.Select(x => x.Symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected data count: {data.Count}");
|
||||
}
|
||||
if (ActiveSecurities.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected ActiveSecurities count: {ActiveSecurities.Count}");
|
||||
}
|
||||
// the price obtained by the previous coarse selection should be the same as the current price
|
||||
if (_historyCoarseSpyPrice != 0 && _historyCoarseSpyPrice != Securities[_spy].Price)
|
||||
{
|
||||
throw new Exception($"Unexpected SPY price: {_historyCoarseSpyPrice}");
|
||||
}
|
||||
_historyCoarseSpyPrice = 0;
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_spy, 1);
|
||||
Debug("Purchased Stock");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "58.336%"},
|
||||
{"Drawdown", "0.900%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.012%"},
|
||||
{"Sharpe Ratio", "5.09"},
|
||||
{"Probabilistic Sharpe Ratio", "68.472%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.322"},
|
||||
{"Beta", "0.265"},
|
||||
{"Annual Standard Deviation", "0.087"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "-0.088"},
|
||||
{"Tracking Error", "0.105"},
|
||||
{"Treynor Ratio", "1.667"},
|
||||
{"Total Fees", "$2.91"},
|
||||
{"Fitness Score", "0.141"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "9.731"},
|
||||
{"Return Over Maximum Drawdown", "61.515"},
|
||||
{"Portfolio Turnover", "0.143"},
|
||||
{"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", "-1959413055"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm of a custom universe selection using coarse data and adding TiingoNews
|
||||
/// If conditions are met will add the underlying and trade it
|
||||
/// </summary>
|
||||
public class CoarseTiingoNewsUniverseSelectionAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const int NumberOfSymbols = 3;
|
||||
private List<Symbol> _symbols;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 03, 24);
|
||||
SetEndDate(2014, 04, 07);
|
||||
|
||||
UniverseSettings.FillForward = false;
|
||||
|
||||
AddUniverse(new CustomDataCoarseFundamentalUniverse(UniverseSettings, SecurityInitializer, CoarseSelectionFunction));
|
||||
|
||||
_symbols = new List<Symbol>();
|
||||
}
|
||||
|
||||
// sort the data by daily dollar volume and take the top 'NumberOfSymbols'
|
||||
public IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
// sort descending by daily dollar volume
|
||||
var sortedByDollarVolume = coarse.OrderByDescending(x => x.DollarVolume);
|
||||
|
||||
// take the top entries from our sorted collection
|
||||
var top = sortedByDollarVolume.Take(NumberOfSymbols);
|
||||
|
||||
// we need to return only the symbol objects
|
||||
return top.Select(x => QuantConnect.Symbol.CreateBase(typeof(TiingoNews), x.Symbol, x.Symbol.ID.Market));
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var articles = data.Get<TiingoNews>();
|
||||
|
||||
foreach (var kvp in articles)
|
||||
{
|
||||
var news = kvp.Value;
|
||||
if (news.Title.IndexOf("Stocks Drop", 0, StringComparison.CurrentCultureIgnoreCase) != -1)
|
||||
{
|
||||
if (!Securities.ContainsKey(kvp.Key.Underlying))
|
||||
{
|
||||
// add underlying we want to trade
|
||||
AddSecurity(kvp.Key.Underlying);
|
||||
_symbols.Add(kvp.Key.Underlying);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var symbol in _symbols)
|
||||
{
|
||||
if (Securities[symbol].HasData)
|
||||
{
|
||||
SetHoldings(symbol, 1m / _symbols.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
changes.FilterCustomSecurities = false;
|
||||
Log($"{Time} {changes}");
|
||||
}
|
||||
|
||||
private class CustomDataCoarseFundamentalUniverse : CoarseFundamentalUniverse
|
||||
{
|
||||
public CustomDataCoarseFundamentalUniverse(UniverseSettings universeSettings, ISecurityInitializer securityInitializer, Func<IEnumerable<CoarseFundamental>, IEnumerable<Symbol>> selector)
|
||||
: base(universeSettings, securityInitializer, selector)
|
||||
{ }
|
||||
|
||||
public override IEnumerable<SubscriptionRequest> GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc,
|
||||
ISubscriptionDataConfigService subscriptionService)
|
||||
{
|
||||
var config = subscriptionService.Add(
|
||||
typeof(TiingoNews),
|
||||
security.Symbol,
|
||||
UniverseSettings.Resolution,
|
||||
UniverseSettings.FillForward,
|
||||
UniverseSettings.ExtendedMarketHours,
|
||||
dataNormalizationMode: UniverseSettings.DataNormalizationMode);
|
||||
return new[]{new SubscriptionRequest(isUniverseSubscription: false,
|
||||
universe: this,
|
||||
security: security,
|
||||
configuration: config,
|
||||
startTimeUtc: currentTimeUtc,
|
||||
endTimeUtc: maximumEndTimeUtc)};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,30 +73,23 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "7"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.40%"},
|
||||
{"Compounding Annual Return", "1114.772%"},
|
||||
{"Drawdown", "1.800%"},
|
||||
{"Expectancy", "-0.319"},
|
||||
{"Net Profit", "3.244%"},
|
||||
{"Sharpe Ratio", "23.478"},
|
||||
{"Probabilistic Sharpe Ratio", "80.383%"},
|
||||
{"Average Loss", "-0.38%"},
|
||||
{"Compounding Annual Return", "1192.794%"},
|
||||
{"Drawdown", "1.700%"},
|
||||
{"Expectancy", "-0.323"},
|
||||
{"Net Profit", "3.326%"},
|
||||
{"Sharpe Ratio", "6.635"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "0.02"},
|
||||
{"Alpha", "4.314"},
|
||||
{"Beta", "1.239"},
|
||||
{"Annual Standard Deviation", "0.285"},
|
||||
{"Annual Variance", "0.081"},
|
||||
{"Information Ratio", "47.452"},
|
||||
{"Tracking Error", "0.101"},
|
||||
{"Treynor Ratio", "5.409"},
|
||||
{"Profit-Loss Ratio", "0.01"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "152.178"},
|
||||
{"Annual Standard Deviation", "0.253"},
|
||||
{"Annual Variance", "0.064"},
|
||||
{"Information Ratio", "6.594"},
|
||||
{"Tracking Error", "0.253"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$67.00"},
|
||||
{"Fitness Score", "0.501"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "148.636"},
|
||||
{"Return Over Maximum Drawdown", "1502.912"},
|
||||
{"Portfolio Turnover", "0.501"},
|
||||
{"Total Insights Generated", "2"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -109,8 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-28636839"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,45 +66,37 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "7"},
|
||||
{"Average Win", "1.02%"},
|
||||
{"Average Loss", "-1.01%"},
|
||||
{"Compounding Annual Return", "205.606%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "0.339"},
|
||||
{"Net Profit", "1.439%"},
|
||||
{"Sharpe Ratio", "7.166"},
|
||||
{"Probabilistic Sharpe Ratio", "64.794%"},
|
||||
{"Average Win", "1.00%"},
|
||||
{"Average Loss", "-1.03%"},
|
||||
{"Compounding Annual Return", "190.425%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "0.314"},
|
||||
{"Net Profit", "1.372%"},
|
||||
{"Sharpe Ratio", "3.771"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "1.01"},
|
||||
{"Alpha", "-0.341"},
|
||||
{"Beta", "0.968"},
|
||||
{"Annual Standard Deviation", "0.213"},
|
||||
{"Annual Variance", "0.045"},
|
||||
{"Information Ratio", "-46.719"},
|
||||
{"Tracking Error", "0.009"},
|
||||
{"Treynor Ratio", "1.575"},
|
||||
{"Profit-Loss Ratio", "0.97"},
|
||||
{"Alpha", "0.007"},
|
||||
{"Beta", "62.953"},
|
||||
{"Annual Standard Deviation", "0.186"},
|
||||
{"Annual Variance", "0.035"},
|
||||
{"Information Ratio", "3.713"},
|
||||
{"Tracking Error", "0.186"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$22.77"},
|
||||
{"Fitness Score", "0.999"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "69.159"},
|
||||
{"Portfolio Turnover", "1.242"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$126657.6305"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
|
||||
{"Mean Population Estimated Insight Value", "$206.1207"},
|
||||
{"Estimated Monthly Alpha Value", "$158418.3850"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$25522.9620"},
|
||||
{"Mean Population Estimated Insight Value", "$257.8077"},
|
||||
{"Mean Population Direction", "54.5455%"},
|
||||
{"Mean Population Magnitude", "54.5455%"},
|
||||
{"Rolling Averaged Population Direction", "59.8056%"},
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"},
|
||||
{"OrderListHash", "-1225025518"}
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Test algorithm using <see cref="ConfidenceWeightedPortfolioConstructionModel"/> and <see cref="ConstantAlphaModel"/>
|
||||
/// generating a constant <see cref="Insight"/> with a 0.25 confidence
|
||||
/// </summary>
|
||||
public class ConfidenceWeightedFrameworkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
// Set requested data resolution
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
// set algorithm framework models
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA)));
|
||||
SetAlpha(new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromMinutes(20), 0.025, 0.25));
|
||||
SetPortfolioConstruction(new ConfidenceWeightedPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (// holdings value should be 0.25 - to avoid price fluctuation issue we compare with 0.28 and 0.23
|
||||
Portfolio.TotalHoldingsValue > Portfolio.TotalPortfolioValue * 0.28m
|
||||
||
|
||||
Portfolio.TotalHoldingsValue < Portfolio.TotalPortfolioValue * 0.23m)
|
||||
{
|
||||
throw new Exception($"Unexpected Total Holdings Value: {Portfolio.TotalHoldingsValue}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "6"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "38.059%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-0.502"},
|
||||
{"Net Profit", "0.413%"},
|
||||
{"Sharpe Ratio", "5.518"},
|
||||
{"Probabilistic Sharpe Ratio", "66.933%"},
|
||||
{"Loss Rate", "67%"},
|
||||
{"Win Rate", "33%"},
|
||||
{"Profit-Loss Ratio", "0.50"},
|
||||
{"Alpha", "-0.178"},
|
||||
{"Beta", "0.249"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-9.844"},
|
||||
{"Tracking Error", "0.165"},
|
||||
{"Treynor Ratio", "1.212"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Fitness Score", "0.063"},
|
||||
{"Kelly Criterion Estimate", "38.64"},
|
||||
{"Kelly Criterion Probability Value", "0.229"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "70.188"},
|
||||
{"Portfolio Turnover", "0.063"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$126657.6305"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$20405.9516"},
|
||||
{"Mean Population Estimated Insight Value", "$206.1207"},
|
||||
{"Mean Population Direction", "54.5455%"},
|
||||
{"Mean Population Magnitude", "54.5455%"},
|
||||
{"Rolling Averaged Population Direction", "59.8056%"},
|
||||
{"Rolling Averaged Population Magnitude", "59.8056%"},
|
||||
{"OrderListHash", "501060991"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Consolidators;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing data type bugs in the Consolidate API. Related to GH 4205.
|
||||
/// </summary>
|
||||
public class ConsolidateRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<int> _consolidationCount;
|
||||
private int _customDataConsolidator;
|
||||
private Symbol _symbol;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 09);
|
||||
|
||||
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
|
||||
AddFutureContract(_symbol);
|
||||
|
||||
_consolidationCount = new List<int> { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
var sma = new SimpleMovingAverage(10);
|
||||
Consolidate<QuoteBar>(_symbol, time => new CalendarInfo(time.RoundDown(TimeSpan.FromDays(1)), TimeSpan.FromDays(1)),
|
||||
bar => UpdateQuoteBar(sma, bar, 0));
|
||||
|
||||
var sma2 = new SimpleMovingAverage(10);
|
||||
Consolidate<QuoteBar>(_symbol, TimeSpan.FromDays(1), bar => UpdateQuoteBar(sma2, bar, 1));
|
||||
|
||||
var sma3 = new SimpleMovingAverage(10);
|
||||
Consolidate(_symbol, Resolution.Daily, TickType.Quote, (Action<QuoteBar>)(bar => UpdateQuoteBar(sma3, bar, 2)));
|
||||
|
||||
var sma4 = new SimpleMovingAverage(10);
|
||||
Consolidate(_symbol, TimeSpan.FromDays(1), bar => UpdateTradeBar(sma4, bar, 3));
|
||||
|
||||
var sma5 = new SimpleMovingAverage(10);
|
||||
Consolidate<TradeBar>(_symbol, TimeSpan.FromDays(1), bar => UpdateTradeBar(sma5, bar, 4));
|
||||
|
||||
// custom data
|
||||
var sma6 = new SimpleMovingAverage(10);
|
||||
var symbol = AddData<CustomDataRegressionAlgorithm.Bitcoin>("BTC", Resolution.Minute).Symbol;
|
||||
Consolidate<TradeBar>(symbol, TimeSpan.FromDays(1), bar => _customDataConsolidator++);
|
||||
|
||||
try
|
||||
{
|
||||
Consolidate<QuoteBar>(symbol, TimeSpan.FromDays(1), bar => { UpdateQuoteBar(sma6, bar, -1); });
|
||||
throw new Exception($"Expected {nameof(ArgumentException)} to be thrown");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// will try to use BaseDataConsolidator for which input is TradeBars not QuoteBars
|
||||
}
|
||||
|
||||
// Test using abstract T types, through defining a 'BaseData' handler
|
||||
var sma7 = new SimpleMovingAverage(10);
|
||||
Consolidate(_symbol, Resolution.Daily, null, (Action<BaseData>)(bar => UpdateBar(sma7, bar, 5)));
|
||||
|
||||
var sma8 = new SimpleMovingAverage(10);
|
||||
Consolidate(_symbol, TimeSpan.FromDays(1), null, (Action<BaseData>)(bar => UpdateBar(sma8, bar, 6)));
|
||||
|
||||
var sma9 = new SimpleMovingAverage(10);
|
||||
Consolidate(_symbol, TimeSpan.FromDays(1), (Action<BaseData>)(bar => UpdateBar(sma9, bar, 7)));
|
||||
}
|
||||
private void UpdateBar(SimpleMovingAverage sma, BaseData tradeBar, int position)
|
||||
{
|
||||
if (!(tradeBar is TradeBar))
|
||||
{
|
||||
throw new Exception("Expected a TradeBar");
|
||||
}
|
||||
_consolidationCount[position]++;
|
||||
sma.Update(tradeBar.EndTime, tradeBar.Value);
|
||||
}
|
||||
private void UpdateTradeBar(SimpleMovingAverage sma, TradeBar tradeBar, int position)
|
||||
{
|
||||
_consolidationCount[position]++;
|
||||
sma.Update(tradeBar.EndTime, tradeBar.High);
|
||||
}
|
||||
private void UpdateQuoteBar(SimpleMovingAverage sma, QuoteBar quoteBar, int position)
|
||||
{
|
||||
_consolidationCount[position]++;
|
||||
sma.Update(quoteBar.EndTime, quoteBar.High);
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_consolidationCount.Any(i => i != 3) || _customDataConsolidator == 0)
|
||||
{
|
||||
throw new Exception("Unexpected consolidation count");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_symbol, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-99.999%"},
|
||||
{"Drawdown", "16.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-6.366%"},
|
||||
{"Sharpe Ratio", "1.194"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "5.579"},
|
||||
{"Beta", "-63.972"},
|
||||
{"Annual Standard Deviation", "0.434"},
|
||||
{"Annual Variance", "0.188"},
|
||||
{"Information Ratio", "0.996"},
|
||||
{"Tracking Error", "0.441"},
|
||||
{"Treynor Ratio", "-0.008"},
|
||||
{"Total Fees", "$20.35"},
|
||||
{"Fitness Score", "0.138"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.727"},
|
||||
{"Return Over Maximum Drawdown", "-12.061"},
|
||||
{"Portfolio Turnover", "4.916"},
|
||||
{"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", "-1453269600"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -13,12 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstration of how to estimate constituents of QC500 index based on the company fundamentals
|
||||
/// The algorithm creates a default tradable and liquid universe containing 500 US equities
|
||||
/// which are chosen at the first trading day of each month.
|
||||
/// The algorithm creates a default tradable and liquid universe containing 500 US equities
|
||||
/// which are chosen at the first trading day of each month.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="universes" />
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm used to generate daily data on disk for the different <see cref="ConstituentsUniverse"/>.
|
||||
/// How to use me? search for 'CHANGE ME'
|
||||
/// 1- change the universe name
|
||||
/// 2- change the desired start and end date to generate
|
||||
/// 3- define the universe selection to use
|
||||
/// Data will be generated in:
|
||||
/// 'Globals.DataFolder\SecurityType\Market\universes\Resolution\{UniverseName}\{dates:yyyyMMdd}.csv'
|
||||
/// </summary>
|
||||
/// <remarks>The data produced by this algorithm is the one used by the
|
||||
/// <see cref="ConstituentsUniverseRegressionAlgorithm"/></remarks>
|
||||
/// <remarks>In the cloud, users can implement their own <see cref="ConstituentsUniverseData"/>
|
||||
/// (not using <see cref="SubscriptionTransportMedium.LocalFile"/>) that can fetch the files
|
||||
/// generated from this algorithm</remarks>
|
||||
public class ConstituentsUniverseDataGeneratorAlgorithm : QCAlgorithm
|
||||
{
|
||||
private readonly HashSet<Symbol> _currentSelection = new HashSet<Symbol>();
|
||||
private DateTime _currentDateTime = DateTime.MinValue;
|
||||
private readonly string _rootDataPath = Globals.DataFolder;
|
||||
private string _dataPath;
|
||||
private bool _skippedFirst;
|
||||
|
||||
// Configuration properties: Only these are supported for now (Don't change me)
|
||||
private readonly SecurityType _securityType = SecurityType.Equity;
|
||||
private readonly string _market = Market.USA;
|
||||
private readonly Resolution _resolution = Resolution.Daily;
|
||||
|
||||
// CHANGE ME
|
||||
private readonly string _universeName = "qctest";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
// CHANGE ME
|
||||
SetStartDate(2013, 10, 07); // Set Start Date
|
||||
SetEndDate(2013, 10, 11); // Set End Date
|
||||
SetCash(100000); // Set Strategy Cash
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
_dataPath = Path.Combine(_rootDataPath,
|
||||
_securityType.SecurityTypeToLower(),
|
||||
_market,
|
||||
"universes",
|
||||
_resolution.ResolutionToLower(),
|
||||
_universeName);
|
||||
Directory.CreateDirectory(_dataPath);
|
||||
|
||||
// CHANGE ME
|
||||
int step = 0;
|
||||
AddUniverse(coarse =>
|
||||
{
|
||||
step++;
|
||||
switch (step)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
return new[]
|
||||
{
|
||||
QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA)
|
||||
};
|
||||
case 3:
|
||||
return Enumerable.Empty<Symbol>();
|
||||
case 4:
|
||||
case 5:
|
||||
return new[]
|
||||
{
|
||||
QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA)
|
||||
};
|
||||
default:
|
||||
throw new Exception("Unexpected step count");
|
||||
}
|
||||
});
|
||||
|
||||
Schedule.On(DateRules.EveryDay(), TimeRules.At(23, 0), SaveConstituentsUniverseDataToDisk);
|
||||
}
|
||||
|
||||
private void SaveConstituentsUniverseDataToDisk()
|
||||
{
|
||||
if (_skippedFirst && Time > _currentDateTime)
|
||||
{
|
||||
if (Time.DayOfWeek == DayOfWeek.Sunday
|
||||
|| Time.DayOfWeek == DayOfWeek.Monday)
|
||||
{
|
||||
// we generate files from Tue to Saturday using current selected securities
|
||||
return;
|
||||
}
|
||||
// files are for Mon to Friday
|
||||
_currentDateTime = Time.Date.AddDays(-1);
|
||||
|
||||
var path = Path.Combine(_dataPath, $"{_currentDateTime:yyyyMMdd}.csv");
|
||||
File.Delete(path);
|
||||
if (_currentSelection.Count == 0)
|
||||
{
|
||||
using (StreamWriter constituentsUniverseFile = new StreamWriter(path, append:true))
|
||||
{
|
||||
constituentsUniverseFile.WriteLine(
|
||||
$"{QuantConnect.Symbol.None.Value},{QuantConnect.Symbol.None.ID.ToString()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var symbol in _currentSelection)
|
||||
{
|
||||
using (StreamWriter constituentsUniverseFile = new StreamWriter(path, append: true))
|
||||
{
|
||||
constituentsUniverseFile.WriteLine($"{symbol.Value},{symbol.ID.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_skippedFirst = true;
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var added in changes.AddedSecurities)
|
||||
{
|
||||
Log($"AddedSecurities {added}");
|
||||
if (_currentSelection.Contains(added.Symbol))
|
||||
{
|
||||
throw new Exception("Added symbol already selected");
|
||||
}
|
||||
_currentSelection.Add(added.Symbol);
|
||||
}
|
||||
|
||||
foreach (var removed in changes.RemovedSecurities)
|
||||
{
|
||||
Log($"RemovedSecurities {removed}");
|
||||
if (!_currentSelection.Contains(removed.Symbol))
|
||||
{
|
||||
throw new Exception("Removing symbol already deselected");
|
||||
}
|
||||
_currentSelection.Remove(removed.Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,215 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Test algorithm using a <see cref="ConstituentsUniverse"/> with test data
|
||||
/// </summary>
|
||||
public class ConstituentsUniverseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private readonly Symbol _appl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
private readonly Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
private readonly Symbol _qqq = QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA);
|
||||
private readonly Symbol _fb = QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA);
|
||||
private int _step;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
var customUniverseSymbol = new Symbol(SecurityIdentifier.GenerateConstituentIdentifier(
|
||||
"constituents-universe-qctest",
|
||||
SecurityType.Equity,
|
||||
Market.USA),
|
||||
"constituents-universe-qctest");
|
||||
|
||||
AddUniverse(new ConstituentsUniverse(customUniverseSymbol, UniverseSettings));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
_step++;
|
||||
if (_step == 1)
|
||||
{
|
||||
if (!data.ContainsKey(_qqq)
|
||||
|| !data.ContainsKey(_appl))
|
||||
{
|
||||
throw new Exception($"Unexpected symbols found, step: {_step}");
|
||||
}
|
||||
if (data.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected data count, step: {_step}");
|
||||
}
|
||||
// AAPL will be deselected by the ConstituentsUniverse
|
||||
// but it shouldn't be removed since we hold it
|
||||
SetHoldings(_appl, 0.5);
|
||||
}
|
||||
else if (_step == 2)
|
||||
{
|
||||
if (!data.ContainsKey(_appl))
|
||||
{
|
||||
throw new Exception($"Unexpected symbols found, step: {_step}");
|
||||
}
|
||||
if (data.Count != 1)
|
||||
{
|
||||
throw new Exception($"Unexpected data count, step: {_step}");
|
||||
}
|
||||
// AAPL should now be released
|
||||
// note: takes one extra loop because the order is executed on market open
|
||||
Liquidate();
|
||||
}
|
||||
else if (_step == 3)
|
||||
{
|
||||
if (!data.ContainsKey(_fb)
|
||||
|| !data.ContainsKey(_spy)
|
||||
|| !data.ContainsKey(_appl))
|
||||
{
|
||||
throw new Exception($"Unexpected symbols found, step: {_step}");
|
||||
}
|
||||
if (data.Count != 3)
|
||||
{
|
||||
throw new Exception($"Unexpected data count, step: {_step}");
|
||||
}
|
||||
}
|
||||
else if (_step == 4)
|
||||
{
|
||||
if (!data.ContainsKey(_fb)
|
||||
|| !data.ContainsKey(_spy))
|
||||
{
|
||||
throw new Exception($"Unexpected symbols found, step: {_step}");
|
||||
}
|
||||
if (data.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected data count, step: {_step}");
|
||||
}
|
||||
}
|
||||
else if (_step == 5)
|
||||
{
|
||||
if (!data.ContainsKey(_fb)
|
||||
|| !data.ContainsKey(_spy))
|
||||
{
|
||||
throw new Exception($"Unexpected symbols found, step: {_step}");
|
||||
}
|
||||
if (data.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected data count, step: {_step}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_step != 5)
|
||||
{
|
||||
throw new Exception($"Unexpected step count: {_step}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var added in changes.AddedSecurities)
|
||||
{
|
||||
Log($"AddedSecurities {added}");
|
||||
}
|
||||
|
||||
foreach (var removed in changes.RemovedSecurities)
|
||||
{
|
||||
Log($"RemovedSecurities {removed} {_step}");
|
||||
// we are currently notifying the removal of AAPl twice,
|
||||
// when deselected and when finally removed (since it stayed pending)
|
||||
if (removed.Symbol == _appl && _step != 1 && _step != 2
|
||||
|| removed.Symbol == _qqq && _step != 1)
|
||||
{
|
||||
throw new Exception($"Unexpected removal step count: {_step}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.52%"},
|
||||
{"Compounding Annual Return", "-31.636%"},
|
||||
{"Drawdown", "0.900%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.520%"},
|
||||
{"Sharpe Ratio", "-3.097"},
|
||||
{"Probabilistic Sharpe Ratio", "24.675%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.443"},
|
||||
{"Beta", "0.157"},
|
||||
{"Annual Standard Deviation", "0.074"},
|
||||
{"Annual Variance", "0.005"},
|
||||
{"Information Ratio", "-9.046"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "-1.46"},
|
||||
{"Total Fees", "$7.82"},
|
||||
{"Fitness Score", "0.1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-35.683"},
|
||||
{"Portfolio Turnover", "0.2"},
|
||||
{"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", "-611289773"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -129,43 +129,35 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "85"},
|
||||
{"Average Win", "4.85%"},
|
||||
{"Average Loss", "-4.21%"},
|
||||
{"Compounding Annual Return", "-3.100%"},
|
||||
{"Compounding Annual Return", "-3.105%"},
|
||||
{"Drawdown", "52.900%"},
|
||||
{"Expectancy", "-0.052"},
|
||||
{"Net Profit", "-29.298%"},
|
||||
{"Sharpe Ratio", "-0.076"},
|
||||
{"Probabilistic Sharpe Ratio", "0.004%"},
|
||||
{"Expectancy", "-0.053"},
|
||||
{"Net Profit", "-29.335%"},
|
||||
{"Sharpe Ratio", "-0.084"},
|
||||
{"Loss Rate", "56%"},
|
||||
{"Win Rate", "44%"},
|
||||
{"Profit-Loss Ratio", "1.15"},
|
||||
{"Alpha", "-0.013"},
|
||||
{"Beta", "0.009"},
|
||||
{"Annual Standard Deviation", "0.164"},
|
||||
{"Annual Variance", "0.027"},
|
||||
{"Information Ratio", "-0.391"},
|
||||
{"Tracking Error", "0.239"},
|
||||
{"Treynor Ratio", "-1.416"},
|
||||
{"Total Fees", "$755.29"},
|
||||
{"Fitness Score", "0.024"},
|
||||
{"Kelly Criterion Estimate", "-0.84"},
|
||||
{"Kelly Criterion Probability Value", "0.53"},
|
||||
{"Sortino Ratio", "-0.224"},
|
||||
{"Return Over Maximum Drawdown", "-0.058"},
|
||||
{"Portfolio Turnover", "0.05"},
|
||||
{"Alpha", "0.046"},
|
||||
{"Beta", "-3.04"},
|
||||
{"Annual Standard Deviation", "0.181"},
|
||||
{"Annual Variance", "0.033"},
|
||||
{"Information Ratio", "-0.194"},
|
||||
{"Tracking Error", "0.181"},
|
||||
{"Treynor Ratio", "0.005"},
|
||||
{"Total Fees", "$755.20"},
|
||||
{"Total Insights Generated", "85"},
|
||||
{"Total Insights Closed", "85"},
|
||||
{"Total Insights Analysis Completed", "85"},
|
||||
{"Long Insight Count", "42"},
|
||||
{"Short Insight Count", "43"},
|
||||
{"Long/Short Ratio", "97.67%"},
|
||||
{"Estimated Monthly Alpha Value", "$-617339.2"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-82686580"},
|
||||
{"Mean Population Estimated Insight Value", "$-972783.3"},
|
||||
{"Mean Population Direction", "51.7647%"},
|
||||
{"Estimated Monthly Alpha Value", "$-607698.1"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-81395260"},
|
||||
{"Mean Population Estimated Insight Value", "$-957591.3"},
|
||||
{"Mean Population Direction", "50.5882%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "48.2217%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1370210213"}
|
||||
{"Rolling Averaged Population Direction", "46.5677%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -13,10 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -25,7 +22,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
public class CustomBenchmarkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class CustomBenchmarkAlgorithm : QCAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
@@ -38,7 +35,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Find more symbols here: http://quantconnect.com/data
|
||||
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second);
|
||||
|
||||
SetBenchmark("AAPL");
|
||||
SetBenchmark("SPY");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,69 +49,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetHoldings("SPY", 1);
|
||||
Debug("Purchased Stock");
|
||||
}
|
||||
|
||||
Symbol symbol;
|
||||
if (SymbolCache.TryGetSymbol("AAPL", out symbol))
|
||||
{
|
||||
throw new Exception("Benchmark Symbol is not expected to be added to the Symbol cache");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "264.819%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.668%"},
|
||||
{"Sharpe Ratio", "8.749"},
|
||||
{"Probabilistic Sharpe Ratio", "67.311%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.119"},
|
||||
{"Beta", "0.805"},
|
||||
{"Annual Standard Deviation", "0.219"},
|
||||
{"Annual Variance", "0.048"},
|
||||
{"Information Ratio", "5.494"},
|
||||
{"Tracking Error", "0.168"},
|
||||
{"Treynor Ratio", "2.38"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.245"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "9.606"},
|
||||
{"Return Over Maximum Drawdown", "105.85"},
|
||||
{"Portfolio Turnover", "0.249"},
|
||||
{"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", "2069976135"}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Reproduces Lean GH issue 3572: benchmark _would_ use custom data versus equity
|
||||
/// when both were present
|
||||
/// </summary>
|
||||
public class CustomBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm initialization
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
AddEquity("AAPL", Resolution.Hour);
|
||||
AddData<DummyCustomData>("AAPL");
|
||||
|
||||
// set benchmark will use equity AAPL as benchmark
|
||||
SetBenchmark("AAPL");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings("AAPL", 1);
|
||||
Debug("Purchased Stock");
|
||||
}
|
||||
}
|
||||
private class DummyCustomData : BaseData
|
||||
{
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource("NonExistingFile", SubscriptionTransportMedium.LocalFile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "37.355%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.407%"},
|
||||
{"Sharpe Ratio", "5.521"},
|
||||
{"Probabilistic Sharpe Ratio", "60.177%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.001"},
|
||||
{"Beta", "0.997"},
|
||||
{"Annual Standard Deviation", "0.179"},
|
||||
{"Annual Variance", "0.032"},
|
||||
{"Information Ratio", "-7.662"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0.988"},
|
||||
{"Total Fees", "$7.78"},
|
||||
{"Fitness Score", "0.031"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.145"},
|
||||
{"Return Over Maximum Drawdown", "-8.479"},
|
||||
{"Portfolio Turnover", "0.25"},
|
||||
{"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", "519536519"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <param name="message">Message object</param>
|
||||
public void Handle(BrokerageMessageEvent message)
|
||||
{
|
||||
var toLog = $"{_algo.Time.ToStringInvariant("o")} Event: {message.Message}";
|
||||
var toLog = _algo.Time.ToString("o") + " Event: " + message.Message;
|
||||
_algo.Debug(toLog);
|
||||
_algo.Log(toLog);
|
||||
}
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm ensures that data added via coarse selection (underlying) is present in ActiveSecurities
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="regression test" />d
|
||||
public class CustomDataAddDataCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<Symbol> _customSymbols = new List<Symbol>();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 3, 24);
|
||||
SetEndDate(2014, 4, 7);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
var symbols = new[]
|
||||
{
|
||||
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("GOOGL", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA),
|
||||
};
|
||||
|
||||
_customSymbols.Clear();
|
||||
|
||||
foreach (var symbol in symbols)
|
||||
{
|
||||
_customSymbols.Add(AddData<SECReport8K>(symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
|
||||
return symbols;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested && Transactions.GetOpenOrders().Count == 0)
|
||||
{
|
||||
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
SetHoldings(aapl, 0.5);
|
||||
}
|
||||
|
||||
foreach (var customSymbol in _customSymbols)
|
||||
{
|
||||
if (!ActiveSecurities.ContainsKey(customSymbol.Underlying))
|
||||
{
|
||||
throw new Exception($"Custom data underlying ({customSymbol.Underlying}) Symbol was not found in active securities");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-33.612%"},
|
||||
{"Drawdown", "2.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-1.669%"},
|
||||
{"Sharpe Ratio", "-4.888"},
|
||||
{"Probabilistic Sharpe Ratio", "5.495%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.273"},
|
||||
{"Beta", "0.045"},
|
||||
{"Annual Standard Deviation", "0.057"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-1.537"},
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "-6.121"},
|
||||
{"Total Fees", "$3.50"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-7.289"},
|
||||
{"Return Over Maximum Drawdown", "-16.95"},
|
||||
{"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", "559673838"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm ensures that data added via OnSecuritiesChanged (underlying) is present in ActiveSecurities
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="regression test" />
|
||||
public class CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<Symbol> _customSymbols = new List<Symbol>();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 3, 24);
|
||||
SetEndDate(2014, 4, 7);
|
||||
SetCash(100000);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
AddUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelector));
|
||||
}
|
||||
|
||||
public IEnumerable<Symbol> CoarseSelector(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("FB", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("GOOGL", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA),
|
||||
QuantConnect.Symbol.Create("IBM", SecurityType.Equity, Market.USA),
|
||||
};
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested && Transactions.GetOpenOrders().Count == 0)
|
||||
{
|
||||
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
SetHoldings(aapl, 0.5);
|
||||
}
|
||||
|
||||
foreach (var customSymbol in _customSymbols)
|
||||
{
|
||||
if (!ActiveSecurities.ContainsKey(customSymbol.Underlying))
|
||||
{
|
||||
throw new Exception($"Custom data underlying ({customSymbol.Underlying}) Symbol was not found in active securities");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
bool iterated = false;
|
||||
foreach (var added in changes.AddedSecurities)
|
||||
{
|
||||
if (!iterated)
|
||||
{
|
||||
_customSymbols.Clear();
|
||||
iterated = true;
|
||||
}
|
||||
_customSymbols.Add(AddData<SECReport8K>(added.Symbol, Resolution.Daily).Symbol);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-33.612%"},
|
||||
{"Drawdown", "2.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-1.669%"},
|
||||
{"Sharpe Ratio", "-4.888"},
|
||||
{"Probabilistic Sharpe Ratio", "5.495%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.273"},
|
||||
{"Beta", "0.045"},
|
||||
{"Annual Standard Deviation", "0.057"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-1.537"},
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "-6.121"},
|
||||
{"Total Fees", "$3.50"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-7.289"},
|
||||
{"Return Over Maximum Drawdown", "-16.95"},
|
||||
{"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", "559673838"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm ensures that added data matches expectations
|
||||
/// </summary>
|
||||
public class CustomDataAddDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _googlEquity;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 7);
|
||||
SetEndDate(2013, 10, 11);
|
||||
SetCash(100000);
|
||||
|
||||
var twxEquity = AddEquity("TWX", Resolution.Daily).Symbol;
|
||||
var customTwxSymbol = AddData<SECReport8K>(twxEquity, Resolution.Daily).Symbol;
|
||||
|
||||
_googlEquity = AddEquity("GOOGL", Resolution.Daily).Symbol;
|
||||
var customGooglSymbol = AddData<SECReport10K>("GOOGL", Resolution.Daily).Symbol;
|
||||
|
||||
var usTreasury = AddData<USTreasuryYieldCurveRate>("GOOGL", Resolution.Daily).Symbol;
|
||||
var usTreasuryUnderlyingEquity = QuantConnect.Symbol.Create("MSFT", SecurityType.Equity, Market.USA);
|
||||
var usTreasuryUnderlying = AddData<USTreasuryYieldCurveRate>(usTreasuryUnderlyingEquity, Resolution.Daily).Symbol;
|
||||
|
||||
var optionSymbol = AddOption("TWX", Resolution.Minute).Symbol;
|
||||
var customOptionSymbol = AddData<SECReport10K>(optionSymbol, Resolution.Daily).Symbol;
|
||||
|
||||
if (customTwxSymbol.Underlying != twxEquity)
|
||||
{
|
||||
throw new Exception($"Underlying symbol for {customTwxSymbol} is not equal to TWX equity. Expected {twxEquity} got {customTwxSymbol.Underlying}");
|
||||
}
|
||||
if (customGooglSymbol.Underlying != _googlEquity)
|
||||
{
|
||||
throw new Exception($"Underlying symbol for {customGooglSymbol} is not equal to GOOGL equity. Expected {_googlEquity} got {customGooglSymbol.Underlying}");
|
||||
}
|
||||
if (usTreasury.HasUnderlying)
|
||||
{
|
||||
throw new Exception($"US Treasury yield curve (no underlying) has underlying when it shouldn't. Found {usTreasury.Underlying}");
|
||||
}
|
||||
if (!usTreasuryUnderlying.HasUnderlying)
|
||||
{
|
||||
throw new Exception("US Treasury yield curve (with underlying) has no underlying Symbol even though we added with Symbol");
|
||||
}
|
||||
if (usTreasuryUnderlying.Underlying != usTreasuryUnderlyingEquity)
|
||||
{
|
||||
throw new Exception($"US Treasury yield curve underlying does not equal equity Symbol added. Expected {usTreasuryUnderlyingEquity} got {usTreasuryUnderlying.Underlying}");
|
||||
}
|
||||
if (customOptionSymbol.Underlying != optionSymbol)
|
||||
{
|
||||
throw new Exception("Option symbol not equal to custom underlying symbol. Expected {optionSymbol} got {customOptionSymbol.Underlying}");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var customDataNoCache = AddData<SECReport10Q>("AAPL", Resolution.Daily);
|
||||
throw new Exception("AAPL was found in the SymbolCache, though it should be missing");
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// This is exactly what we wanted. AAPL shouldn't have been found in the SymbolCache, and because
|
||||
// SECReport10Q is a mappable type, we threw
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested && !Transactions.GetOpenOrders().Any())
|
||||
{
|
||||
SetHoldings(_googlEquity, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "31.756%"},
|
||||
{"Drawdown", "0.700%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.378%"},
|
||||
{"Sharpe Ratio", "2.708"},
|
||||
{"Probabilistic Sharpe Ratio", "56.960%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.079"},
|
||||
{"Beta", "0.099"},
|
||||
{"Annual Standard Deviation", "0.079"},
|
||||
{"Annual Variance", "0.006"},
|
||||
{"Information Ratio", "-6.058"},
|
||||
{"Tracking Error", "0.19"},
|
||||
{"Treynor Ratio", "2.159"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Fitness Score", "0.1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "47.335"},
|
||||
{"Portfolio Turnover", "0.1"},
|
||||
{"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", "1531253381"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
Console.WriteLine("Buying BTC 'Shares': BTC: " + data.Close);
|
||||
}
|
||||
Console.WriteLine("Time: " + Time.ToStringInvariant("T") + " " + Time.ToStringInvariant("T") + data.Close.ToStringInvariant());
|
||||
Console.WriteLine("Time: " + Time.ToLongDateString() + " " + Time.ToLongTimeString() + data.Close.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -60,8 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
//Bitcoin used as a tradable asset, like stocks, futures etc.
|
||||
if (data.Close != 0)
|
||||
{
|
||||
//Access custom data symbols using <ticker>.<custom-type>
|
||||
Order("BTC.Bitcoin", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
|
||||
Order("BTC", Portfolio.MarginRemaining / Math.Abs(data.Close + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,43 +83,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "155.262%"},
|
||||
{"Compounding Annual Return", "155.365%"},
|
||||
{"Drawdown", "84.800%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "5123.170%"},
|
||||
{"Sharpe Ratio", "2.066"},
|
||||
{"Probabilistic Sharpe Ratio", "68.832%"},
|
||||
{"Sharpe Ratio", "1.2"},
|
||||
{"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"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "2.238"},
|
||||
{"Return Over Maximum Drawdown", "1.832"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-541549381"}
|
||||
{"Alpha", "-0.008"},
|
||||
{"Beta", "73.725"},
|
||||
{"Annual Standard Deviation", "0.84"},
|
||||
{"Annual Variance", "0.706"},
|
||||
{"Information Ratio", "1.183"},
|
||||
{"Tracking Error", "0.84"},
|
||||
{"Treynor Ratio", "0.014"},
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null),
|
||||
Symbol = Symbol.Create(csv[1], SecurityType.Equity, Market.USA),
|
||||
TopGainersRank = Parse.Int(csv[2])
|
||||
TopGainersRank = int.Parse(csv[2])
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,217 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm demonstrating use of map files with custom data
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="regression test" />
|
||||
/// <meta name="tag" content="rename event" />
|
||||
/// <meta name="tag" content="map" />
|
||||
/// <meta name="tag" content="mapping" />
|
||||
/// <meta name="tag" content="map files" />
|
||||
public class CustomDataUsingMapFileRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _symbol;
|
||||
private bool _initialMapping;
|
||||
private bool _executionMapping;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 06, 27);
|
||||
SetEndDate(2013, 07, 02);
|
||||
|
||||
var foxa = QuantConnect.Symbol.Create("FOXA", SecurityType.Equity, Market.USA);
|
||||
_symbol = AddData<CustomDataUsingMapping>(foxa).Symbol;
|
||||
|
||||
foreach (var config in SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(_symbol))
|
||||
{
|
||||
if (config.Resolution != Resolution.Minute)
|
||||
{
|
||||
throw new Exception("Expected resolution to be set to Minute");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks to see if the stock has been renamed, and places an order once the symbol has changed
|
||||
/// </summary>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (slice.SymbolChangedEvents.ContainsKey(_symbol))
|
||||
{
|
||||
var mappingEvent = slice.SymbolChangedEvents.Single(x => x.Key.SecurityType == SecurityType.Base).Value;
|
||||
Log($"{Time} - Ticker changed from: {mappingEvent.OldSymbol} to {mappingEvent.NewSymbol}");
|
||||
if (Time.Date == new DateTime(2013, 06, 27))
|
||||
{
|
||||
// we should Not receive the initial mapping event
|
||||
if (mappingEvent.NewSymbol != "NWSA"
|
||||
|| mappingEvent.OldSymbol != "FOXA")
|
||||
{
|
||||
throw new Exception($"Unexpected mapping event {mappingEvent}");
|
||||
}
|
||||
_initialMapping = true;
|
||||
}
|
||||
else if (Time.Date == new DateTime(2013, 06, 29))
|
||||
{
|
||||
if (mappingEvent.NewSymbol != "FOXA"
|
||||
|| mappingEvent.OldSymbol != "NWSA")
|
||||
{
|
||||
throw new Exception($"Unexpected mapping event {mappingEvent}");
|
||||
}
|
||||
|
||||
_executionMapping = true;
|
||||
SetHoldings(_symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Final step of the algorithm
|
||||
/// </summary>
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_initialMapping)
|
||||
{
|
||||
throw new Exception("The ticker generated the initial rename event");
|
||||
}
|
||||
if (!_executionMapping)
|
||||
{
|
||||
throw new Exception("The ticker did not rename throughout the course of its life even though it should have");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-99.920%"},
|
||||
{"Drawdown", "11.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-10.486%"},
|
||||
{"Sharpe Ratio", "-1.534"},
|
||||
{"Probabilistic Sharpe Ratio", "0.001%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.898"},
|
||||
{"Beta", "-7.027"},
|
||||
{"Annual Standard Deviation", "0.651"},
|
||||
{"Annual Variance", "0.424"},
|
||||
{"Information Ratio", "-1.396"},
|
||||
{"Tracking Error", "0.726"},
|
||||
{"Treynor Ratio", "0.142"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0.127"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-9.383"},
|
||||
{"Portfolio Turnover", "0.249"},
|
||||
{"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", "-1014157203"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Test example custom data showing how to enable the use of mapping.
|
||||
/// Implemented as a wrapper of existing NWSA->FOXA equity
|
||||
/// </summary>
|
||||
private class CustomDataUsingMapping : TradeBar
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates if there is support for mapping
|
||||
/// </summary>
|
||||
/// <returns>True indicates mapping should be done</returns>
|
||||
public override bool RequiresMapping()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return base.GetSource(new SubscriptionDataConfig(config,
|
||||
typeof(CustomDataUsingMapping),
|
||||
// create a new symbol as equity so we find the existing data files
|
||||
Symbol.Create(config.MappedSymbol, SecurityType.Equity, config.Market)),
|
||||
date,
|
||||
isLiveMode);
|
||||
}
|
||||
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return ParseEquity(config, line, date);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default resolution for this data and security type
|
||||
/// </summary>
|
||||
/// <remarks>This is a method and not a property so that python
|
||||
/// custom data types can override it</remarks>
|
||||
public override Resolution DefaultResolution()
|
||||
{
|
||||
return Resolution.Minute;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported resolution for this data and security type
|
||||
/// </summary>
|
||||
/// <remarks>This is a method and not a property so that python
|
||||
/// custom data types can override it</remarks>
|
||||
public override List<Resolution> SupportedResolutions()
|
||||
{
|
||||
return new List<Resolution> { Resolution.Minute };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -171,45 +171,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "62"},
|
||||
{"Average Win", "0.10%"},
|
||||
{"Average Win", "0.11%"},
|
||||
{"Average Loss", "-0.06%"},
|
||||
{"Compounding Annual Return", "-7.727%"},
|
||||
{"Compounding Annual Return", "-7.582%"},
|
||||
{"Drawdown", "2.400%"},
|
||||
{"Expectancy", "-0.197"},
|
||||
{"Net Profit", "-0.673%"},
|
||||
{"Sharpe Ratio", "-1.565"},
|
||||
{"Probabilistic Sharpe Ratio", "22.763%"},
|
||||
{"Expectancy", "-0.193"},
|
||||
{"Net Profit", "-0.660%"},
|
||||
{"Sharpe Ratio", "-1.563"},
|
||||
{"Loss Rate", "70%"},
|
||||
{"Win Rate", "30%"},
|
||||
{"Profit-Loss Ratio", "1.70"},
|
||||
{"Alpha", "-0.14"},
|
||||
{"Beta", "0.124"},
|
||||
{"Annual Standard Deviation", "0.047"},
|
||||
{"Profit-Loss Ratio", "1.71"},
|
||||
{"Alpha", "-0.174"},
|
||||
{"Beta", "5.695"},
|
||||
{"Annual Standard Deviation", "0.046"},
|
||||
{"Annual Variance", "0.002"},
|
||||
{"Information Ratio", "-5.163"},
|
||||
{"Tracking Error", "0.118"},
|
||||
{"Treynor Ratio", "-0.591"},
|
||||
{"Total Fees", "$62.24"},
|
||||
{"Fitness Score", "0.147"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.792"},
|
||||
{"Return Over Maximum Drawdown", "-3.569"},
|
||||
{"Portfolio Turnover", "2.562"},
|
||||
{"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", "852026186"}
|
||||
{"Information Ratio", "-1.959"},
|
||||
{"Tracking Error", "0.046"},
|
||||
{"Treynor Ratio", "-0.013"},
|
||||
{"Total Fees", "$62.24"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Orders.Fills;
|
||||
using QuantConnect.Securities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template algorithm that implements a fill model with partial fills
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="transaction fees and slippage" />
|
||||
/// <meta name="tag" content="custom fill models" />
|
||||
public class CustomPartialFillModelAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _spy;
|
||||
private SecurityHolding _holdings;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2019, 1, 1);
|
||||
SetEndDate(2019, 3, 1);
|
||||
|
||||
var equity = AddEquity("SPY", Resolution.Hour);
|
||||
_spy = equity.Symbol;
|
||||
_holdings = equity.Holdings;
|
||||
|
||||
// Set the fill model
|
||||
equity.SetFillModel(new CustomPartialFillModel(this));
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var openOrders = Transactions.GetOpenOrders(_spy);
|
||||
if (openOrders.Count != 0) return;
|
||||
|
||||
if (Time.Day > 10 && _holdings.Quantity <= 0)
|
||||
{
|
||||
MarketOrder(_spy, 100, true);
|
||||
}
|
||||
else if (Time.Day > 20 && _holdings.Quantity >= 0)
|
||||
{
|
||||
MarketOrder(_spy, -100, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implements a custom fill model that inherit from FillModel. Override the MarketFill method to simulate partially fill orders
|
||||
/// </summary>
|
||||
internal class CustomPartialFillModel : FillModel
|
||||
{
|
||||
private readonly QCAlgorithm _algorithm;
|
||||
private readonly Dictionary<int, decimal> _absoluteRemainingByOrderId;
|
||||
|
||||
public CustomPartialFillModel(QCAlgorithm algorithm)
|
||||
: base()
|
||||
{
|
||||
_algorithm = algorithm;
|
||||
_absoluteRemainingByOrderId = new Dictionary<int, decimal>();
|
||||
}
|
||||
|
||||
public override OrderEvent MarketFill(Security asset, MarketOrder order)
|
||||
{
|
||||
decimal absoluteRemaining;
|
||||
if (!_absoluteRemainingByOrderId.TryGetValue(order.Id, out absoluteRemaining))
|
||||
{
|
||||
absoluteRemaining = order.AbsoluteQuantity;
|
||||
}
|
||||
|
||||
// Create the object
|
||||
var fill = base.MarketFill(asset, order);
|
||||
|
||||
// Set this fill amount
|
||||
fill.FillQuantity = Math.Sign(order.Quantity) * 10;
|
||||
|
||||
if (absoluteRemaining == fill.FillQuantity)
|
||||
{
|
||||
fill.Status = OrderStatus.Filled;
|
||||
_absoluteRemainingByOrderId.Remove(order.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
fill.Status = OrderStatus.PartiallyFilled;
|
||||
_absoluteRemainingByOrderId[order.Id] = absoluteRemaining - fill.FillQuantity;
|
||||
var price = fill.FillPrice;
|
||||
_algorithm.Debug($"{_algorithm.Time} - Partial Fill - Remaining {absoluteRemaining} Price - {price}");
|
||||
}
|
||||
return fill;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Test algorithm that verifies that securities added through
|
||||
/// <see cref="QCAlgorithm.AddEquity"/> API and universe selection
|
||||
/// both start sending data at the same time
|
||||
/// </summary>
|
||||
public class CustomUniverseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
AddUniverse(SecurityType.Equity,
|
||||
"SecondUniverse",
|
||||
Resolution.Daily,
|
||||
Market.USA,
|
||||
UniverseSettings,
|
||||
time => new[] { "SPY" });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (data.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected data count: {data.Count}");
|
||||
}
|
||||
if (ActiveSecurities.Count != 2)
|
||||
{
|
||||
throw new Exception($"Unexpected ActiveSecurities count: {ActiveSecurities.Count}");
|
||||
}
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(Securities.Keys.First(symbol => symbol.Value == "SPY"), 1);
|
||||
Debug("Purchased Stock");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "241.885%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.698%"},
|
||||
{"Sharpe Ratio", "7.17"},
|
||||
{"Probabilistic Sharpe Ratio", "68.718%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.171"},
|
||||
{"Beta", "0.147"},
|
||||
{"Annual Standard Deviation", "0.191"},
|
||||
{"Annual Variance", "0.037"},
|
||||
{"Information Ratio", "0.035"},
|
||||
{"Tracking Error", "0.251"},
|
||||
{"Treynor Ratio", "9.323"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.201"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "211.158"},
|
||||
{"Portfolio Turnover", "0.201"},
|
||||
{"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", "1268340653"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm with a custom universe and benchmark, both using the same security.
|
||||
/// </summary>
|
||||
public class CustomUniverseWithBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private const int ExpectedLeverage = 2;
|
||||
private Symbol _spy;
|
||||
private decimal _previousBenchmarkValue;
|
||||
private DateTime _previousTime;
|
||||
private decimal _previousSecurityValue;
|
||||
private bool _universeSelected;
|
||||
private bool _onDataWasCalled;
|
||||
private int _benchmarkPriceDidNotChange;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 4);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
// Hour resolution
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
|
||||
// Minute resolution
|
||||
AddUniverse("my-universe", x =>
|
||||
{
|
||||
if(x.Day % 2 == 0)
|
||||
{
|
||||
_universeSelected = true;
|
||||
return new List<string> {"SPY"};
|
||||
}
|
||||
_universeSelected = false;
|
||||
return Enumerable.Empty<string>();
|
||||
}
|
||||
);
|
||||
|
||||
// internal daily resolution
|
||||
SetBenchmark("SPY");
|
||||
|
||||
Symbol symbol;
|
||||
if (!SymbolCache.TryGetSymbol("SPY", out symbol)
|
||||
|| !ReferenceEquals(_spy, symbol))
|
||||
{
|
||||
throw new Exception("We expected 'SPY' to be added to the Symbol cache," +
|
||||
" since the algorithm is also using it");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var security = Securities[_spy];
|
||||
_onDataWasCalled = true;
|
||||
|
||||
var bar = data.Bars.Values.Single();
|
||||
if (_universeSelected)
|
||||
{
|
||||
if (bar.IsFillForward
|
||||
|| bar.Period != TimeSpan.FromMinutes(1))
|
||||
{
|
||||
// bar should always be the Minute resolution one here
|
||||
throw new Exception("Unexpected Bar error");
|
||||
}
|
||||
if (_previousTime.Date == data.Time.Date
|
||||
&& (data.Time - _previousTime) != TimeSpan.FromMinutes(1))
|
||||
{
|
||||
throw new Exception("For the same date expected data updates every 1 minute");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data.Time.Minute == 0
|
||||
&& _previousSecurityValue == security.Price)
|
||||
{
|
||||
throw new Exception($"Security Price error. Price should change every new hour");
|
||||
}
|
||||
if (data.Time.Minute != 0
|
||||
&& _previousSecurityValue != security.Price)
|
||||
{
|
||||
throw new Exception($"Security Price error. Price should not change every minute");
|
||||
}
|
||||
}
|
||||
_previousSecurityValue = security.Price;
|
||||
|
||||
// assert benchmark updates only on date change
|
||||
var currentValue = Benchmark.Evaluate(data.Time);
|
||||
if (_previousTime.Hour == data.Time.Hour)
|
||||
{
|
||||
if (currentValue != _previousBenchmarkValue)
|
||||
{
|
||||
throw new Exception($"Benchmark value error - expected: {_previousBenchmarkValue} {_previousTime}, actual: {currentValue} {data.Time}. " +
|
||||
"Benchmark value should only change when there is a change in hours");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data.Time.Minute == 0)
|
||||
{
|
||||
if (currentValue == _previousBenchmarkValue)
|
||||
{
|
||||
_benchmarkPriceDidNotChange++;
|
||||
// there are two consecutive equal data points so we give it some room
|
||||
if (_benchmarkPriceDidNotChange > 1)
|
||||
{
|
||||
throw new Exception($"Benchmark value error - expected a new value, current {currentValue} {data.Time}" +
|
||||
"Benchmark value should change when there is a change in hours");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_benchmarkPriceDidNotChange = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
_previousBenchmarkValue = currentValue;
|
||||
_previousTime = data.Time;
|
||||
|
||||
// assert algorithm security is the correct one - not the internal one
|
||||
if (security.Leverage != ExpectedLeverage)
|
||||
{
|
||||
throw new Exception($"Leverage error - expected: {ExpectedLeverage}, actual: {security.Leverage}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_onDataWasCalled)
|
||||
{
|
||||
throw new Exception("OnData was not called");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.53"},
|
||||
{"Tracking Error", "0.211"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -96,20 +96,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Consolidate("EURUSD", Resolution.Daily, DailyEurUsdBarHandler);
|
||||
|
||||
// API convenience method for easily receiving weekly-consolidated data
|
||||
Consolidate("SPY", Calendar.Weekly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", Calendar.Weekly, CalendarQuoteBarHandler);
|
||||
Consolidate("SPY", CalendarType.Weekly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", CalendarType.Weekly, CalendarQuoteBarHandler);
|
||||
|
||||
// API convenience method for easily receiving monthly-consolidated data
|
||||
Consolidate("SPY", Calendar.Monthly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", Calendar.Monthly, CalendarQuoteBarHandler);
|
||||
|
||||
// API convenience method for easily receiving quarterly-consolidated data
|
||||
Consolidate("SPY", Calendar.Quarterly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", Calendar.Quarterly, CalendarQuoteBarHandler);
|
||||
|
||||
// API convenience method for easily receiving yearly-consolidated data
|
||||
Consolidate("SPY", Calendar.Yearly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", Calendar.Yearly, CalendarQuoteBarHandler);
|
||||
Consolidate("SPY", CalendarType.Monthly, CalendarTradeBarHandler);
|
||||
Consolidate("EURUSD", CalendarType.Monthly, CalendarQuoteBarHandler);
|
||||
|
||||
// requires quote data subscription
|
||||
//Consolidate<QuoteBar>("EURUSD", TimeSpan.FromMinutes(45), FortyFiveMinuteBarHandler);
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.Custom;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Data.Custom.Fred;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Data.Custom.Tiingo;
|
||||
using QuantConnect.Data.Custom.USEnergy;
|
||||
using QuantConnect.Data.Custom.USTreasury;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests the performance related GH issue 3772
|
||||
/// </summary>
|
||||
public class DefaultResolutionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 11);
|
||||
SetEndDate(2013, 10, 12);
|
||||
var spy = AddEquity("SPY").Symbol;
|
||||
|
||||
var types = new[]
|
||||
{
|
||||
typeof(SECReport8K),
|
||||
typeof(SECReport10K),
|
||||
typeof(SECReport10Q),
|
||||
typeof(USTreasuryYieldCurveRate),
|
||||
typeof(USEnergy),
|
||||
typeof(CBOE),
|
||||
typeof(TiingoPrice),
|
||||
typeof(Fred)
|
||||
};
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var custom = AddData(type, spy);
|
||||
|
||||
if (SubscriptionManager.SubscriptionDataConfigService
|
||||
.GetSubscriptionDataConfigs(custom.Symbol)
|
||||
.Any(config => config.Resolution != Resolution.Daily))
|
||||
{
|
||||
throw new Exception("Was expecting resolution to be set to Daily");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
AddData(type, spy, Resolution.Tick);
|
||||
throw new Exception("Was expecting an ArgumentException to be thrown");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// expected, these custom types don't support tick resolution
|
||||
}
|
||||
}
|
||||
|
||||
var security = AddData<USEnergyAPI>(spy);
|
||||
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(security.Symbol)
|
||||
.Any(config => config.Resolution != Resolution.Hour))
|
||||
{
|
||||
throw new Exception("Was expecting resolution to be set to Hour");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
AddOption("AAPL", Resolution.Daily);
|
||||
throw new Exception("Was expecting an ArgumentException to be thrown");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// expected, options only support minute resolution
|
||||
}
|
||||
|
||||
var option = AddOption("AAPL");
|
||||
if (SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(option.Symbol)
|
||||
.Any(config => config.Resolution != Resolution.Minute))
|
||||
{
|
||||
throw new Exception("Was expecting resolution to be set to Minute");
|
||||
}
|
||||
|
||||
Quit();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Return Over Maximum Drawdown", "0"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm which reproduces GH issue 4446
|
||||
/// </summary>
|
||||
public class DelistedFutureLiquidateRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contractSymbol;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 12, 30);
|
||||
|
||||
var futureSP500 = AddFuture(Futures.Indices.SP500EMini);
|
||||
futureSP500.SetFilter(0, 182);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
|
||||
/// </summary>
|
||||
/// <param name="slice">The current slice of data keyed by symbol string</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (_contractSymbol == null)
|
||||
{
|
||||
foreach (var chain in slice.FutureChains)
|
||||
{
|
||||
var contract = chain.Value.OrderBy(x => x.Expiry).FirstOrDefault();
|
||||
// if found, trade it
|
||||
if (contract != null)
|
||||
{
|
||||
_contractSymbol = contract.Symbol;
|
||||
MarketOrder(_contractSymbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
Log($"{_contractSymbol}: {Securities[_contractSymbol].Invested}");
|
||||
if (Securities[_contractSymbol].Invested)
|
||||
{
|
||||
throw new Exception($"Position should be closed when {_contractSymbol} got delisted {_contractSymbol.ID.Date}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Log($"{orderEvent}. Delisting on: {_contractSymbol.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; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "1.63%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "7.292%"},
|
||||
{"Drawdown", "1.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.634%"},
|
||||
{"Sharpe Ratio", "2.476"},
|
||||
{"Probabilistic Sharpe Ratio", "92.194%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.006"},
|
||||
{"Beta", "0.158"},
|
||||
{"Annual Standard Deviation", "0.032"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "-4.89"},
|
||||
{"Tracking Error", "0.08"},
|
||||
{"Treynor Ratio", "0.509"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0.019"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.362"},
|
||||
{"Return Over Maximum Drawdown", "9.699"},
|
||||
{"Portfolio Turnover", "0.022"},
|
||||
{"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", "-1252326142"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
var symbol = kvp.Key;
|
||||
var tradeBar = kvp.Value;
|
||||
Debug($"OnData(Slice): {Time}: {symbol}: {tradeBar.Close.ToStringInvariant("0.00")}");
|
||||
Debug($"OnData(Slice): {Time}: {symbol}: {tradeBar.Close.ToString("0.00")}");
|
||||
}
|
||||
|
||||
// the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting
|
||||
@@ -80,8 +80,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
throw new Exception("Securities must be marked as tradable until they're delisted or removed from the universe");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kvp in data.Delistings)
|
||||
public void OnData(Delistings data)
|
||||
{
|
||||
foreach (var kvp in data)
|
||||
{
|
||||
var symbol = kvp.Key;
|
||||
var delisting = kvp.Value;
|
||||
@@ -140,46 +143,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-3.23%"},
|
||||
{"Compounding Annual Return", "-79.990%"},
|
||||
{"Drawdown", "4.300%"},
|
||||
{"Average Loss", "-5.58%"},
|
||||
{"Compounding Annual Return", "-87.694%"},
|
||||
{"Drawdown", "5.600%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-4.312%"},
|
||||
{"Sharpe Ratio", "-5.958"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Net Profit", "-5.578%"},
|
||||
{"Sharpe Ratio", "-10.227"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.685"},
|
||||
{"Beta", "-0.445"},
|
||||
{"Annual Standard Deviation", "0.119"},
|
||||
{"Annual Variance", "0.014"},
|
||||
{"Information Ratio", "-4.887"},
|
||||
{"Tracking Error", "0.155"},
|
||||
{"Treynor Ratio", "1.589"},
|
||||
{"Total Fees", "$55.05"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-15.687"},
|
||||
{"Return Over Maximum Drawdown", "-18.549"},
|
||||
{"Portfolio Turnover", "0.334"},
|
||||
{"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", "-2022527947"}
|
||||
{"Alpha", "-1.953"},
|
||||
{"Beta", "23.587"},
|
||||
{"Annual Standard Deviation", "0.156"},
|
||||
{"Annual Variance", "0.024"},
|
||||
{"Information Ratio", "-10.33"},
|
||||
{"Tracking Error", "0.156"},
|
||||
{"Treynor Ratio", "-0.067"},
|
||||
{"Total Fees", "$36.70"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,45 +167,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "7"},
|
||||
{"Average Win", "19.16%"},
|
||||
{"Average Win", "19.15%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "16.727%"},
|
||||
{"Drawdown", "12.200%"},
|
||||
{"Compounding Annual Return", "16.720%"},
|
||||
{"Drawdown", "12.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "153.058%"},
|
||||
{"Sharpe Ratio", "1.239"},
|
||||
{"Probabilistic Sharpe Ratio", "66.414%"},
|
||||
{"Net Profit", "152.966%"},
|
||||
{"Sharpe Ratio", "1.275"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.146"},
|
||||
{"Beta", "-0.018"},
|
||||
{"Annual Standard Deviation", "0.116"},
|
||||
{"Annual Variance", "0.013"},
|
||||
{"Information Ratio", "-0.053"},
|
||||
{"Tracking Error", "0.204"},
|
||||
{"Treynor Ratio", "-8.165"},
|
||||
{"Total Fees", "$46.75"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.607"},
|
||||
{"Return Over Maximum Drawdown", "1.366"},
|
||||
{"Portfolio Turnover", "0.003"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-807056289"}
|
||||
{"Alpha", "0.079"},
|
||||
{"Beta", "4.194"},
|
||||
{"Annual Standard Deviation", "0.128"},
|
||||
{"Annual Variance", "0.016"},
|
||||
{"Information Ratio", "1.119"},
|
||||
{"Tracking Error", "0.128"},
|
||||
{"Treynor Ratio", "0.039"},
|
||||
{"Total Fees", "$46.73"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +69,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public void OnData(Dividends data) // update this to Dividends dictionary
|
||||
{
|
||||
var dividend = data["MSFT"];
|
||||
Debug($"{dividend.Time.ToStringInvariant("o")} >> DIVIDEND >> {dividend.Symbol} - " +
|
||||
$"{dividend.Distribution.ToStringInvariant("C")} - {Portfolio.Cash} - " +
|
||||
$"{Portfolio["MSFT"].Price.ToStringInvariant("C")}"
|
||||
);
|
||||
Debug(string.Format("{0} >> DIVIDEND >> {1} - {2} - {3} - {4}", dividend.Time.ToString("o"), dividend.Symbol, dividend.Distribution.ToString("C"), Portfolio.Cash, Portfolio["MSFT"].Price.ToString("C")));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,18 +80,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
Debug("MSFT: " + Securities["MSFT"].Price);
|
||||
var split = data["MSFT"];
|
||||
Debug($"{split.Time.ToIso8601Invariant()} >> SPLIT >> {split.Symbol} - " +
|
||||
$"{split.SplitFactor.ToStringInvariant()} - " +
|
||||
$"{Portfolio.Cash.ToStringInvariant()} - " +
|
||||
$"{Portfolio["MSFT"].Quantity.ToStringInvariant()}"
|
||||
);
|
||||
Debug(string.Format("{0} >> SPLIT >> {1} - {2} - {3} - {4}", split.Time.ToString("o"), split.Symbol, split.SplitFactor, Portfolio.Cash, Portfolio["MSFT"].Quantity));
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
// orders get adjusted based on split events to maintain order value
|
||||
var order = Transactions.GetOrderById(orderEvent.OrderId);
|
||||
Debug($"{Time.ToStringInvariant()} >> ORDER >> {order}");
|
||||
Debug(string.Format("{0} >> ORDER >> " + order, Time));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,8 +45,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
SetStartDate(2017, 07, 04);
|
||||
SetEndDate(2018, 07, 04);
|
||||
SetStartDate(2013, 01, 01);
|
||||
SetEndDate(2013, 12, 31);
|
||||
|
||||
AddUniverse<StockDataSource>("my-stock-data-source", stockDataSource =>
|
||||
{
|
||||
@@ -102,8 +102,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
class StockDataSource : BaseData
|
||||
{
|
||||
private const string LiveUrl = @"https://www.dropbox.com/s/2l73mu97gcehmh7/daily-stock-picker-live.csv?dl=1";
|
||||
private const string BacktestUrl = @"https://www.dropbox.com/s/ae1couew5ir3z9y/daily-stock-picker-backtest.csv?dl=1";
|
||||
private const string LiveUrl = @"https://www.dropbox.com/s/2az14r5xbx4w5j6/daily-stock-picker-live.csv?dl=1";
|
||||
private const string BacktestUrl = @"https://www.dropbox.com/s/rmiiktz0ntpff3a/daily-stock-picker-backtest.csv?dl=1";
|
||||
|
||||
/// <summary>
|
||||
/// The symbols to be selected
|
||||
@@ -184,46 +184,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6441"},
|
||||
{"Average Win", "0.07%"},
|
||||
{"Average Loss", "-0.07%"},
|
||||
{"Compounding Annual Return", "13.284%"},
|
||||
{"Drawdown", "10.700%"},
|
||||
{"Expectancy", "0.061"},
|
||||
{"Net Profit", "13.284%"},
|
||||
{"Sharpe Ratio", "0.96"},
|
||||
{"Probabilistic Sharpe Ratio", "46.111%"},
|
||||
{"Loss Rate", "46%"},
|
||||
{"Win Rate", "54%"},
|
||||
{"Profit-Loss Ratio", "0.97"},
|
||||
{"Alpha", "0.124"},
|
||||
{"Beta", "-0.066"},
|
||||
{"Annual Standard Deviation", "0.121"},
|
||||
{"Annual Variance", "0.015"},
|
||||
{"Information Ratio", "0.004"},
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-1.754"},
|
||||
{"Total Fees", "$8669.33"},
|
||||
{"Fitness Score", "0.675"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.124"},
|
||||
{"Return Over Maximum Drawdown", "1.242"},
|
||||
{"Portfolio Turnover", "1.64"},
|
||||
{"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", "-1120327913"}
|
||||
{"Total Trades", "90"},
|
||||
{"Average Win", "0.78%"},
|
||||
{"Average Loss", "-0.39%"},
|
||||
{"Compounding Annual Return", "18.547%"},
|
||||
{"Drawdown", "4.700%"},
|
||||
{"Expectancy", "1.068"},
|
||||
{"Net Profit", "18.547%"},
|
||||
{"Sharpe Ratio", "1.993"},
|
||||
{"Loss Rate", "30%"},
|
||||
{"Win Rate", "70%"},
|
||||
{"Profit-Loss Ratio", "1.96"},
|
||||
{"Alpha", "0.119"},
|
||||
{"Beta", "2.617"},
|
||||
{"Annual Standard Deviation", "0.086"},
|
||||
{"Annual Variance", "0.007"},
|
||||
{"Information Ratio", "1.764"},
|
||||
{"Tracking Error", "0.086"},
|
||||
{"Treynor Ratio", "0.065"},
|
||||
{"Total Fees", "$251.12"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
// set our start and end for backtest mode
|
||||
SetStartDate(2017, 07, 04);
|
||||
SetEndDate(2018, 07, 04);
|
||||
SetStartDate(2013, 01, 01);
|
||||
SetEndDate(2013, 12, 31);
|
||||
|
||||
// define a new custom universe that will trigger each day at midnight
|
||||
AddUniverse("my-dropbox-universe", Resolution.Daily, dateTime =>
|
||||
@@ -60,7 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
if (LiveMode)
|
||||
{
|
||||
// fetch the file from dropbox
|
||||
var file = Download(@"https://www.dropbox.com/s/2l73mu97gcehmh7/daily-stock-picker-live.csv?dl=1");
|
||||
var file = Download(@"https://www.dropbox.com/s/2az14r5xbx4w5j6/daily-stock-picker-live.csv?dl=1");
|
||||
// if we have a file for today, break apart by commas and return symbols
|
||||
if (file.Length > 0) return file.ToCsv();
|
||||
// no symbol today, leave universe unchanged
|
||||
@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
new KeyValuePair<string, string>("Authorization", $"Basic ({Convert.ToBase64String(byteKey)})")
|
||||
};
|
||||
|
||||
var file = Download(@"https://www.dropbox.com/s/ae1couew5ir3z9y/daily-stock-picker-backtest.csv?dl=1", headers);
|
||||
var file = Download(@"https://www.dropbox.com/s/rmiiktz0ntpff3a/daily-stock-picker-backtest.csv?dl=1", headers);
|
||||
|
||||
// split the file into lines and add to our cache
|
||||
foreach (var line in file.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries))
|
||||
@@ -157,46 +157,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "5059"},
|
||||
{"Average Win", "0.08%"},
|
||||
{"Average Loss", "-0.08%"},
|
||||
{"Compounding Annual Return", "14.901%"},
|
||||
{"Drawdown", "10.600%"},
|
||||
{"Expectancy", "0.075"},
|
||||
{"Net Profit", "14.901%"},
|
||||
{"Sharpe Ratio", "1.068"},
|
||||
{"Probabilistic Sharpe Ratio", "50.201%"},
|
||||
{"Loss Rate", "45%"},
|
||||
{"Win Rate", "55%"},
|
||||
{"Profit-Loss Ratio", "0.97"},
|
||||
{"Alpha", "0.137"},
|
||||
{"Beta", "-0.066"},
|
||||
{"Annual Standard Deviation", "0.121"},
|
||||
{"Annual Variance", "0.015"},
|
||||
{"Information Ratio", "0.08"},
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "-1.963"},
|
||||
{"Total Fees", "$6806.57"},
|
||||
{"Fitness Score", "0.694"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.261"},
|
||||
{"Return Over Maximum Drawdown", "1.404"},
|
||||
{"Portfolio Turnover", "1.296"},
|
||||
{"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", "974523768"}
|
||||
{"Total Trades", "66"},
|
||||
{"Average Win", "1.06%"},
|
||||
{"Average Loss", "-0.50%"},
|
||||
{"Compounding Annual Return", "18.511%"},
|
||||
{"Drawdown", "7.100%"},
|
||||
{"Expectancy", "0.810"},
|
||||
{"Net Profit", "18.511%"},
|
||||
{"Sharpe Ratio", "1.439"},
|
||||
{"Loss Rate", "42%"},
|
||||
{"Win Rate", "58%"},
|
||||
{"Profit-Loss Ratio", "2.12"},
|
||||
{"Alpha", "0.308"},
|
||||
{"Beta", "-10.065"},
|
||||
{"Annual Standard Deviation", "0.1"},
|
||||
{"Annual Variance", "0.01"},
|
||||
{"Information Ratio", "1.275"},
|
||||
{"Tracking Error", "0.1"},
|
||||
{"Treynor Ratio", "-0.014"},
|
||||
{"Total Fees", "$193.75"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -106,30 +105,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-7.068"},
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.SEC;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an example algorithm showcasing the <see cref="Security.Data"/> features
|
||||
/// </summary>
|
||||
public class DynamicSecurityDataAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Security GOOGL;
|
||||
private const string Ticker = "GOOGL";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2015, 10, 22);
|
||||
SetEndDate(2015, 10, 30);
|
||||
|
||||
GOOGL = AddEquity(Ticker, Resolution.Daily);
|
||||
|
||||
AddData<SECReport8K>(Ticker, Resolution.Daily);
|
||||
AddData<SECReport10K>(Ticker, Resolution.Daily);
|
||||
AddData<SECReport10Q>(Ticker, Resolution.Daily);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// The Security object's Data property provides convenient access
|
||||
// to the various types of data related to that security. You can
|
||||
// access not only the security's price data, but also any custom
|
||||
// data that is mapped to the security, such as our SEC reports.
|
||||
|
||||
// 1. Get the most recent data point of a particular type:
|
||||
// 1.a Using the C# generic method, Get<T>:
|
||||
SECReport8K googlSec8kReport = GOOGL.Data.Get<SECReport8K>();
|
||||
SECReport10K googlSec10kReport = GOOGL.Data.Get<SECReport10K>();
|
||||
Log($"{Time:o}: 8K: {googlSec8kReport}");
|
||||
Log($"{Time:o}: 10K: {googlSec10kReport}");
|
||||
|
||||
// 2. Get the list of data points of a particular type for the most recent time step:
|
||||
// 2.a Using the C# generic method, GetAll<T>:
|
||||
List<SECReport8K> googlSec8kReports = GOOGL.Data.GetAll<SECReport8K>();
|
||||
List<SECReport10K> googlSec10kReports = GOOGL.Data.GetAll<SECReport10K>();
|
||||
Log($"{Time:o}: List: 8K: {googlSec8kReports.Count}");
|
||||
Log($"{Time:o}: List: 10K: {googlSec10kReports.Count}");
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
Buy(GOOGL.Symbol, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var orderedObjScores = _symbolData.OrderByDescending(x => x.ObjectiveScore).ToList();
|
||||
foreach (var orderedObjScore in orderedObjScores)
|
||||
{
|
||||
Log($">>SCORE>>{orderedObjScore.Symbol}>>{orderedObjScore.ObjectiveScore.ToStringInvariant()}");
|
||||
Log(">>SCORE>>" + orderedObjScore.Symbol + ">>" + orderedObjScore.ObjectiveScore);
|
||||
}
|
||||
var bestGrowth = orderedObjScores.First();
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Log("PREBUY>>LIQUIDATE>>");
|
||||
Liquidate();
|
||||
}
|
||||
Log($">>BUY>>{bestGrowth.Symbol}@{(100 * bestGrowth.OneMonthPerformance).ToStringInvariant("00.00")}");
|
||||
Log(">>BUY>>" + bestGrowth.Symbol + "@" + (100 * bestGrowth.OneMonthPerformance).ToString("00.00"));
|
||||
var qty = Portfolio.MarginRemaining / Securities[bestGrowth.Symbol].Close;
|
||||
MarketOrder(bestGrowth.Symbol, (int) qty);
|
||||
}
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Consolidators;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Securities;
|
||||
using System.Linq;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to implement a cross moving average for the futures front contract
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="indicator" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class EmaCrossFuturesFrontMonthAlgorithm : QCAlgorithm
|
||||
{
|
||||
private const decimal _tolerance = 0.001m;
|
||||
private Symbol _symbol;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
private IDataConsolidator _consolidator;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 10);
|
||||
SetCash(1000000);
|
||||
|
||||
var future = AddFuture(Futures.Metals.Gold);
|
||||
|
||||
// Only consider the front month contract
|
||||
// Update the universe once per day to improve performance
|
||||
future.SetFilter(x => x.FrontMonth().OnlyApplyFilterAtMarketOpen());
|
||||
|
||||
// Create two exponential moving averages
|
||||
_fast = new ExponentialMovingAverage(100);
|
||||
_slow = new ExponentialMovingAverage(300);
|
||||
|
||||
// Add a custom chart to track the EMA cross
|
||||
var chart = new Chart("EMA Cross");
|
||||
chart.AddSeries(new Series("Fast", SeriesType.Line, 0));
|
||||
chart.AddSeries(new Series("Slow", SeriesType.Line, 0));
|
||||
AddChart(chart);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
SecurityHolding holding;
|
||||
if (Portfolio.TryGetValue(_symbol, out holding))
|
||||
{
|
||||
// Buy the futures' front contract when the fast EMA is above the slow one
|
||||
if (_fast > _slow * (1 + _tolerance))
|
||||
{
|
||||
if (!holding.Invested)
|
||||
{
|
||||
SetHoldings(_symbol, .1);
|
||||
PlotEma();
|
||||
}
|
||||
}
|
||||
else if (holding.Invested)
|
||||
{
|
||||
Liquidate(_symbol);
|
||||
PlotEma();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
if (changes.RemovedSecurities.Count > 0)
|
||||
{
|
||||
// Remove the consolidator for the previous contract
|
||||
// and reset the indicators
|
||||
if (_symbol != null && _consolidator != null)
|
||||
{
|
||||
SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
|
||||
_fast.Reset();
|
||||
_slow.Reset();
|
||||
}
|
||||
// We don't need to call Liquidate(_symbol),
|
||||
// since its positions are liquidated because the contract has expired.
|
||||
}
|
||||
|
||||
// Only one security will be added: the new front contract
|
||||
_symbol = changes.AddedSecurities.SingleOrDefault().Symbol;
|
||||
|
||||
// Create a new consolidator and register the indicators to it
|
||||
_consolidator = ResolveConsolidator(_symbol, Resolution.Minute);
|
||||
RegisterIndicator(_symbol, _fast, _consolidator);
|
||||
RegisterIndicator(_symbol, _slow, _consolidator);
|
||||
|
||||
// Warm up the indicators
|
||||
WarmUpIndicator(_symbol, _fast, Resolution.Minute);
|
||||
WarmUpIndicator(_symbol, _slow, Resolution.Minute);
|
||||
|
||||
PlotEma();
|
||||
}
|
||||
|
||||
private void PlotEma()
|
||||
{
|
||||
Plot("EMA Cross", "Fast", _fast);
|
||||
Plot("EMA Cross", "Slow", _slow);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -74,29 +74,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "5.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "-3.802%"},
|
||||
{"Sharpe Ratio", "-12.079"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Annual Standard Deviation", "0.397"},
|
||||
{"Annual Variance", "0.158"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$14.91"},
|
||||
{"Fitness Score", "0.258"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-27.251"},
|
||||
{"Portfolio Turnover", "0.515"},
|
||||
{"Total Fees", "$14.92"},
|
||||
{"Total Insights Generated", "1"},
|
||||
{"Total Insights Closed", "1"},
|
||||
{"Total Insights Analysis Completed", "1"},
|
||||
@@ -109,8 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "221046152"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -17,6 +17,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Data;
|
||||
@@ -111,32 +112,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "5"},
|
||||
{"Total Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-72.415%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-72.251%"},
|
||||
{"Drawdown", "2.800%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-1.749%"},
|
||||
{"Sharpe Ratio", "-3.059"},
|
||||
{"Probabilistic Sharpe Ratio", "21.811%"},
|
||||
{"Net Profit", "-1.741%"},
|
||||
{"Sharpe Ratio", "-4.242"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.385"},
|
||||
{"Beta", "-0.146"},
|
||||
{"Annual Standard Deviation", "0.191"},
|
||||
{"Annual Variance", "0.036"},
|
||||
{"Information Ratio", "-6.701"},
|
||||
{"Tracking Error", "0.29"},
|
||||
{"Treynor Ratio", "4.005"},
|
||||
{"Total Fees", "$18.28"},
|
||||
{"Fitness Score", "0.052"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-4.187"},
|
||||
{"Return Over Maximum Drawdown", "-25.473"},
|
||||
{"Portfolio Turnover", "0.998"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "-62.982"},
|
||||
{"Annual Standard Deviation", "0.171"},
|
||||
{"Annual Variance", "0.029"},
|
||||
{"Information Ratio", "-4.308"},
|
||||
{"Tracking Error", "0.171"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$10.77"},
|
||||
{"Total Insights Generated", "1"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -149,8 +143,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1300818910"}
|
||||
{"Rolling Averaged Population Magnitude", "0%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -110,43 +110,35 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "4"},
|
||||
{"Average Win", "0.96%"},
|
||||
{"Average Loss", "-0.95%"},
|
||||
{"Compounding Annual Return", "-44.357%"},
|
||||
{"Compounding Annual Return", "-44.117%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0.005"},
|
||||
{"Net Profit", "-0.800%"},
|
||||
{"Sharpe Ratio", "-2.218"},
|
||||
{"Probabilistic Sharpe Ratio", "32.508%"},
|
||||
{"Expectancy", "0.002"},
|
||||
{"Net Profit", "-0.794%"},
|
||||
{"Sharpe Ratio", "-2.497"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "1.01"},
|
||||
{"Alpha", "-0.64"},
|
||||
{"Beta", "0.23"},
|
||||
{"Annual Standard Deviation", "0.147"},
|
||||
{"Annual Variance", "0.022"},
|
||||
{"Information Ratio", "-8.259"},
|
||||
{"Tracking Error", "0.204"},
|
||||
{"Treynor Ratio", "-1.424"},
|
||||
{"Profit-Loss Ratio", "1.00"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "-28.473"},
|
||||
{"Annual Standard Deviation", "0.131"},
|
||||
{"Annual Variance", "0.017"},
|
||||
{"Information Ratio", "-2.584"},
|
||||
{"Tracking Error", "0.131"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$16.26"},
|
||||
{"Fitness Score", "0.003"},
|
||||
{"Kelly Criterion Estimate", "12.539"},
|
||||
{"Kelly Criterion Probability Value", "0.367"},
|
||||
{"Sortino Ratio", "-22.336"},
|
||||
{"Return Over Maximum Drawdown", "-38.722"},
|
||||
{"Portfolio Turnover", "1.003"},
|
||||
{"Total Insights Generated", "7"},
|
||||
{"Total Insights Closed", "4"},
|
||||
{"Total Insights Analysis Completed", "4"},
|
||||
{"Long Insight Count", "5"},
|
||||
{"Short Insight Count", "2"},
|
||||
{"Long/Short Ratio", "250.0%"},
|
||||
{"Estimated Monthly Alpha Value", "$19016880.2887"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$3275129.3830"},
|
||||
{"Mean Population Estimated Insight Value", "$818782.3458"},
|
||||
{"Estimated Monthly Alpha Value", "$15518791.1380"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$2672680.6960"},
|
||||
{"Mean Population Estimated Insight Value", "$668170.1740"},
|
||||
{"Mean Population Direction", "50%"},
|
||||
{"Mean Population Magnitude", "50%"},
|
||||
{"Rolling Averaged Population Direction", "50%"},
|
||||
{"Rolling Averaged Population Magnitude", "50%"},
|
||||
{"OrderListHash", "-218498072"}
|
||||
{"Rolling Averaged Population Magnitude", "50%"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Futures regression algorithm intended to test the behavior of the framework models. See GH issue 4027.
|
||||
/// </summary>
|
||||
public class EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private int _fillCount;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
SetUniverseSelection(new FrontMonthFutureUniverseSelectionModel(SelectFutureChainSymbols));
|
||||
SetAlpha(new ConstantFutureContractAlphaModel(InsightType.Price, InsightDirection.Up, TimeSpan.FromDays(1)));
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
}
|
||||
|
||||
// future symbol universe selection function
|
||||
private static IEnumerable<Symbol> SelectFutureChainSymbols(DateTime utcTime)
|
||||
{
|
||||
return new []
|
||||
{
|
||||
QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME),
|
||||
QuantConnect.Symbol.Create(Futures.Metals.Gold, SecurityType.Future, Market.COMEX)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates futures chain universes that select the front month contract and runs a user
|
||||
/// defined futureChainSymbolSelector every day to enable choosing different futures chains
|
||||
/// </summary>
|
||||
class FrontMonthFutureUniverseSelectionModel : FutureUniverseSelectionModel
|
||||
{
|
||||
public FrontMonthFutureUniverseSelectionModel(Func<DateTime, IEnumerable<Symbol>> futureChainSymbolSelector)
|
||||
: base(TimeSpan.FromDays(1), futureChainSymbolSelector)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines the future chain universe filter
|
||||
/// </summary>
|
||||
protected override FutureFilterUniverse Filter(FutureFilterUniverse filter)
|
||||
{
|
||||
return filter
|
||||
.FrontMonth()
|
||||
.OnlyApplyFilterAtMarketOpen();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of a constant alpha model that only emits insights for future symbols
|
||||
/// </summary>
|
||||
class ConstantFutureContractAlphaModel : ConstantAlphaModel
|
||||
{
|
||||
public ConstantFutureContractAlphaModel(InsightType type, InsightDirection direction, TimeSpan period)
|
||||
: base(type, direction, period)
|
||||
{
|
||||
}
|
||||
|
||||
protected override bool ShouldEmitInsight(DateTime utcTime, Symbol symbol)
|
||||
{
|
||||
// only emit alpha for future symbols and not underlying equity symbols
|
||||
if (symbol.SecurityType != SecurityType.Future)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.ShouldEmitInsight(utcTime, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Log($"{orderEvent}");
|
||||
if (orderEvent.Status == OrderStatus.Filled)
|
||||
{
|
||||
_fillCount++;
|
||||
if (_fillCount == 2)
|
||||
{
|
||||
if (Portfolio.TotalHoldingsValue / Portfolio.TotalPortfolioValue < 10)
|
||||
{
|
||||
throw new Exception("Expected to be trading using the futures margin leverage");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.91%"},
|
||||
{"Compounding Annual Return", "-99.755%"},
|
||||
{"Drawdown", "29.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-7.463%"},
|
||||
{"Sharpe Ratio", "-0.605"},
|
||||
{"Probabilistic Sharpe Ratio", "34.850%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-13.685"},
|
||||
{"Beta", "6.59"},
|
||||
{"Annual Standard Deviation", "1.632"},
|
||||
{"Annual Variance", "2.665"},
|
||||
{"Information Ratio", "-2.023"},
|
||||
{"Tracking Error", "1.441"},
|
||||
{"Treynor Ratio", "-0.15"},
|
||||
{"Total Fees", "$33.30"},
|
||||
{"Fitness Score", "0.079"},
|
||||
{"Kelly Criterion Estimate", "-9.366"},
|
||||
{"Kelly Criterion Probability Value", "0.607"},
|
||||
{"Sortino Ratio", "-4.657"},
|
||||
{"Return Over Maximum Drawdown", "-5.203"},
|
||||
{"Portfolio Turnover", "4.377"},
|
||||
{"Total Insights Generated", "10"},
|
||||
{"Total Insights Closed", "8"},
|
||||
{"Total Insights Analysis Completed", "8"},
|
||||
{"Long Insight Count", "10"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$-78.89231"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-12.82"},
|
||||
{"Mean Population Estimated Insight Value", "$-1.6025"},
|
||||
{"Mean Population Direction", "25%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "25.058%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1105779454"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm that test if the fill prices are the correct quote side.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="using quantconnect" />
|
||||
/// <meta name="tag" content="trading and orders" />
|
||||
public class EquityTradeAndQuotesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _symbol;
|
||||
private bool _canTrade;
|
||||
private int _quoteCounter;
|
||||
private int _tradeCounter;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
|
||||
SetSecurityInitializer(x => x.SetDataNormalizationMode(DataNormalizationMode.Raw));
|
||||
|
||||
_symbol = AddEquity("IBM", Resolution.Minute).Symbol;
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
// 2013-10-07 was Monday, that's why we ask 3 days history to get data from previous Friday.
|
||||
var history = History(new[] { _symbol }, TimeSpan.FromDays(3), Resolution.Minute).ToList();
|
||||
Log($"{Time} - history.Count: {history.Count}");
|
||||
|
||||
const int expectedSliceCount = 390;
|
||||
if (history.Count != expectedSliceCount)
|
||||
{
|
||||
throw new Exception($"History slices - expected: {expectedSliceCount}, actual: {history.Count}");
|
||||
}
|
||||
|
||||
|
||||
if (history.Any(s => s.Bars.Count != 1 && s.QuoteBars.Count != 1))
|
||||
{
|
||||
throw new Exception($"History not all slices have trades and quotes.");
|
||||
}
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_symbol), TimeRules.AfterMarketOpen(_symbol, 0), () => { _canTrade = true; });
|
||||
|
||||
Schedule.On(DateRules.EveryDay(_symbol), TimeRules.BeforeMarketClose(_symbol, 16), () => { _canTrade = false; });
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
_quoteCounter += data.QuoteBars.Count;
|
||||
_tradeCounter += data.Bars.Count;
|
||||
|
||||
if (!Portfolio.Invested && _canTrade)
|
||||
{
|
||||
SetHoldings(_symbol, 1);
|
||||
Log($"Purchased Security {_symbol.ID}");
|
||||
}
|
||||
|
||||
if (Time.Minute % 15 == 0)
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var addedSecurity in changes.AddedSecurities)
|
||||
{
|
||||
var subscriptions = SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(addedSecurity.Symbol);
|
||||
if (addedSecurity.Symbol == _symbol)
|
||||
{
|
||||
if (!(subscriptions.Count == 2 &&
|
||||
subscriptions.Any(s => s.TickType == TickType.Trade) &&
|
||||
subscriptions.Any(s => s.TickType == TickType.Quote)))
|
||||
{
|
||||
throw new Exception($"Subscriptions were not correctly added for high resolution.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (subscriptions.Single().TickType != TickType.Trade)
|
||||
{
|
||||
throw new Exception($"Subscriptions were not correctly added for low resolution.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
if (orderEvent.Status == OrderStatus.Filled)
|
||||
{
|
||||
Log($"{Time:s} {orderEvent.Direction}");
|
||||
var expectedFillPrice = orderEvent.Direction == OrderDirection.Buy ? Securities[_symbol].AskPrice : Securities[_symbol].BidPrice;
|
||||
if (orderEvent.FillPrice != expectedFillPrice)
|
||||
{
|
||||
throw new Exception($"Fill price is not the expected for OrderId {orderEvent.OrderId} at Algorithm Time {Time:s}." +
|
||||
$"\n\tExpected fill price: {expectedFillPrice}, Actual fill price: {orderEvent.FillPrice}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
// We expect at least 390 * 5 = 1950 minute bar
|
||||
// + 5 daily bars, but those are pumped into OnData every minute
|
||||
if (_tradeCounter <= 1955)
|
||||
{
|
||||
throw new Exception($"Fail at trade bars count expected >= 1955, actual: {_tradeCounter}.");
|
||||
}
|
||||
// We expect 390 * 5 = 1950 quote bars.
|
||||
if (_quoteCounter != 1950)
|
||||
{
|
||||
throw new Exception($"Fail at trade bars count expected: 1950, actual: {_quoteCounter}.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "250"},
|
||||
{"Average Win", "0.12%"},
|
||||
{"Average Loss", "-0.10%"},
|
||||
{"Compounding Annual Return", "-88.523%"},
|
||||
{"Drawdown", "3.400%"},
|
||||
{"Expectancy", "-0.238"},
|
||||
{"Net Profit", "-2.922%"},
|
||||
{"Sharpe Ratio", "-5.16"},
|
||||
{"Probabilistic Sharpe Ratio", "0.502%"},
|
||||
{"Loss Rate", "65%"},
|
||||
{"Win Rate", "35%"},
|
||||
{"Profit-Loss Ratio", "1.17"},
|
||||
{"Alpha", "-1.423"},
|
||||
{"Beta", "0.537"},
|
||||
{"Annual Standard Deviation", "0.134"},
|
||||
{"Annual Variance", "0.018"},
|
||||
{"Information Ratio", "-16.652"},
|
||||
{"Tracking Error", "0.123"},
|
||||
{"Treynor Ratio", "-1.288"},
|
||||
{"Total Fees", "$669.76"},
|
||||
{"Fitness Score", "0.021"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-7.372"},
|
||||
{"Return Over Maximum Drawdown", "-30.295"},
|
||||
{"Portfolio Turnover", "49.96"},
|
||||
{"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", "1040964928"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2017, 1, 1);
|
||||
SetEndDate(2017, 12, 31);
|
||||
|
||||
// be sure to add the underlying data source for our estimize data as it requires the mappings
|
||||
AddEquity("AAPL");
|
||||
|
||||
AddData<EstimizeRelease>("AAPL");
|
||||
AddData<EstimizeEstimate>("AAPL");
|
||||
AddData<EstimizeConsensus>("AAPL");
|
||||
AddData<EstimizeRelease>("AAPL.R");
|
||||
AddData<EstimizeEstimate>("AAPL.E");
|
||||
AddData<EstimizeConsensus>("AAPL.C");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -156,44 +156,23 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Average Loss", "-6.67%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "3.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-6.428%"},
|
||||
{"Sharpe Ratio", "-11.232"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$804.33"},
|
||||
{"Fitness Score", "0.504"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-15.573"},
|
||||
{"Portfolio Turnover", "2.056"},
|
||||
{"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", "-1311542155"}
|
||||
{"Alpha", "-16.193"},
|
||||
{"Beta", "1173.18"},
|
||||
{"Annual Standard Deviation", "0.721"},
|
||||
{"Annual Variance", "0.52"},
|
||||
{"Information Ratio", "-11.251"},
|
||||
{"Tracking Error", "0.72"},
|
||||
{"Treynor Ratio", "-0.007"},
|
||||
{"Total Fees", "$804.33"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Fundamental;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm which tests a fine fundamental filtered universe, related to GH issue 4127
|
||||
/// </summary>
|
||||
public class FineFundamentalFilteredUniverseRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 10, 07);
|
||||
SetEndDate(2014, 10, 11);
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
var customUniverseSymbol = new Symbol(SecurityIdentifier.GenerateConstituentIdentifier(
|
||||
"constituents-universe-qctest",
|
||||
SecurityType.Equity,
|
||||
Market.USA),
|
||||
"constituents-universe-qctest");
|
||||
|
||||
// we use test ConstituentsUniverse
|
||||
AddUniverse(new ConstituentsUniverse(customUniverseSymbol, UniverseSettings), FineSelectionFunction);
|
||||
}
|
||||
|
||||
private IEnumerable<Symbol> FineSelectionFunction(IEnumerable<FineFundamental> data)
|
||||
{
|
||||
return data.Where(fundamental => fundamental.CompanyProfile.HeadquarterCity.Equals("Cupertino"))
|
||||
.Select(fundamental => fundamental.Symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
if (data.Keys.Single().Value != "AAPL")
|
||||
{
|
||||
throw new Exception($"Unexpected symbol was added to the universe: {data.Keys.Single()}");
|
||||
}
|
||||
SetHoldings(data.Keys.Single(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "500.622%"},
|
||||
{"Drawdown", "0.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.984%"},
|
||||
{"Sharpe Ratio", "14.933"},
|
||||
{"Probabilistic Sharpe Ratio", "90.520%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "2.211"},
|
||||
{"Beta", "-0.467"},
|
||||
{"Annual Standard Deviation", "0.166"},
|
||||
{"Annual Variance", "0.028"},
|
||||
{"Information Ratio", "7.778"},
|
||||
{"Tracking Error", "0.394"},
|
||||
{"Treynor Ratio", "-5.313"},
|
||||
{"Total Fees", "$5.40"},
|
||||
{"Fitness Score", "0.244"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "1748.254"},
|
||||
{"Portfolio Turnover", "0.244"},
|
||||
{"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", "-423205673"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
private readonly Dictionary<Symbol, int> _dataPointsPerSymbol = new Dictionary<Symbol, int>();
|
||||
private bool _added;
|
||||
private Symbol _eurusd;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
@@ -40,7 +39,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2013, 10, 8);
|
||||
SetCash(100000);
|
||||
|
||||
_eurusd = QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.FXCM);
|
||||
var eurgbp = AddForex("EURGBP", Resolution.Daily);
|
||||
_dataPointsPerSymbol.Add(eurgbp.Symbol, 0);
|
||||
}
|
||||
@@ -53,9 +51,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
if (_added)
|
||||
{
|
||||
var eurUsdSubscription = SubscriptionManager.SubscriptionDataConfigService
|
||||
.GetSubscriptionDataConfigs(_eurusd, includeInternalConfigs:true)
|
||||
.Single();
|
||||
var eurUsdSubscription = SubscriptionManager.Subscriptions.Single(x => x.Symbol.Value == "EURUSD");
|
||||
if (eurUsdSubscription.IsInternalFeed)
|
||||
{
|
||||
throw new Exception("Unexpected internal 'EURUSD' Subscription");
|
||||
@@ -63,15 +59,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
if (!_added)
|
||||
{
|
||||
var eurUsdSubscription = SubscriptionManager.SubscriptionDataConfigService
|
||||
.GetSubscriptionDataConfigs(_eurusd, includeInternalConfigs: true)
|
||||
.Single();
|
||||
var eurUsdSubscription = SubscriptionManager.Subscriptions.Single(x => x.Symbol.Value == "EURUSD");
|
||||
if (!eurUsdSubscription.IsInternalFeed)
|
||||
{
|
||||
throw new Exception("Unexpected not internal 'EURUSD' Subscription");
|
||||
}
|
||||
AddForex("EURUSD", Resolution.Hour);
|
||||
_dataPointsPerSymbol.Add(_eurusd, 0);
|
||||
var eurusd = AddForex("EURUSD", Resolution.Hour);
|
||||
_dataPointsPerSymbol.Add(eurusd.Symbol, 0);
|
||||
|
||||
_added = true;
|
||||
}
|
||||
@@ -81,7 +75,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var symbol = kvp.Key;
|
||||
_dataPointsPerSymbol[symbol]++;
|
||||
|
||||
Log($"{Time} {symbol.Value} {kvp.Value.Price} EndTime {kvp.Value.EndTime}");
|
||||
Log($"{Time} {symbol.Value} {kvp.Value.Price}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +88,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var expectedDataPointsPerSymbol = new Dictionary<string, int>
|
||||
{
|
||||
{ "EURGBP", 3 },
|
||||
{ "EURUSD", 48 }
|
||||
{ "EURUSD", 24 }
|
||||
};
|
||||
|
||||
foreach (var kvp in _dataPointsPerSymbol)
|
||||
@@ -105,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
if (actualDataPoints != expectedDataPointsPerSymbol[symbol.Value])
|
||||
{
|
||||
throw new Exception($"Data point count mismatch for symbol {symbol.Value}: expected: {expectedDataPointsPerSymbol[symbol.Value]}, actual: {actualDataPoints}");
|
||||
throw new Exception($"Data point count mismatch for symbol {symbol.Value}: expected: {expectedDataPointsPerSymbol}, actual: {actualDataPoints}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +127,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -141,30 +134,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "5.893"},
|
||||
{"Tracking Error", "0.131"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
private readonly Dictionary<Symbol, int> _dataPointsPerSymbol = new Dictionary<Symbol, int>();
|
||||
private bool _added;
|
||||
private Symbol _eurusd;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
@@ -40,7 +39,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2013, 10, 8);
|
||||
SetCash(100000);
|
||||
|
||||
_eurusd = QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.FXCM);
|
||||
var eurgbp = AddForex("EURGBP", Resolution.Daily);
|
||||
_dataPointsPerSymbol.Add(eurgbp.Symbol, 0);
|
||||
}
|
||||
@@ -53,9 +51,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
if (_added)
|
||||
{
|
||||
var eurUsdSubscription = SubscriptionManager.SubscriptionDataConfigService
|
||||
.GetSubscriptionDataConfigs(_eurusd, includeInternalConfigs: true)
|
||||
.Single();
|
||||
var eurUsdSubscription = SubscriptionManager.Subscriptions.Single(x => x.Symbol.Value == "EURUSD");
|
||||
if (eurUsdSubscription.IsInternalFeed)
|
||||
{
|
||||
throw new Exception("Unexpected internal 'EURUSD' Subscription");
|
||||
@@ -63,9 +59,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
if (!_added)
|
||||
{
|
||||
var eurUsdSubscription = SubscriptionManager.SubscriptionDataConfigService
|
||||
.GetSubscriptionDataConfigs(_eurusd, includeInternalConfigs: true)
|
||||
.Single();
|
||||
var eurUsdSubscription = SubscriptionManager.Subscriptions.Single(x => x.Symbol.Value == "EURUSD");
|
||||
if (!eurUsdSubscription.IsInternalFeed)
|
||||
{
|
||||
throw new Exception("Unexpected not internal 'EURUSD' Subscription");
|
||||
@@ -81,7 +75,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var symbol = kvp.Key;
|
||||
_dataPointsPerSymbol[symbol]++;
|
||||
|
||||
Log($"{Time} {symbol.Value} {kvp.Value.Price} EndTime {kvp.Value.EndTime}");
|
||||
Log($"{Time} {symbol.Value} {kvp.Value.Price}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +90,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// normal feed
|
||||
{ "EURGBP", 3 },
|
||||
// internal feed on the first day, normal feed on the other two days
|
||||
{ "EURUSD", 3 },
|
||||
{ "EURUSD", 2 },
|
||||
// internal feed only
|
||||
{ "GBPUSD", 0 }
|
||||
};
|
||||
@@ -137,7 +131,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -145,30 +138,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "5.893"},
|
||||
{"Tracking Error", "0.131"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
|
||||
|
||||
SetTimeZone(NodaTime.DateTimeZone.Utc);
|
||||
var security = AddSecurity(SecurityType.Crypto, "BTCUSD", Resolution.Daily, Market.GDAX, false, 1, true);
|
||||
var security = AddSecurity(SecurityType.Crypto, "BTCUSD", Resolution.Daily, Market.GDAX, false, 3.3m, true);
|
||||
|
||||
// The default buying power model for the Crypto security type is now CashBuyingPowerModel.
|
||||
// Since this test algorithm uses leverage we need to set a buying power model with margin.
|
||||
@@ -101,43 +101,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "6.02%"},
|
||||
{"Average Loss", "-2.40%"},
|
||||
{"Compounding Annual Return", "915.481%"},
|
||||
{"Compounding Annual Return", "915.597%"},
|
||||
{"Drawdown", "5.500%"},
|
||||
{"Expectancy", "1.338"},
|
||||
{"Net Profit", "11.400%"},
|
||||
{"Sharpe Ratio", "9.507"},
|
||||
{"Probabilistic Sharpe Ratio", "76.768%"},
|
||||
{"Expectancy", "1.339"},
|
||||
{"Net Profit", "11.401%"},
|
||||
{"Sharpe Ratio", "3.299"},
|
||||
{"Loss Rate", "33%"},
|
||||
{"Win Rate", "67%"},
|
||||
{"Profit-Loss Ratio", "2.51"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0.507"},
|
||||
{"Annual Variance", "0.257"},
|
||||
{"Information Ratio", "9.507"},
|
||||
{"Tracking Error", "0.507"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$2651.00"},
|
||||
{"Fitness Score", "0.467"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "53.455"},
|
||||
{"Return Over Maximum Drawdown", "165.408"},
|
||||
{"Portfolio Turnover", "0.468"},
|
||||
{"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", "-1241317053"}
|
||||
{"Alpha", "-0.409"},
|
||||
{"Beta", "1.047"},
|
||||
{"Annual Standard Deviation", "0.493"},
|
||||
{"Annual Variance", "0.243"},
|
||||
{"Information Ratio", "-2.648"},
|
||||
{"Tracking Error", "0.12"},
|
||||
{"Treynor Ratio", "1.555"},
|
||||
{"Total Fees", "$2650.41"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm which reproduced GH issue 3759 (performing 26 trades).
|
||||
/// </summary>
|
||||
public class FreePortfolioValueRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
SetStartDate(2007, 10, 1);
|
||||
SetEndDate(2018, 2, 1);
|
||||
SetCash(1000000);
|
||||
|
||||
UniverseSettings.Leverage = 1;
|
||||
SetUniverseSelection(
|
||||
new ManualUniverseSelectionModel(QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA))
|
||||
);
|
||||
SetAlpha(
|
||||
new ConstantAlphaModel(InsightType.Price, InsightDirection.Up, QuantConnect.Time.OneDay, 0.025, null)
|
||||
);
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (Settings.FreePortfolioValue != 1000000 * Settings.FreePortfolioValuePercentage)
|
||||
{
|
||||
throw new Exception($"Unexpected FreePortfolioValue value: {Settings.FreePortfolioValue}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug($"OnOrderEvent: {orderEvent}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "8.172%"},
|
||||
{"Drawdown", "55.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "125.433%"},
|
||||
{"Sharpe Ratio", "0.468"},
|
||||
{"Probabilistic Sharpe Ratio", "2.573%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.093"},
|
||||
{"Beta", "-0.1"},
|
||||
{"Annual Standard Deviation", "0.18"},
|
||||
{"Annual Variance", "0.032"},
|
||||
{"Information Ratio", "-0.001"},
|
||||
{"Tracking Error", "0.267"},
|
||||
{"Treynor Ratio", "-0.846"},
|
||||
{"Total Fees", "$41.17"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "38.884"},
|
||||
{"Kelly Criterion Probability Value", "0.009"},
|
||||
{"Sortino Ratio", "0.501"},
|
||||
{"Return Over Maximum Drawdown", "0.148"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "2604"},
|
||||
{"Total Insights Closed", "2603"},
|
||||
{"Total Insights Analysis Completed", "2603"},
|
||||
{"Long Insight Count", "2604"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$1176372.2118"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$148113430.7231"},
|
||||
{"Mean Population Estimated Insight Value", "$56901.0491"},
|
||||
{"Mean Population Direction", "43.2962%"},
|
||||
{"Mean Population Magnitude", "43.2962%"},
|
||||
{"Rolling Averaged Population Direction", "48.763%"},
|
||||
{"Rolling Averaged Population Magnitude", "48.763%"},
|
||||
{"OrderListHash", "-1756838669"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm showcasing adding two futures with the same ticker for different market, related to PR 4328
|
||||
/// </summary>
|
||||
public class FutureSharingTickerRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 10);
|
||||
|
||||
var gold = AddFuture(Futures.Metals.Gold, market: Market.COMEX);
|
||||
gold.SetFilter(0, 182);
|
||||
|
||||
// this future does not exist just added as an example
|
||||
var gold2 = AddFuture(Futures.Metals.Gold, market: Market.NYMEX);
|
||||
gold2.SetFilter(0, 182);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
foreach (var chain in data.FutureChains)
|
||||
{
|
||||
// find the front contract expiring no earlier than in 90 days
|
||||
var contract = (
|
||||
from futuresContract in chain.Value.OrderBy(x => x.Expiry)
|
||||
where futuresContract.Expiry > Time.Date.AddDays(90)
|
||||
select futuresContract
|
||||
).FirstOrDefault();
|
||||
|
||||
if (contract != null)
|
||||
{
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-98.645%"},
|
||||
{"Drawdown", "5.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-3.474%"},
|
||||
{"Sharpe Ratio", "-4.693"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.545"},
|
||||
{"Beta", "-0.45"},
|
||||
{"Annual Standard Deviation", "0.194"},
|
||||
{"Annual Variance", "0.038"},
|
||||
{"Information Ratio", "-19.15"},
|
||||
{"Tracking Error", "0.332"},
|
||||
{"Treynor Ratio", "2.021"},
|
||||
{"Total Fees", "$1.85"},
|
||||
{"Fitness Score", "0.005"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-10.938"},
|
||||
{"Return Over Maximum Drawdown", "-25.528"},
|
||||
{"Portfolio Turnover", "0.445"},
|
||||
{"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", "378972600"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -300,43 +300,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "364.889%"},
|
||||
{"Compounding Annual Return", "359.952%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.698%"},
|
||||
{"Sharpe Ratio", "8.904"},
|
||||
{"Probabilistic Sharpe Ratio", "67.623%"},
|
||||
{"Net Profit", "1.686%"},
|
||||
{"Sharpe Ratio", "4.502"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.575"},
|
||||
{"Beta", "0.072"},
|
||||
{"Annual Standard Deviation", "0.218"},
|
||||
{"Annual Variance", "0.047"},
|
||||
{"Information Ratio", "-11.876"},
|
||||
{"Tracking Error", "0.264"},
|
||||
{"Treynor Ratio", "26.924"},
|
||||
{"Total Fees", "$3.26"},
|
||||
{"Fitness Score", "0.251"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "318.537"},
|
||||
{"Portfolio Turnover", "0.251"},
|
||||
{"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", "1268340653"}
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "77.786"},
|
||||
{"Annual Standard Deviation", "0.191"},
|
||||
{"Annual Variance", "0.036"},
|
||||
{"Information Ratio", "4.445"},
|
||||
{"Tracking Error", "0.191"},
|
||||
{"Treynor Ratio", "0.011"},
|
||||
{"Total Fees", "$3.26"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -82,7 +82,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -90,30 +89,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-7.068"},
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "371857150"}
|
||||
{"Total Fees", "$0.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,43 +67,22 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Compounding Annual Return", "-5.029%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "-0.024%"},
|
||||
{"Sharpe Ratio", "-11.225"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Standard Deviation", "0.003"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1795141360"}
|
||||
{"Total Fees", "$1.00"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user