Compare commits
130 Commits
feature-py
...
10604
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
115dcab789 | ||
|
|
5117609ea5 | ||
|
|
6040cc8e90 | ||
|
|
eb25dce462 | ||
|
|
0d0389ef6a | ||
|
|
3e962b2e76 | ||
|
|
f263fd49a7 | ||
|
|
9b38bf3d91 | ||
|
|
7d70698c9a | ||
|
|
1606b12475 | ||
|
|
3a483fc4ec | ||
|
|
fe74d037c6 | ||
|
|
43e9cad2d6 | ||
|
|
403ea22606 | ||
|
|
6cb103b17a | ||
|
|
8cbdfcaf28 | ||
|
|
1778462505 | ||
|
|
472896c2d0 | ||
|
|
15cb846570 | ||
|
|
553b50a92e | ||
|
|
5f73a05e04 | ||
|
|
a5eaa43e35 | ||
|
|
e91af0814f | ||
|
|
a2850fb20c | ||
|
|
c86fceac97 | ||
|
|
9997df45af | ||
|
|
1ef92b3eca | ||
|
|
c6d29c8be5 | ||
|
|
97deb4bbc6 | ||
|
|
6ab40c102b | ||
|
|
41417593aa | ||
|
|
3ccf428498 | ||
|
|
5d8a62c2e1 | ||
|
|
5df29f16dd | ||
|
|
56a0d52212 | ||
|
|
765f2cab3b | ||
|
|
f175ac6c6b | ||
|
|
79c544d3a2 | ||
|
|
5dcbed535d | ||
|
|
35393b66a3 | ||
|
|
ce42c888ce | ||
|
|
f2fd10d9d2 | ||
|
|
94d766ff89 | ||
|
|
592d037085 | ||
|
|
17ab10531a | ||
|
|
9d576a4121 | ||
|
|
7aefe07274 | ||
|
|
6de9a146a9 | ||
|
|
4d4ad92fa7 | ||
|
|
345fe7357e | ||
|
|
3e7af17e02 | ||
|
|
a2a874e333 | ||
|
|
96592b3387 | ||
|
|
7e3741d983 | ||
|
|
e6d16882f7 | ||
|
|
d5aa9e65f3 | ||
|
|
ec1c4b7142 | ||
|
|
9a0d943f1d | ||
|
|
771244aaa0 | ||
|
|
659a57884c | ||
|
|
3f2a558f91 | ||
|
|
9bb7c77fb7 | ||
|
|
c8eb9e0099 | ||
|
|
b85a32a391 | ||
|
|
31d101253c | ||
|
|
7531046f14 | ||
|
|
6b99266669 | ||
|
|
8d48996948 | ||
|
|
7f381cb135 | ||
|
|
2b7372783a | ||
|
|
54fce3f666 | ||
|
|
12db2261dc | ||
|
|
c6d4888e70 | ||
|
|
33b58b0dbc | ||
|
|
56cb9fbec5 | ||
|
|
194e6f6b58 | ||
|
|
612c4f8b66 | ||
|
|
d3b9f8bc7a | ||
|
|
c4a1c245a7 | ||
|
|
050dadc21f | ||
|
|
7b0ea0982e | ||
|
|
f8cf923d7b | ||
|
|
14b44bbe17 | ||
|
|
2ed221b623 | ||
|
|
3f1c33e1c5 | ||
|
|
017b464e21 | ||
|
|
4dec21ccc0 | ||
|
|
529d0a3634 | ||
|
|
9c89e8d403 | ||
|
|
1988ad1ae5 | ||
|
|
3658fb1405 | ||
|
|
0ac79487d7 | ||
|
|
38120a3217 | ||
|
|
01a13a095a | ||
|
|
704a5cb00e | ||
|
|
490ad08c89 | ||
|
|
a60cd95611 | ||
|
|
eed8e9c763 | ||
|
|
365f53dfc7 | ||
|
|
48a86c2626 | ||
|
|
2de9c21b6d | ||
|
|
649aafc952 | ||
|
|
25fa4c6fb6 | ||
|
|
d1b35f7974 | ||
|
|
4006ba01e4 | ||
|
|
6d824b40a6 | ||
|
|
8e410fcaf1 | ||
|
|
d136428556 | ||
|
|
40d81965be | ||
|
|
c650eb6c1c | ||
|
|
aa2f9f927a | ||
|
|
c698a65a84 | ||
|
|
181283a4cd | ||
|
|
b247724a34 | ||
|
|
dde3576161 | ||
|
|
e8734a0797 | ||
|
|
7f5d69bbec | ||
|
|
f6be7a41a5 | ||
|
|
7f30c0cd00 | ||
|
|
6694fe01f8 | ||
|
|
32ab4fdea1 | ||
|
|
fc81f606e4 | ||
|
|
ec74abd4d0 | ||
|
|
bd3ead3480 | ||
|
|
45849962a3 | ||
|
|
8279cf7eac | ||
|
|
4c4a699cb0 | ||
|
|
31a2c31c0a | ||
|
|
877a123276 | ||
|
|
4134b05bfd |
31
.github/workflows/gh-actions.yml
vendored
Normal file
31
.github/workflows/gh-actions.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Build & Test Lean
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['*']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-16.04
|
||||
container:
|
||||
image: quantconnect/lean:foundation
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Restore nuget dependencies
|
||||
run: |
|
||||
nuget restore QuantConnect.Lean.sln -v quiet
|
||||
nuget install NUnit.Runners -Version 3.11.1 -OutputDirectory testrunner
|
||||
|
||||
- name: Build
|
||||
run: msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
|
||||
- name: Run Tests
|
||||
run: mono ./testrunner/NUnit.ConsoleRunner.3.11.1/tools/nunit3-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --where "cat != TravisExclude" --labels=Off --params:log-handler=ConsoleErrorLogHandler
|
||||
|
||||
- name: Generate & Publish python stubs
|
||||
run: |
|
||||
chmod +x ci_build_stubs.sh
|
||||
./ci_build_stubs.sh -d -t -g #Ignore Publish as of since credentials are missing on CI
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -144,6 +144,7 @@ $tf/
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding addin-in
|
||||
|
||||
4
.idea/workspace.xml
generated
4
.idea/workspace.xml
generated
@@ -3,7 +3,7 @@
|
||||
<component name="RunManager" selected="Python Debug Server.Debug in Container">
|
||||
<configuration name="Debug Local" type="PyRemoteDebugConfigurationType" factoryName="Python Remote Debug">
|
||||
<module name="LEAN" />
|
||||
<option name="PORT" value="5678" />
|
||||
<option name="PORT" value="6000" />
|
||||
<option name="HOST" value="localhost" />
|
||||
<PathMappingSettings>
|
||||
<option name="pathMappings">
|
||||
@@ -16,7 +16,7 @@
|
||||
</configuration>
|
||||
<configuration name="Debug in Container" type="PyRemoteDebugConfigurationType" factoryName="Python Remote Debug">
|
||||
<module name="LEAN" />
|
||||
<option name="PORT" value="5678" />
|
||||
<option name="PORT" value="6000" />
|
||||
<option name="HOST" value="localhost" />
|
||||
<PathMappingSettings>
|
||||
<option name="pathMappings">
|
||||
|
||||
@@ -5,7 +5,7 @@ mono:
|
||||
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
|
||||
- wget -q https://cdn.quantconnect.com/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh
|
||||
- bash Miniconda3-4.5.12-Linux-x86_64.sh -b
|
||||
- rm -rf Miniconda3-4.5.12-Linux-x86_64.sh
|
||||
- sudo ln -s $HOME/miniconda3/lib/libpython3.6m.so /usr/lib/libpython3.6m.so
|
||||
@@ -17,10 +17,10 @@ before_install:
|
||||
- conda install -y scipy=1.4.1
|
||||
- conda install -y wrapt=1.12.1
|
||||
install:
|
||||
- nuget restore QuantConnect.Lean.sln
|
||||
- nuget restore QuantConnect.Lean.sln -v quiet
|
||||
- nuget install NUnit.Runners -Version 3.11.1 -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
|
||||
- msbuild /p:Configuration=Release /p:VbcToolExe=vbnc.exe /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
- mono ./testrunner/NUnit.ConsoleRunner.3.11.1/tools/nunit3-console.exe ./Tests/bin/Release/QuantConnect.Tests.dll --where "cat != TravisExclude" --labels=Off --params:log-handler=ConsoleErrorLogHandler
|
||||
- chmod +x ci_build_stubs.sh
|
||||
- sudo -E ./ci_build_stubs.sh -d -t -g -p
|
||||
|
||||
15
.vscode/readme.md
vendored
15
.vscode/readme.md
vendored
@@ -13,7 +13,7 @@ Before anything we need to ensure a few things have been done:
|
||||
|
||||
|
||||
1. Get [Visual Studio Code](https://code.visualstudio.com/download)
|
||||
* Get the Extension [Mono Debug](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) for C# Debugging
|
||||
* Get the Extension [Mono Debug **15.8**](https://marketplace.visualstudio.com/items?itemName=ms-vscode.mono-debug) for C# Debugging
|
||||
* Get the Extension [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Python Debugging
|
||||
|
||||
2. Get [Docker](https://docs.docker.com/get-docker/):
|
||||
@@ -35,7 +35,8 @@ Before anything we need to ensure a few things have been done:
|
||||
* Download the repo or clone it using: _git clone[ https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
|
||||
* Open the folder using VS Code
|
||||
|
||||
|
||||
**NOTES**:
|
||||
- Mono Extension Version 16 and greater fails to debug the docker container remotely, please install **Version 15.8**. To install an older version from within VS Code go to the extensions tab, search "Mono Debug", and select "Install Another Version...".
|
||||
<br />
|
||||
|
||||
<h1>Develop Algorithms Locally, Run in Container</h1>
|
||||
@@ -112,6 +113,12 @@ In VS Code click on the debug/run icon on the left toolbar, at the top you shoul
|
||||
|
||||
As defaults these are all great! Feel free to change them as needed for your setup.
|
||||
|
||||
**NOTE:** VSCode may try and throw errors when launching this way regarding build on `QuantConnect.csx` and `Config.json` these errors can be ignored by selecting "*Debug Anyway*". To stop this error message in the future select "*Remember my choice in user settings*".
|
||||
|
||||
If using C# algorithms ensure that msbuild can build them successfully.
|
||||
|
||||
|
||||
|
||||
<br />
|
||||
|
||||
<h3>Option 2</h3>
|
||||
@@ -194,4 +201,6 @@ _Figure 2: Python Debugger Messages_
|
||||
<h1>Common Issues</h1>
|
||||
Here we will cover some common issues with setting this up. This section will expand as we get user feedback!
|
||||
|
||||
* Error messages about build in VSCode points to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.
|
||||
* Any error messages about building in VSCode that point to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.
|
||||
* `Errors exist after running preLaunchTask 'run-docker'`This VSCode error appears to warn you of CSharp errors when trying to use `Debug in Container` select "Debug Anyway" as the errors are false flags for JSON comments as well as `QuantConnect.csx` not finding references. Neither of these will impact your debugging.
|
||||
* `The container name "/LeanEngine" is already in use by container "****"` This Docker error implies that another instance of lean is already running under the container name /LeanEngine. If this error appears either use Docker Desktop to delete the container or use `docker kill LeanEngine` from the command line.
|
||||
28
.vscode/tasks.json
vendored
28
.vscode/tasks.json
vendored
@@ -20,6 +20,34 @@
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "rebuild",
|
||||
"type": "shell",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
"/p:Configuration=Debug",
|
||||
"/p:DebugType=portable",
|
||||
"/t:rebuild",
|
||||
],
|
||||
"group": "build",
|
||||
"presentation": {
|
||||
"reveal": "silent"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "clean",
|
||||
"type": "shell",
|
||||
"command": "msbuild",
|
||||
"args": [
|
||||
"/t:clean",
|
||||
],
|
||||
"group": "build",
|
||||
"presentation": {
|
||||
"reveal": "silent"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "force build linux",
|
||||
"type": "shell",
|
||||
|
||||
@@ -131,13 +131,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.92"},
|
||||
{"Alpha", "-0.023"},
|
||||
{"Beta", "0.005"},
|
||||
{"Alpha", "-0.021"},
|
||||
{"Beta", "-0.01"},
|
||||
{"Annual Standard Deviation", "0.006"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-3.424"},
|
||||
{"Tracking Error", "0.057"},
|
||||
{"Treynor Ratio", "-4.775"},
|
||||
{"Information Ratio", "-3.374"},
|
||||
{"Tracking Error", "0.058"},
|
||||
{"Treynor Ratio", "2.133"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
@@ -158,7 +158,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1185639451"}
|
||||
{"OrderListHash", "-262924291"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* 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.Brokerages;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Shortable;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests filtering in coarse selection by shortable quantity
|
||||
/// </summary>
|
||||
public class AllShortableSymbolsCoarseSelectionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private static readonly DateTime _20140325 = new DateTime(2014, 3, 25);
|
||||
private static readonly DateTime _20140326 = new DateTime(2014, 3, 26);
|
||||
private static readonly DateTime _20140327 = new DateTime(2014, 3, 27);
|
||||
private static readonly DateTime _20140328 = new DateTime(2014, 3, 28);
|
||||
private static readonly DateTime _20140329 = new DateTime(2014, 3, 29);
|
||||
|
||||
private static readonly Symbol _aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
private static readonly Symbol _bac = QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA);
|
||||
private static readonly Symbol _gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
|
||||
private static readonly Symbol _goog = QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA);
|
||||
private static readonly Symbol _qqq = QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA);
|
||||
private static readonly Symbol _spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
private DateTime _lastTradeDate;
|
||||
|
||||
private static readonly Dictionary<DateTime, bool> _coarseSelected = new Dictionary<DateTime, bool>
|
||||
{
|
||||
{ _20140325, false },
|
||||
{ _20140326, false },
|
||||
{ _20140327, false },
|
||||
{ _20140328, false },
|
||||
};
|
||||
|
||||
private static readonly Dictionary<DateTime, Symbol[]> _expectedSymbols = new Dictionary<DateTime, Symbol[]>
|
||||
{
|
||||
{ _20140325, new[]
|
||||
{
|
||||
_bac,
|
||||
_qqq,
|
||||
_spy
|
||||
}
|
||||
},
|
||||
{ _20140326, new[]
|
||||
{
|
||||
_spy
|
||||
}
|
||||
},
|
||||
{ _20140327, new[]
|
||||
{
|
||||
_aapl,
|
||||
_bac,
|
||||
_gme,
|
||||
_qqq,
|
||||
_spy,
|
||||
}
|
||||
},
|
||||
{ _20140328, new[]
|
||||
{
|
||||
_goog
|
||||
}
|
||||
},
|
||||
{ _20140329, new Symbol[0] }
|
||||
};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 3, 25);
|
||||
SetEndDate(2014, 3, 29);
|
||||
SetCash(10000000);
|
||||
|
||||
AddUniverse(CoarseSelection);
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
SetBrokerageModel(new AllShortableSymbolsRegressionAlgorithmBrokerageModel());
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Time.Date == _lastTradeDate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var symbol in ActiveSecurities.Keys)
|
||||
{
|
||||
if (!Portfolio.ContainsKey(symbol) || !Portfolio[symbol].Invested)
|
||||
{
|
||||
if (!Shortable(symbol))
|
||||
{
|
||||
throw new Exception($"Expected {symbol} to be shortable on {Time:yyyy-MM-dd}");
|
||||
}
|
||||
|
||||
// Buy at least once into all Symbols. Since daily data will always use
|
||||
// MOO orders, it makes the testing of liquidating buying into Symbols difficult.
|
||||
MarketOrder(symbol, -(decimal)ShortableQuantity(symbol));
|
||||
_lastTradeDate = Time.Date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<Symbol> CoarseSelection(IEnumerable<CoarseFundamental> coarse)
|
||||
{
|
||||
var shortableSymbols = AllShortableSymbols();
|
||||
var selectedSymbols = coarse
|
||||
.Select(x => x.Symbol)
|
||||
.Where(s => shortableSymbols.ContainsKey(s) && shortableSymbols[s] >= 500)
|
||||
.OrderBy(s => s)
|
||||
.ToList();
|
||||
|
||||
var expectedMissing = 0;
|
||||
if (Time.Date == _20140327)
|
||||
{
|
||||
var gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
|
||||
if (!shortableSymbols.ContainsKey(gme))
|
||||
{
|
||||
throw new Exception("Expected unmapped GME in shortable symbols list on 2014-03-27");
|
||||
}
|
||||
if (!coarse.Select(x => x.Symbol.Value).Contains("GME"))
|
||||
{
|
||||
throw new Exception("Expected mapped GME in coarse symbols on 2014-03-27");
|
||||
}
|
||||
|
||||
expectedMissing = 1;
|
||||
}
|
||||
|
||||
var missing = _expectedSymbols[Time.Date].Except(selectedSymbols).ToList();
|
||||
if (missing.Count != expectedMissing)
|
||||
{
|
||||
throw new Exception($"Expected Symbols selected on {Time.Date:yyyy-MM-dd} to match expected Symbols, but the following Symbols were missing: {string.Join(", ", missing.Select(s => s.ToString()))}");
|
||||
}
|
||||
|
||||
_coarseSelected[Time.Date] = true;
|
||||
return selectedSymbols;
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_coarseSelected.Values.All(x => x))
|
||||
{
|
||||
throw new AggregateException($"Expected coarse selection on all dates, but didn't run on: {string.Join(", ", _coarseSelected.Where(kvp => !kvp.Value).Select(kvp => kvp.Key.ToStringInvariant("yyyy-MM-dd")))}");
|
||||
}
|
||||
}
|
||||
|
||||
private class AllShortableSymbolsRegressionAlgorithmBrokerageModel : DefaultBrokerageModel
|
||||
{
|
||||
public AllShortableSymbolsRegressionAlgorithmBrokerageModel() : base()
|
||||
{
|
||||
ShortableProvider = new RegressionTestShortableProvider();
|
||||
}
|
||||
}
|
||||
|
||||
private class RegressionTestShortableProvider : LocalDiskShortableProvider
|
||||
{
|
||||
public RegressionTestShortableProvider() : base(SecurityType.Equity, "testbrokerage", Market.USA)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "5"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "36.294%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.340%"},
|
||||
{"Sharpe Ratio", "21.2"},
|
||||
{"Probabilistic Sharpe Ratio", "99.990%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.274"},
|
||||
{"Beta", "0.138"},
|
||||
{"Annual Standard Deviation", "0.011"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "7.202"},
|
||||
{"Tracking Error", "0.068"},
|
||||
{"Treynor Ratio", "1.722"},
|
||||
{"Total Fees", "$307.50"},
|
||||
{"Fitness Score", "0.173"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.173"},
|
||||
{"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", "97613274"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,27 @@ using QuantConnect.Indicators;
|
||||
using QuantConnect.Orders.Fees;
|
||||
using QuantConnect.Data.Custom;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Risk;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
{
|
||||
/// <summary>
|
||||
/// This Alpha Model uses Wells Fargo 30-year Fixed Rate Mortgage data from Quandl to
|
||||
/// generate Insights about the movement of Real Estate ETFs. Mortgage rates can provide information
|
||||
/// regarding the general price trend of real estate, and ETFs provide good continuous-time instruments
|
||||
/// to measure the impact against. Volatility in mortgage rates tends to put downward pressure on real
|
||||
/// estate prices, whereas stable mortgage rates, regardless of true rate, lead to stable or higher real
|
||||
/// estate prices. This Alpha model seeks to take advantage of this correlation by emitting insights
|
||||
/// based on volatility and rate deviation from its historic mean.
|
||||
|
||||
/// This alpha is part of the Benchmark Alpha Series created by QuantConnect which are open
|
||||
///<summary>
|
||||
/// This Alpha Model uses Wells Fargo 30-year Fixed Rate Mortgage data from Quandl to
|
||||
/// generate Insights about the movement of Real Estate ETFs. Mortgage rates can provide information
|
||||
/// regarding the general price trend of real estate, and ETFs provide good continuous-time instruments
|
||||
/// to measure the impact against. Volatility in mortgage rates tends to put downward pressure on real
|
||||
/// estate prices, whereas stable mortgage rates, regardless of true rate, lead to stable or higher real
|
||||
/// estate prices. This Alpha model seeks to take advantage of this correlation by emitting insights
|
||||
/// based on volatility and rate deviation from its historic mean.
|
||||
///
|
||||
/// This alpha is part of the Benchmark Alpha Series created by QuantConnect which are open
|
||||
/// sourced so the community and client funds can see an example of an alpha.
|
||||
/// <summary>
|
||||
public class MortgageRateVolatilityAlgorithm : QCAlgorithmFramework
|
||||
///</summary>
|
||||
public class MortgageRateVolatilityAlgorithm : QCAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -51,8 +50,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetSecurityInitializer(security => security.FeeModel = new ConstantFeeModel(0));
|
||||
|
||||
// Basket of 6 liquid real estate ETFs
|
||||
Func<string, Symbol> ToSymbol = x => QuantConnect.Symbol.Create(x, SecurityType.Equity, Market.USA);
|
||||
var realEstateETFs = new[] { "VNQ", "REET", "TAO", "FREL", "SRET", "HIPS" }.Select(ToSymbol).ToArray();
|
||||
Func<string, Symbol> toSymbol = x => QuantConnect.Symbol.Create(x, SecurityType.Equity, Market.USA);
|
||||
var realEstateETFs = new[] { "VNQ", "REET", "TAO", "FREL", "SRET", "HIPS" }.Select(toSymbol).ToArray();
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(realEstateETFs));
|
||||
|
||||
SetAlpha(new MortgageRateVolatilityAlphaModel(this));
|
||||
@@ -64,8 +63,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetRiskManagement(new NullRiskManagementModel());
|
||||
|
||||
}
|
||||
|
||||
public void OnData(QuandlMortgagePriceColumns data) { }
|
||||
|
||||
private class MortgageRateVolatilityAlphaModel : AlphaModel
|
||||
{
|
||||
@@ -79,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
private readonly StandardDeviation _mortgageRateStd;
|
||||
|
||||
public MortgageRateVolatilityAlphaModel(
|
||||
QCAlgorithmFramework algorithm,
|
||||
QCAlgorithm algorithm,
|
||||
int indicatorPeriod = 15,
|
||||
double insightMagnitude = 0.0005,
|
||||
int deviations = 2,
|
||||
@@ -102,7 +99,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
WarmUpIndicators(algorithm);
|
||||
}
|
||||
|
||||
public override IEnumerable<Insight> Update(QCAlgorithmFramework algorithm, Slice data)
|
||||
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
|
||||
{
|
||||
var insights = new List<Insight>();
|
||||
|
||||
@@ -141,7 +138,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
return insights;
|
||||
}
|
||||
|
||||
private void WarmUpIndicators(QCAlgorithmFramework algorithm)
|
||||
private void WarmUpIndicators(QCAlgorithm algorithm)
|
||||
{
|
||||
// Make a history call and update the indicators
|
||||
algorithm.History(new[] { _mortgageRate }, _indicatorPeriod, _resolution).PushThrough(bar =>
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm to test the behaviour of ARMA versus AR models at the same order of differencing.
|
||||
/// In particular, an ARIMA(1,1,1) and ARIMA(1,1,0) are instantiated while orders are placed if their difference
|
||||
/// is sufficiently large (which would be due to the inclusion of the MA(1) term).
|
||||
/// </summary>
|
||||
public class AutoRegressiveIntegratedMovingAverageRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private AutoRegressiveIntegratedMovingAverage _arima;
|
||||
private AutoRegressiveIntegratedMovingAverage _ar;
|
||||
private decimal _last;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 1, 07);
|
||||
SetEndDate(2013, 12, 11);
|
||||
|
||||
EnableAutomaticIndicatorWarmUp = true;
|
||||
AddEquity("SPY", Resolution.Daily);
|
||||
_arima = ARIMA("SPY", 1, 1, 1, 50);
|
||||
_ar = ARIMA("SPY", 1, 1, 0, 50);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (_arima.IsReady)
|
||||
{
|
||||
if (Math.Abs(_ar.Current.Value - _arima.Current.Value) > 1) // Difference due to MA(1) being included.
|
||||
{
|
||||
if (_arima.Current.Value > _last)
|
||||
{
|
||||
MarketOrder("SPY", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
MarketOrder("SPY", -1);
|
||||
}
|
||||
}
|
||||
|
||||
_last = _arima.Current.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "65"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "0.145%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "2.190"},
|
||||
{"Net Profit", "0.134%"},
|
||||
{"Sharpe Ratio", "0.993"},
|
||||
{"Probabilistic Sharpe Ratio", "49.669%"},
|
||||
{"Loss Rate", "29%"},
|
||||
{"Win Rate", "71%"},
|
||||
{"Profit-Loss Ratio", "3.50"},
|
||||
{"Alpha", "0.001"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.168"},
|
||||
{"Tracking Error", "0.099"},
|
||||
{"Treynor Ratio", "-5.187"},
|
||||
{"Total Fees", "$65.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "1.51"},
|
||||
{"Return Over Maximum Drawdown", "1.819"},
|
||||
{"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", "852801548"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -303,21 +303,39 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "0.400%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.323%"},
|
||||
{"Sharpe Ratio", "-0.888"},
|
||||
{"Sharpe Ratio", "-11.098"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.035"},
|
||||
{"Beta", "0.183"},
|
||||
{"Annual Standard Deviation", "0.004"},
|
||||
{"Alpha", "-0.002"},
|
||||
{"Beta", "0.099"},
|
||||
{"Annual Standard Deviation", "0.002"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "12.058"},
|
||||
{"Tracking Error", "0.017"},
|
||||
{"Treynor Ratio", "-0.018"},
|
||||
{"Information Ratio", "9.899"},
|
||||
{"Tracking Error", "0.019"},
|
||||
{"Treynor Ratio", "-0.23"},
|
||||
{"Total Fees", "$2.00"},
|
||||
{"Fitness Score", "0.213"},
|
||||
{"OrderListHash", "904167951"}
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-73.456"},
|
||||
{"Portfolio Turnover", "0.426"},
|
||||
{"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", "-1990039314"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -102,7 +102,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
@@ -141,7 +141,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "687310345"}
|
||||
{"OrderListHash", "-91832511"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$4.00"},
|
||||
{"Total Fees", "$3.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0.327"},
|
||||
{"Kelly Criterion Probability Value", "1"},
|
||||
@@ -180,7 +180,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "50.0482%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "352959406"}
|
||||
{"OrderListHash", "-695205588"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Custom.CBOE;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests the consolidation of custom data with random data
|
||||
/// </summary>
|
||||
public class CBOECustomDataConsolidationRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _vix;
|
||||
private BollingerBands _bb;
|
||||
private bool _invested;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the algorithm with fake VIX data
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 7);
|
||||
SetEndDate(2013, 10, 11);
|
||||
SetCash(100000);
|
||||
|
||||
_vix = AddData<IncrementallyGeneratedCustomData>("VIX", Resolution.Daily).Symbol;
|
||||
_bb = BB(_vix, 30, 2, MovingAverageType.Simple, Resolution.Daily);
|
||||
}
|
||||
|
||||
/// <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 (_bb.Current.Value == 0)
|
||||
{
|
||||
throw new Exception("Bollinger Band value is zero when we expect non-zero value.");
|
||||
}
|
||||
|
||||
if (!_invested && _bb.Current.Value > 0.05m)
|
||||
{
|
||||
MarketOrder(_vix, 1);
|
||||
_invested = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Incrementally updating data
|
||||
/// </summary>
|
||||
private class IncrementallyGeneratedCustomData : CBOE
|
||||
{
|
||||
private const decimal _start = 10.01m;
|
||||
private static decimal _step;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the source of the subscription. In this case, we set it to existing
|
||||
/// equity data so that we can pass fake data from Reader
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="date">Date we're making this request</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>Source of subscription</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource(Path.Combine(Globals.DataFolder, "equity", "usa", "minute", "spy", $"{date:yyyyMMdd}_trade.zip#{date:yyyyMMdd}_spy_minute_trade.csv"), SubscriptionTransportMedium.LocalFile, FileFormat.Csv);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the data, which in this case is fake incremental data
|
||||
/// </summary>
|
||||
/// <param name="config">Subscription configuration</param>
|
||||
/// <param name="line">Line of data</param>
|
||||
/// <param name="date">Date of the request</param>
|
||||
/// <param name="isLiveMode">Is live mode</param>
|
||||
/// <returns>Incremental BaseData instance</returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var vix = new CBOE();
|
||||
_step += 0.10m;
|
||||
var open = _start + _step;
|
||||
var close = _start + _step + 0.02m;
|
||||
var high = close;
|
||||
var low = open;
|
||||
|
||||
return new IncrementallyGeneratedCustomData
|
||||
{
|
||||
Open = open,
|
||||
High = high,
|
||||
Low = low,
|
||||
Close = close,
|
||||
Time = date,
|
||||
Symbol = new Symbol(
|
||||
SecurityIdentifier.GenerateBase(typeof(IncrementallyGeneratedCustomData), "VIX", Market.USA, false),
|
||||
"VIX"),
|
||||
Period = vix.Period,
|
||||
DataType = vix.DataType
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <remarks>
|
||||
/// Unable to be tested in Python, due to pythonnet not supporting overriding of methods from Python
|
||||
/// </remarks>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0.029%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.000%"},
|
||||
{"Sharpe Ratio", "28.4"},
|
||||
{"Probabilistic Sharpe Ratio", "88.597%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-7.067"},
|
||||
{"Tracking Error", "0.193"},
|
||||
{"Treynor Ratio", "7.887"},
|
||||
{"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", "349101050"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Annual Variance", "0.027"},
|
||||
{"Information Ratio", "-0.391"},
|
||||
{"Tracking Error", "0.239"},
|
||||
{"Treynor Ratio", "-1.416"},
|
||||
{"Treynor Ratio", "-1.435"},
|
||||
{"Total Fees", "$755.29"},
|
||||
{"Fitness Score", "0.024"},
|
||||
{"Kelly Criterion Estimate", "-0.84"},
|
||||
|
||||
@@ -38,6 +38,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Find more symbols here: http://quantconnect.com/data
|
||||
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second);
|
||||
|
||||
// Disabling the benchmark / setting to a fixed value
|
||||
// SetBenchmark(time => 0);
|
||||
|
||||
// Set the benchmark to AAPL US Equity
|
||||
SetBenchmark("AAPL");
|
||||
}
|
||||
|
||||
|
||||
260
Algorithm.CSharp/CustomDataPropertiesRegressionAlgorithm.cs
Normal file
260
Algorithm.CSharp/CustomDataPropertiesRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* 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.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression test to demonstrate setting custom Symbol Properties and Market Hours for a custom data import
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="custom data" />
|
||||
/// <meta name="tag" content="crypto" />
|
||||
/// <meta name="tag" content="regression test" />
|
||||
public class CustomDataPropertiesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private string _ticker = "BTC";
|
||||
private Security _bitcoin;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2011, 9, 13);
|
||||
SetEndDate(2015, 12, 01);
|
||||
|
||||
//Set the cash for the strategy:
|
||||
SetCash(100000);
|
||||
|
||||
// Define our custom data properties and exchange hours
|
||||
var properties = new SymbolProperties("Bitcoin", "USD", 1, 0.01m, 0.01m, _ticker);
|
||||
var exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork);
|
||||
|
||||
// Add the custom data to our algorithm with our custom properties and exchange hours
|
||||
_bitcoin = AddData<Bitcoin>(_ticker, properties, exchangeHours);
|
||||
|
||||
//Verify our symbol properties were changed and loaded into this security
|
||||
if (_bitcoin.SymbolProperties != properties)
|
||||
{
|
||||
throw new Exception("Failed to set and retrieve custom SymbolProperties for BTC");
|
||||
}
|
||||
|
||||
//Verify our exchange hours were changed and loaded into this security
|
||||
if (_bitcoin.Exchange.Hours != exchangeHours)
|
||||
{
|
||||
throw new Exception("Failed to set and retrieve custom ExchangeHours for BTC");
|
||||
}
|
||||
|
||||
// For regression purposes on AddData overloads, this call is simply to ensure Lean can accept this
|
||||
// with default params and is not routed to a breaking function.
|
||||
AddData<Bitcoin>("BTCUSD");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event Handler for Bitcoin Data Events: These Bitcoin objects are created from our
|
||||
/// "Bitcoin" type below and fired into this event handler.
|
||||
/// </summary>
|
||||
/// <param name="data">One(1) Bitcoin Object, streamed into our algorithm synchronized in time with our other data streams</param>
|
||||
public void OnData(Bitcoin data)
|
||||
{
|
||||
//If we don't have any bitcoin "SHARES" -- invest"
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
//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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
// Reset our Symbol property value, for testing purposes.
|
||||
SymbolPropertiesDatabase.SetEntry(Market.USA, MarketHoursDatabase.GetDatabaseSymbolKey(_bitcoin.Symbol), SecurityType.Base,
|
||||
SymbolProperties.GetDefault("USD"));
|
||||
}
|
||||
|
||||
/// <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", "155.262%"},
|
||||
{"Drawdown", "84.800%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "5123.242%"},
|
||||
{"Sharpe Ratio", "2.067"},
|
||||
{"Probabilistic Sharpe Ratio", "68.833%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "1.732"},
|
||||
{"Beta", "0.037"},
|
||||
{"Annual Standard Deviation", "0.841"},
|
||||
{"Annual Variance", "0.707"},
|
||||
{"Information Ratio", "1.902"},
|
||||
{"Tracking Error", "0.848"},
|
||||
{"Treynor Ratio", "46.992"},
|
||||
{"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", "508036553"}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Custom Data Type: Bitcoin data from Quandl - http://www.quandl.com/help/api-for-bitcoin-data
|
||||
/// </summary>
|
||||
public class Bitcoin : BaseData
|
||||
{
|
||||
[JsonProperty("timestamp")]
|
||||
public int Timestamp = 0;
|
||||
[JsonProperty("open")]
|
||||
public decimal Open = 0;
|
||||
[JsonProperty("high")]
|
||||
public decimal High = 0;
|
||||
[JsonProperty("low")]
|
||||
public decimal Low = 0;
|
||||
[JsonProperty("last")]
|
||||
public decimal Close = 0;
|
||||
[JsonProperty("bid")]
|
||||
public decimal Bid = 0;
|
||||
[JsonProperty("ask")]
|
||||
public decimal Ask = 0;
|
||||
[JsonProperty("vwap")]
|
||||
public decimal WeightedPrice = 0;
|
||||
[JsonProperty("volume")]
|
||||
public decimal VolumeBTC = 0;
|
||||
public decimal VolumeUSD = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 1. DEFAULT CONSTRUCTOR: Custom data types need a default constructor.
|
||||
/// We search for a default constructor so please provide one here. It won't be used for data, just to generate the "Factory".
|
||||
/// </summary>
|
||||
public Bitcoin()
|
||||
{
|
||||
Symbol = "BTC";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 2. RETURN THE STRING URL SOURCE LOCATION FOR YOUR DATA:
|
||||
/// This is a powerful and dynamic select source file method. If you have a large dataset, 10+mb we recommend you break it into smaller files. E.g. One zip per year.
|
||||
/// We can accept raw text or ZIP files. We read the file extension to determine if it is a zip file.
|
||||
/// </summary>
|
||||
/// <param name="config">Configuration object</param>
|
||||
/// <param name="date">Date of this source file</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>String URL of source file.</returns>
|
||||
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
|
||||
{
|
||||
if (isLiveMode)
|
||||
{
|
||||
return new SubscriptionDataSource("https://www.bitstamp.net/api/ticker/", SubscriptionTransportMedium.Rest);
|
||||
}
|
||||
|
||||
//return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip";
|
||||
// OR simply return a fixed small data file. Large files will slow down your backtest
|
||||
return new SubscriptionDataSource("https://www.quantconnect.com/api/v2/proxy/quandl/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc&api_key=WyAazVXnq7ATy_fefTqm", SubscriptionTransportMedium.RemoteFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 3. READER METHOD: Read 1 line from data source and convert it into Object.
|
||||
/// Each line of the CSV File is presented in here. The backend downloads your file, loads it into memory and then line by line
|
||||
/// feeds it into your algorithm
|
||||
/// </summary>
|
||||
/// <param name="line">string line from the data source file submitted above</param>
|
||||
/// <param name="config">Subscription data, symbol name, data type</param>
|
||||
/// <param name="date">Current date we're requesting. This allows you to break up the data source into daily files.</param>
|
||||
/// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
|
||||
/// <returns>New Bitcoin Object which extends BaseData.</returns>
|
||||
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
|
||||
{
|
||||
var coin = new Bitcoin();
|
||||
if (isLiveMode)
|
||||
{
|
||||
//Example Line Format:
|
||||
//{"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"}
|
||||
try
|
||||
{
|
||||
coin = JsonConvert.DeserializeObject<Bitcoin>(line);
|
||||
coin.EndTime = DateTime.UtcNow.ConvertFromUtc(config.ExchangeTimeZone);
|
||||
coin.Value = coin.Close;
|
||||
}
|
||||
catch { /* Do nothing, possible error in json decoding */ }
|
||||
return coin;
|
||||
}
|
||||
|
||||
//Example Line Format:
|
||||
//Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price
|
||||
//2011-09-13 5.8 6.0 5.65 5.97 58.37138238, 346.0973893944 5.929230648356
|
||||
try
|
||||
{
|
||||
string[] data = line.Split(',');
|
||||
coin.Time = DateTime.Parse(data[0], CultureInfo.InvariantCulture);
|
||||
coin.Open = Convert.ToDecimal(data[1], CultureInfo.InvariantCulture);
|
||||
coin.High = Convert.ToDecimal(data[2], CultureInfo.InvariantCulture);
|
||||
coin.Low = Convert.ToDecimal(data[3], CultureInfo.InvariantCulture);
|
||||
coin.Close = Convert.ToDecimal(data[4], CultureInfo.InvariantCulture);
|
||||
coin.VolumeBTC = Convert.ToDecimal(data[5], CultureInfo.InvariantCulture);
|
||||
coin.VolumeUSD = Convert.ToDecimal(data[6], CultureInfo.InvariantCulture);
|
||||
coin.WeightedPrice = Convert.ToDecimal(data[7], CultureInfo.InvariantCulture);
|
||||
coin.Value = coin.Close;
|
||||
}
|
||||
catch { /* Do nothing, skip first title row */ }
|
||||
|
||||
return coin;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,25 +100,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "1.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.634%"},
|
||||
{"Sharpe Ratio", "2.476"},
|
||||
{"Probabilistic Sharpe Ratio", "92.194%"},
|
||||
{"Sharpe Ratio", "2.495"},
|
||||
{"Probabilistic Sharpe Ratio", "92.298%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.006"},
|
||||
{"Beta", "0.158"},
|
||||
{"Annual Standard Deviation", "0.032"},
|
||||
{"Annual Standard Deviation", "0.033"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "-4.89"},
|
||||
{"Information Ratio", "-4.942"},
|
||||
{"Tracking Error", "0.08"},
|
||||
{"Treynor Ratio", "0.509"},
|
||||
{"Treynor Ratio", "0.517"},
|
||||
{"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"},
|
||||
{"Portfolio Turnover", "0.023"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -132,7 +132,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1252326142"}
|
||||
{"OrderListHash", "528208939"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2007, 05, 25); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
// Find more symbols here: http://quantconnect.com/data
|
||||
AddSecurity(SecurityType.Equity, "AAA", Resolution.Daily);
|
||||
AddSecurity(SecurityType.Equity, "AAA.1", Resolution.Daily);
|
||||
AddSecurity(SecurityType.Equity, "SPY", Resolution.Daily);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
_dataCount += data.Bars.Count;
|
||||
if (Transactions.OrdersCount == 0)
|
||||
{
|
||||
SetHoldings("AAA", 1);
|
||||
SetHoldings("AAA.1", 1);
|
||||
Debug("Purchased Stock");
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
// the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting
|
||||
|
||||
var aaa = Securities["AAA"];
|
||||
var aaa = Securities["AAA.1"];
|
||||
if (aaa.IsDelisted && aaa.IsTradable)
|
||||
{
|
||||
throw new Exception("Delisted security must NOT be tradable");
|
||||
@@ -179,7 +179,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-2022527947"}
|
||||
{"OrderListHash", "-335704027"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
148
Algorithm.CSharp/DelistingFutureOptionRegressionAlgorithm.cs
Normal file
148
Algorithm.CSharp/DelistingFutureOptionRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing issue #5160 where delisting order would be cancelled because it was placed at the market close on the delisting day
|
||||
/// </summary>
|
||||
public class DelistingFutureOptionRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private bool _traded;
|
||||
private int _lastMonth;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2012, 1, 1);
|
||||
SetEndDate(2013, 1, 1);
|
||||
SetCash(10000000);
|
||||
|
||||
var dc = AddFuture(Futures.Dairy.ClassIIIMilk, Resolution.Minute, Market.CME);
|
||||
dc.SetFilter(1, 120);
|
||||
|
||||
AddFutureOption(dc.Symbol, universe => universe.Strikes(-2, 2));
|
||||
_lastMonth = -1;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (Time.Month != _lastMonth)
|
||||
{
|
||||
_lastMonth = Time.Month;
|
||||
var investedSymbols = Securities.Values
|
||||
.Where(security => security.Invested)
|
||||
.Select(security => security.Symbol)
|
||||
.ToList();
|
||||
|
||||
var delistedSecurity = investedSymbols.Where(symbol => symbol.ID.Date.AddDays(1) < Time).ToList();
|
||||
if (delistedSecurity.Count > 0)
|
||||
{
|
||||
throw new Exception($"[{UtcTime}] We hold a delisted securities: {string.Join(",", delistedSecurity)}");
|
||||
}
|
||||
Log($"Holdings({Time}): {string.Join(",", investedSymbols)}");
|
||||
}
|
||||
|
||||
if (Portfolio.Invested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var chain in data.OptionChains.Values)
|
||||
{
|
||||
foreach (var contractsValue in chain.Contracts.Values)
|
||||
{
|
||||
MarketOrder(contractsValue.Symbol, 1);
|
||||
_traded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_traded)
|
||||
{
|
||||
throw new Exception("We expected some FOP trading to happen");
|
||||
}
|
||||
if (Portfolio.Invested)
|
||||
{
|
||||
throw new Exception("We shouldn't be invested anymore");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "16"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-0.111%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-0.679"},
|
||||
{"Net Profit", "-0.112%"},
|
||||
{"Sharpe Ratio", "-1.052"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "80%"},
|
||||
{"Win Rate", "20%"},
|
||||
{"Profit-Loss Ratio", "0.61"},
|
||||
{"Alpha", "-0.001"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.001"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.187"},
|
||||
{"Tracking Error", "0.115"},
|
||||
{"Treynor Ratio", "1.545"},
|
||||
{"Total Fees", "$37.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.128"},
|
||||
{"Return Over Maximum Drawdown", "-0.995"},
|
||||
{"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", "657651179"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -85,11 +85,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-0.500%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Average Loss", "-0.12%"},
|
||||
{"Compounding Annual Return", "-9.062%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.006%"},
|
||||
{"Net Profit", "-0.121%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
@@ -103,12 +103,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0.22"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$6.41"},
|
||||
{"Fitness Score", "0.248"},
|
||||
{"Fitness Score", "0.249"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-82.815"},
|
||||
{"Portfolio Turnover", "0.497"},
|
||||
{"Return Over Maximum Drawdown", "-79.031"},
|
||||
{"Portfolio Turnover", "0.498"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -122,7 +122,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1213851303"}
|
||||
{"OrderListHash", "-1760998125"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression test algorithm simply fetch and compare data of minute resolution around daylight saving period
|
||||
/// reproduces issue reported in GB issue GH issue https://github.com/QuantConnect/Lean/issues/4925
|
||||
/// related issues https://github.com/QuantConnect/Lean/issues/3707; https://github.com/QuantConnect/Lean/issues/4630
|
||||
/// </summary>
|
||||
public class FillForwardEnumeratorOutOfOrderBarRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private decimal _exptectedClose = 84.09m;
|
||||
private DateTime _exptectedTime = new DateTime(2008, 3, 10, 9, 30, 0);
|
||||
private Symbol _shy;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2008, 3, 7);
|
||||
SetEndDate(2008, 3, 10);
|
||||
_shy = AddEquity("SHY", Resolution.Minute).Symbol;
|
||||
// just to make debugging easier, less subscriptions
|
||||
SetBenchmark(time => 1);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var trackingBar = slice.Bars.Values.FirstOrDefault(s => s.Time.Equals(_exptectedTime));
|
||||
|
||||
if (trackingBar != null)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_shy, 1);
|
||||
}
|
||||
|
||||
if (trackingBar.Close != _exptectedClose)
|
||||
{
|
||||
throw new Exception(
|
||||
$"Bar at {_exptectedTime.ToStringInvariant()} closed at price {trackingBar.Close.ToStringInvariant()}; expected {_exptectedClose.ToStringInvariant()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$5.93"},
|
||||
{"Fitness Score", "0.499"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-105.726"},
|
||||
{"Portfolio Turnover", "0.998"},
|
||||
{"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", "-850144190"}
|
||||
};
|
||||
}
|
||||
}
|
||||
169
Algorithm.CSharp/FillForwardUntilExpiryRegressionAlgorithm.cs
Normal file
169
Algorithm.CSharp/FillForwardUntilExpiryRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities.Option;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm checks FillForwardEnumerator should FF the data until it reaches the delisting date
|
||||
/// replicates GH issue https://github.com/QuantConnect/Lean/issues/4872
|
||||
/// </summary>
|
||||
public class FillForwardUntilExpiryRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private DateTime _realEndDate = new DateTime(2014, 06, 07);
|
||||
private SecurityExchange _exchange;
|
||||
private Dictionary<Symbol, HashSet<DateTime>> _options;
|
||||
|
||||
private string[] _contracts =
|
||||
{
|
||||
"TWX 140621P00067500",
|
||||
"TWX 140621C00067500",
|
||||
"TWX 140621C00070000",
|
||||
"TWX 140621P00070000"
|
||||
};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 06, 05);
|
||||
SetEndDate(2014, 06, 30);
|
||||
|
||||
_options = new Dictionary<Symbol, HashSet<DateTime>>();
|
||||
var _twxOption = AddOption("TWX", Resolution.Minute);
|
||||
_exchange = _twxOption.Exchange;
|
||||
_twxOption.SetFilter((x) => x
|
||||
.Contracts(c => c.Where(s => _contracts.Contains(s.Value))));
|
||||
SetBenchmark(t => 1);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var value in data.OptionChains.Values)
|
||||
{
|
||||
foreach (var contact in value.Contracts)
|
||||
{
|
||||
BaseData bar = null;
|
||||
QuoteBar quoteBar;
|
||||
if (bar == null && value.QuoteBars.TryGetValue(contact.Key, out quoteBar))
|
||||
{
|
||||
bar = quoteBar;
|
||||
}
|
||||
TradeBar tradeBar;
|
||||
if (bar == null && value.TradeBars.TryGetValue(contact.Key, out tradeBar))
|
||||
{
|
||||
bar = tradeBar;
|
||||
}
|
||||
if (bar.IsFillForward)
|
||||
{
|
||||
_options[contact.Key].Add(value.Time.Date);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var security in changes.AddedSecurities.OfType<Option>())
|
||||
{
|
||||
_options.Add(security.Symbol, new HashSet<DateTime>());
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_options.Count != _contracts.Length)
|
||||
{
|
||||
throw new Exception($"Options weren't setup properly. Expected: {_contracts.Length}");
|
||||
}
|
||||
|
||||
foreach (var option in _options)
|
||||
{
|
||||
for (DateTime date = _realEndDate; date < option.Key.ID.Date; date = date.AddDays(1))
|
||||
{
|
||||
if (_exchange.Hours.IsDateOpen(date) &&
|
||||
!option.Value.Contains(date))
|
||||
{
|
||||
throw new Exception("Delisted security should be FF until expiry 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", "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"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -92,12 +92,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.093"},
|
||||
{"Beta", "-0.1"},
|
||||
{"Beta", "-0.099"},
|
||||
{"Annual Standard Deviation", "0.18"},
|
||||
{"Annual Variance", "0.032"},
|
||||
{"Information Ratio", "-0.001"},
|
||||
{"Tracking Error", "0.267"},
|
||||
{"Treynor Ratio", "-0.846"},
|
||||
{"Treynor Ratio", "-0.847"},
|
||||
{"Total Fees", "$41.17"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "38.884"},
|
||||
|
||||
@@ -43,11 +43,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
var es20h20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -124,31 +119,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "2.94%"},
|
||||
{"Average Win", "2.93%"},
|
||||
{"Average Loss", "-4.15%"},
|
||||
{"Compounding Annual Return", "-5.601%"},
|
||||
{"Drawdown", "5.600%"},
|
||||
{"Expectancy", "-0.146"},
|
||||
{"Net Profit", "-2.771%"},
|
||||
{"Sharpe Ratio", "-0.49"},
|
||||
{"Probabilistic Sharpe Ratio", "10.583%"},
|
||||
{"Compounding Annual Return", "-6.023%"},
|
||||
{"Drawdown", "5.700%"},
|
||||
{"Expectancy", "-0.148"},
|
||||
{"Net Profit", "-2.802%"},
|
||||
{"Sharpe Ratio", "-0.501"},
|
||||
{"Probabilistic Sharpe Ratio", "10.679%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.71"},
|
||||
{"Alpha", "-0.043"},
|
||||
{"Profit-Loss Ratio", "0.70"},
|
||||
{"Alpha", "-0.045"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.087"},
|
||||
{"Annual Standard Deviation", "0.089"},
|
||||
{"Annual Variance", "0.008"},
|
||||
{"Information Ratio", "0.96"},
|
||||
{"Tracking Error", "0.192"},
|
||||
{"Treynor Ratio", "58.394"},
|
||||
{"Information Ratio", "0.966"},
|
||||
{"Tracking Error", "0.195"},
|
||||
{"Treynor Ratio", "55.977"},
|
||||
{"Total Fees", "$14.80"},
|
||||
{"Fitness Score", "0.018"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.096"},
|
||||
{"Return Over Maximum Drawdown", "-0.993"},
|
||||
{"Portfolio Turnover", "0.043"},
|
||||
{"Sortino Ratio", "-0.103"},
|
||||
{"Return Over Maximum Drawdown", "-1.063"},
|
||||
{"Portfolio Turnover", "0.045"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -162,7 +157,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-290004562"}
|
||||
{"OrderListHash", "79413316"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
@@ -46,11 +45,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -132,12 +126,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
private void AssertFutureOptionOrderExercise(OrderEvent orderEvent, Security future, Security optionContract)
|
||||
{
|
||||
// We expect the liquidation to occur on the day of the delisting (while the market is open),
|
||||
// but currently we liquidate at the next market open (AAPL open) which happens to be
|
||||
// at 9:30:00 Eastern Time. For unknown reasons, the delisting happens two minutes after the
|
||||
// market open.
|
||||
// Read more about the issue affecting this test here: https://github.com/QuantConnect/Lean/issues/4980
|
||||
var expectedLiquidationTimeUtc = new DateTime(2020, 6, 22, 13, 32, 0);
|
||||
var expectedLiquidationTimeUtc = new DateTime(2020, 6, 19, 20, 0, 0);
|
||||
|
||||
if (orderEvent.Direction == OrderDirection.Sell && future.Holdings.Quantity != 0)
|
||||
{
|
||||
@@ -214,31 +203,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "1.25%"},
|
||||
{"Average Win", "1.22%"},
|
||||
{"Average Loss", "-7.42%"},
|
||||
{"Compounding Annual Return", "-12.413%"},
|
||||
{"Compounding Annual Return", "-13.222%"},
|
||||
{"Drawdown", "6.300%"},
|
||||
{"Expectancy", "-0.416"},
|
||||
{"Net Profit", "-6.257%"},
|
||||
{"Sharpe Ratio", "-1.325"},
|
||||
{"Probabilistic Sharpe Ratio", "0.004%"},
|
||||
{"Expectancy", "-0.417"},
|
||||
{"Net Profit", "-6.282%"},
|
||||
{"Sharpe Ratio", "-1.345"},
|
||||
{"Probabilistic Sharpe Ratio", "0.005%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.17"},
|
||||
{"Alpha", "-0.102"},
|
||||
{"Alpha", "-0.105"},
|
||||
{"Beta", "-0.003"},
|
||||
{"Annual Standard Deviation", "0.076"},
|
||||
{"Annual Standard Deviation", "0.078"},
|
||||
{"Annual Variance", "0.006"},
|
||||
{"Information Ratio", "0.673"},
|
||||
{"Tracking Error", "0.188"},
|
||||
{"Treynor Ratio", "33.559"},
|
||||
{"Information Ratio", "0.678"},
|
||||
{"Tracking Error", "0.191"},
|
||||
{"Treynor Ratio", "33.18"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.008"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.205"},
|
||||
{"Return Over Maximum Drawdown", "-1.983"},
|
||||
{"Portfolio Turnover", "0.023"},
|
||||
{"Sortino Ratio", "-0.217"},
|
||||
{"Return Over Maximum Drawdown", "-2.105"},
|
||||
{"Portfolio Turnover", "0.024"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -252,7 +241,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "23301049"}
|
||||
{"OrderListHash", "-1947859887"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -166,31 +161,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "28.04%"},
|
||||
{"Average Win", "27.44%"},
|
||||
{"Average Loss", "-62.81%"},
|
||||
{"Compounding Annual Return", "-78.165%"},
|
||||
{"Drawdown", "52.400%"},
|
||||
{"Expectancy", "-0.277"},
|
||||
{"Net Profit", "-52.379%"},
|
||||
{"Sharpe Ratio", "-0.865"},
|
||||
{"Probabilistic Sharpe Ratio", "0.019%"},
|
||||
{"Compounding Annual Return", "-80.444%"},
|
||||
{"Drawdown", "52.600%"},
|
||||
{"Expectancy", "-0.282"},
|
||||
{"Net Profit", "-52.604%"},
|
||||
{"Sharpe Ratio", "-0.867"},
|
||||
{"Probabilistic Sharpe Ratio", "0.021%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.45"},
|
||||
{"Alpha", "-0.596"},
|
||||
{"Beta", "-0.031"},
|
||||
{"Annual Standard Deviation", "0.681"},
|
||||
{"Annual Variance", "0.463"},
|
||||
{"Information Ratio", "-0.514"},
|
||||
{"Tracking Error", "0.703"},
|
||||
{"Treynor Ratio", "18.748"},
|
||||
{"Profit-Loss Ratio", "0.44"},
|
||||
{"Alpha", "-0.611"},
|
||||
{"Beta", "-0.033"},
|
||||
{"Annual Standard Deviation", "0.695"},
|
||||
{"Annual Variance", "0.484"},
|
||||
{"Information Ratio", "-0.513"},
|
||||
{"Tracking Error", "0.718"},
|
||||
{"Treynor Ratio", "18.473"},
|
||||
{"Total Fees", "$66.60"},
|
||||
{"Fitness Score", "0.157"},
|
||||
{"Fitness Score", "0.162"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.133"},
|
||||
{"Return Over Maximum Drawdown", "-1.492"},
|
||||
{"Portfolio Turnover", "0.411"},
|
||||
{"Sortino Ratio", "-0.136"},
|
||||
{"Return Over Maximum Drawdown", "-1.529"},
|
||||
{"Portfolio Turnover", "0.427"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -204,7 +199,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "151392833"}
|
||||
{"OrderListHash", "1153646593"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests Out of The Money (OTM) future option expiry for calls.
|
||||
/// We expect 1 order from the algorithm, which are:
|
||||
/// We expect 2 orders from the algorithm, which are:
|
||||
///
|
||||
/// * Initial entry, buy ES Call Option (expiring OTM)
|
||||
/// - contract expires worthless, not exercised, so never opened a position in the underlying
|
||||
///
|
||||
/// * Liquidation of worthless ES call option (expiring OTM)
|
||||
///
|
||||
/// Additionally, we test delistings for future options and assert that our
|
||||
/// portfolio holdings reflect the orders the algorithm has submitted.
|
||||
/// </summary>
|
||||
@@ -49,11 +51,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -183,28 +180,28 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-4.03%"},
|
||||
{"Compounding Annual Return", "-8.088%"},
|
||||
{"Compounding Annual Return", "-8.595%"},
|
||||
{"Drawdown", "4.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-4.029%"},
|
||||
{"Sharpe Ratio", "-1.274"},
|
||||
{"Probabilistic Sharpe Ratio", "0.015%"},
|
||||
{"Sharpe Ratio", "-1.294"},
|
||||
{"Probabilistic Sharpe Ratio", "0.017%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.066"},
|
||||
{"Alpha", "-0.069"},
|
||||
{"Beta", "-0.002"},
|
||||
{"Annual Standard Deviation", "0.052"},
|
||||
{"Annual Standard Deviation", "0.053"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "0.9"},
|
||||
{"Tracking Error", "0.179"},
|
||||
{"Treynor Ratio", "28.537"},
|
||||
{"Information Ratio", "0.911"},
|
||||
{"Tracking Error", "0.182"},
|
||||
{"Treynor Ratio", "28.46"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.183"},
|
||||
{"Return Over Maximum Drawdown", "-2.007"},
|
||||
{"Sortino Ratio", "-0.195"},
|
||||
{"Return Over Maximum Drawdown", "-2.134"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -219,7 +216,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1116221764"}
|
||||
{"OrderListHash", "-1004351165"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression test tests for the loading of futures options contracts with a contract month of 2020-03 can live
|
||||
/// and be loaded from the same ZIP file that the 2020-04 contract month Future Option contract lives in.
|
||||
/// </summary>
|
||||
public class FutureOptionMultipleContractsInDifferentContractMonthsWithSameUnderlyingFutureRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private readonly Dictionary<Symbol, bool> _expectedSymbols = new Dictionary<Symbol, bool>
|
||||
{
|
||||
{ CreateOption(new DateTime(2020, 3, 26), OptionRight.Call, 1650), false },
|
||||
{ CreateOption(new DateTime(2020, 3, 26), OptionRight.Put, 1540), false },
|
||||
{ CreateOption(new DateTime(2020, 2, 25), OptionRight.Call, 1600), false },
|
||||
{ CreateOption(new DateTime(2020, 2, 25), OptionRight.Put, 1545), false }
|
||||
};
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 1, 6);
|
||||
|
||||
var goldFutures = AddFuture("GC", Resolution.Minute, Market.COMEX);
|
||||
goldFutures.SetFilter(0, 365);
|
||||
|
||||
AddFutureOption(goldFutures.Symbol);
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var symbol in data.QuoteBars.Keys)
|
||||
{
|
||||
if (_expectedSymbols.ContainsKey(symbol))
|
||||
{
|
||||
var invested = _expectedSymbols[symbol];
|
||||
if (!invested)
|
||||
{
|
||||
MarketOrder(symbol, 1);
|
||||
}
|
||||
|
||||
_expectedSymbols[symbol] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
var notEncountered = _expectedSymbols.Where(kvp => !kvp.Value).ToList();
|
||||
if (notEncountered.Any())
|
||||
{
|
||||
throw new Exception($"Expected all Symbols encountered and invested in, but the following were not found: {string.Join(", ", notEncountered.Select(kvp => kvp.Value.ToStringInvariant()))}");
|
||||
}
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
throw new Exception("Expected holdings at the end of algorithm, but none were found.");
|
||||
}
|
||||
}
|
||||
|
||||
private static Symbol CreateOption(DateTime expiry, OptionRight optionRight, decimal strikePrice)
|
||||
{
|
||||
return QuantConnect.Symbol.CreateOption(
|
||||
QuantConnect.Symbol.CreateFuture("GC", Market.COMEX, new DateTime(2020, 4, 28)),
|
||||
Market.COMEX,
|
||||
OptionStyle.American,
|
||||
optionRight,
|
||||
strikePrice,
|
||||
expiry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-8.289%"},
|
||||
{"Drawdown", "3.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-0.047%"},
|
||||
{"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", "-14.395"},
|
||||
{"Tracking Error", "0.043"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.019"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-194.237"},
|
||||
{"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", "1328857323"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -46,11 +46,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -132,12 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
private void AssertFutureOptionOrderExercise(OrderEvent orderEvent, Security future, Security optionContract)
|
||||
{
|
||||
// We expect the liquidation to occur on the day of the delisting (while the market is open),
|
||||
// but currently we liquidate at the next market open (AAPL open) which happens to be
|
||||
// at 9:30:00 Eastern Time. For unknown reasons, the delisting happens two minutes after the
|
||||
// market open.
|
||||
// Read more about the issue affecting this test here: https://github.com/QuantConnect/Lean/issues/4980
|
||||
var expectedLiquidationTimeUtc = new DateTime(2020, 6, 22, 13, 32, 0);
|
||||
var expectedLiquidationTimeUtc = new DateTime(2020, 6, 19, 20, 0, 0);
|
||||
|
||||
if (orderEvent.Direction == OrderDirection.Buy && future.Holdings.Quantity != 0)
|
||||
{
|
||||
@@ -214,31 +204,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "4.18%"},
|
||||
{"Average Win", "4.15%"},
|
||||
{"Average Loss", "-8.27%"},
|
||||
{"Compounding Annual Return", "-8.879%"},
|
||||
{"Drawdown", "4.400%"},
|
||||
{"Expectancy", "-0.247"},
|
||||
{"Net Profit", "-4.432%"},
|
||||
{"Sharpe Ratio", "-1.391"},
|
||||
{"Compounding Annual Return", "-9.486%"},
|
||||
{"Drawdown", "4.500%"},
|
||||
{"Expectancy", "-0.249"},
|
||||
{"Net Profit", "-4.457%"},
|
||||
{"Sharpe Ratio", "-1.412"},
|
||||
{"Probabilistic Sharpe Ratio", "0.002%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.51"},
|
||||
{"Alpha", "-0.073"},
|
||||
{"Profit-Loss Ratio", "0.50"},
|
||||
{"Alpha", "-0.076"},
|
||||
{"Beta", "-0.002"},
|
||||
{"Annual Standard Deviation", "0.052"},
|
||||
{"Annual Standard Deviation", "0.053"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "0.863"},
|
||||
{"Tracking Error", "0.179"},
|
||||
{"Treynor Ratio", "38.46"},
|
||||
{"Information Ratio", "0.871"},
|
||||
{"Tracking Error", "0.183"},
|
||||
{"Treynor Ratio", "37.798"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.008"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.224"},
|
||||
{"Return Over Maximum Drawdown", "-2.003"},
|
||||
{"Portfolio Turnover", "0.023"},
|
||||
{"Sortino Ratio", "-0.238"},
|
||||
{"Return Over Maximum Drawdown", "-2.128"},
|
||||
{"Portfolio Turnover", "0.024"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -252,7 +242,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-675079082"}
|
||||
{"OrderListHash", "1657883738"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests Out of The Money (OTM) future option expiry for puts.
|
||||
/// We expect 1 order from the algorithm, which are:
|
||||
/// We expect 2 orders from the algorithm, which are:
|
||||
///
|
||||
/// * Initial entry, buy ES Put Option (expiring OTM)
|
||||
/// - contract expires worthless, not exercised, so never opened a position in the underlying
|
||||
///
|
||||
/// * Liquidation of worthless ES Put OTM contract
|
||||
///
|
||||
/// Additionally, we test delistings for future options and assert that our
|
||||
/// portfolio holdings reflect the orders the algorithm has submitted.
|
||||
/// </summary>
|
||||
@@ -48,11 +50,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -182,28 +179,28 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-5.12%"},
|
||||
{"Compounding Annual Return", "-10.212%"},
|
||||
{"Compounding Annual Return", "-10.844%"},
|
||||
{"Drawdown", "5.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-5.116%"},
|
||||
{"Sharpe Ratio", "-1.26"},
|
||||
{"Probabilistic Sharpe Ratio", "0.016%"},
|
||||
{"Sharpe Ratio", "-1.28"},
|
||||
{"Probabilistic Sharpe Ratio", "0.017%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.084"},
|
||||
{"Alpha", "-0.086"},
|
||||
{"Beta", "-0.003"},
|
||||
{"Annual Standard Deviation", "0.066"},
|
||||
{"Annual Standard Deviation", "0.067"},
|
||||
{"Annual Variance", "0.004"},
|
||||
{"Information Ratio", "0.785"},
|
||||
{"Tracking Error", "0.184"},
|
||||
{"Treynor Ratio", "28.158"},
|
||||
{"Information Ratio", "0.794"},
|
||||
{"Tracking Error", "0.187"},
|
||||
{"Treynor Ratio", "28.078"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.181"},
|
||||
{"Return Over Maximum Drawdown", "-1.995"},
|
||||
{"Sortino Ratio", "-0.193"},
|
||||
{"Return Over Maximum Drawdown", "-2.12"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -218,7 +215,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "515984318"}
|
||||
{"OrderListHash", "-49211561"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -194,29 +189,29 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "10.05%"},
|
||||
{"Average Loss", "-5.60%"},
|
||||
{"Compounding Annual Return", "8.121%"},
|
||||
{"Average Loss", "-5.63%"},
|
||||
{"Compounding Annual Return", "8.619%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "0.396"},
|
||||
{"Net Profit", "3.880%"},
|
||||
{"Sharpe Ratio", "1.192"},
|
||||
{"Probabilistic Sharpe Ratio", "58.203%"},
|
||||
{"Expectancy", "0.393"},
|
||||
{"Net Profit", "3.855%"},
|
||||
{"Sharpe Ratio", "1.212"},
|
||||
{"Probabilistic Sharpe Ratio", "59.039%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "1.79"},
|
||||
{"Alpha", "0.069"},
|
||||
{"Alpha", "0.071"},
|
||||
{"Beta", "0.003"},
|
||||
{"Annual Standard Deviation", "0.057"},
|
||||
{"Annual Standard Deviation", "0.058"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "1.641"},
|
||||
{"Tracking Error", "0.18"},
|
||||
{"Treynor Ratio", "22.101"},
|
||||
{"Information Ratio", "1.663"},
|
||||
{"Tracking Error", "0.183"},
|
||||
{"Treynor Ratio", "22.266"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.021"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "17.255"},
|
||||
{"Return Over Maximum Drawdown", "18.319"},
|
||||
{"Portfolio Turnover", "0.021"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -231,7 +226,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1118389718"}
|
||||
{"OrderListHash", "-120798310"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests Out of The Money (OTM) future option expiry for short calls.
|
||||
/// We expect 1 order from the algorithm, which are:
|
||||
/// We expect 2 orders from the algorithm, which are:
|
||||
///
|
||||
/// * Initial entry, sell ES Call Option (expiring OTM)
|
||||
/// - Profit the option premium, since the option was not assigned.
|
||||
///
|
||||
/// * Liquidation of ES call OTM contract on the last trade date
|
||||
///
|
||||
/// Additionally, we test delistings for future options and assert that our
|
||||
/// portfolio holdings reflect the orders the algorithm has submitted.
|
||||
/// </summary>
|
||||
@@ -45,11 +47,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -176,28 +173,28 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "1.81%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "3.745%"},
|
||||
{"Compounding Annual Return", "3.996%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "1.809%"},
|
||||
{"Sharpe Ratio", "1.292"},
|
||||
{"Probabilistic Sharpe Ratio", "65.890%"},
|
||||
{"Sharpe Ratio", "1.315"},
|
||||
{"Probabilistic Sharpe Ratio", "66.818%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.031"},
|
||||
{"Alpha", "0.032"},
|
||||
{"Beta", "0.001"},
|
||||
{"Annual Standard Deviation", "0.024"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "1.496"},
|
||||
{"Tracking Error", "0.173"},
|
||||
{"Treynor Ratio", "27.281"},
|
||||
{"Information Ratio", "1.516"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "27.339"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "95.176"},
|
||||
{"Return Over Maximum Drawdown", "101.571"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -212,7 +209,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1364902860"}
|
||||
{"OrderListHash", "-404864705"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +46,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -191,30 +186,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "10.18%"},
|
||||
{"Average Loss", "-8.02%"},
|
||||
{"Compounding Annual Return", "2.773%"},
|
||||
{"Average Loss", "-8.05%"},
|
||||
{"Compounding Annual Return", "2.902%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "0.135"},
|
||||
{"Net Profit", "1.343%"},
|
||||
{"Sharpe Ratio", "0.939"},
|
||||
{"Probabilistic Sharpe Ratio", "46.842%"},
|
||||
{"Expectancy", "0.133"},
|
||||
{"Net Profit", "1.318%"},
|
||||
{"Sharpe Ratio", "0.95"},
|
||||
{"Probabilistic Sharpe Ratio", "47.360%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "1.27"},
|
||||
{"Alpha", "0.023"},
|
||||
{"Alpha", "0.024"},
|
||||
{"Beta", "0.002"},
|
||||
{"Annual Standard Deviation", "0.025"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "1.45"},
|
||||
{"Tracking Error", "0.173"},
|
||||
{"Treynor Ratio", "14.62"},
|
||||
{"Information Ratio", "1.467"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "14.729"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.021"},
|
||||
{"Fitness Score", "0.022"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "5.815"},
|
||||
{"Portfolio Turnover", "0.022"},
|
||||
{"Return Over Maximum Drawdown", "6.087"},
|
||||
{"Portfolio Turnover", "0.023"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -228,7 +223,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "980293281"}
|
||||
{"OrderListHash", "-1218521879"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,11 +26,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests Out of The Money (OTM) future option expiry for short puts.
|
||||
/// We expect 1 order from the algorithm, which are:
|
||||
/// We expect 2 order from the algorithm, which are:
|
||||
///
|
||||
/// * Initial entry, sell ES Put Option (expiring OTM)
|
||||
/// - Profit the option premium, since the option was not assigned.
|
||||
///
|
||||
/// * Liquidation of ES put OTM contract on the last trade date
|
||||
///
|
||||
/// Additionally, we test delistings for future options and assert that our
|
||||
/// portfolio holdings reflect the orders the algorithm has submitted.
|
||||
/// </summary>
|
||||
@@ -45,11 +47,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 6, 30);
|
||||
|
||||
// We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
// which causes delisting events to never be processed, thus leading to options that might never
|
||||
// be exercised until the next data point arrives.
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
|
||||
_es19m20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -175,28 +172,28 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "3.28%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "6.852%"},
|
||||
{"Compounding Annual Return", "7.317%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "3.284%"},
|
||||
{"Sharpe Ratio", "1.319"},
|
||||
{"Probabilistic Sharpe Ratio", "66.574%"},
|
||||
{"Sharpe Ratio", "1.343"},
|
||||
{"Probabilistic Sharpe Ratio", "67.503%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.058"},
|
||||
{"Alpha", "0.06"},
|
||||
{"Beta", "0.002"},
|
||||
{"Annual Standard Deviation", "0.043"},
|
||||
{"Annual Standard Deviation", "0.044"},
|
||||
{"Annual Variance", "0.002"},
|
||||
{"Information Ratio", "1.614"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "28.2"},
|
||||
{"Information Ratio", "1.636"},
|
||||
{"Tracking Error", "0.179"},
|
||||
{"Treynor Ratio", "28.253"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "150.252"},
|
||||
{"Return Over Maximum Drawdown", "160.505"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -211,7 +208,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-418839052"}
|
||||
{"OrderListHash", "-2019978457"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests delistings for Futures and Futures Options to ensure that they are delisted at the expected times.
|
||||
/// </summary>
|
||||
public class FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private bool _invested;
|
||||
private int _liquidated;
|
||||
private int _delistingsReceived;
|
||||
|
||||
private Symbol _esFuture;
|
||||
private Symbol _esFutureOption;
|
||||
|
||||
private readonly DateTime _expectedExpiryWarningTime = new DateTime(2020, 6, 19);
|
||||
private readonly DateTime _expectedExpiryDelistingTime = new DateTime(2020, 6, 20);
|
||||
private readonly DateTime _expectedLiquidationTime = new DateTime(2020, 6, 19, 16, 0, 0);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 5);
|
||||
SetEndDate(2020, 12, 1);
|
||||
SetCash(100000);
|
||||
|
||||
var es = QuantConnect.Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
Market.CME,
|
||||
new DateTime(2020, 6, 19));
|
||||
|
||||
var esOption = QuantConnect.Symbol.CreateOption(
|
||||
es,
|
||||
Market.CME,
|
||||
OptionStyle.American,
|
||||
OptionRight.Put,
|
||||
3400m,
|
||||
new DateTime(2020, 6, 19));
|
||||
|
||||
_esFuture = AddFutureContract(es, Resolution.Minute).Symbol;
|
||||
_esFutureOption = AddFutureOptionContract(esOption, Resolution.Minute).Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var delisting in data.Delistings.Values)
|
||||
{
|
||||
// Two warnings and two delisted events should be received for a grand total of 4 events.
|
||||
_delistingsReceived++;
|
||||
|
||||
if (delisting.Type == DelistingType.Warning &&
|
||||
delisting.Time != _expectedExpiryWarningTime)
|
||||
{
|
||||
throw new Exception($"Expiry warning with time {delisting.Time} but is expected to be {_expectedExpiryWarningTime}");
|
||||
}
|
||||
if (delisting.Type == DelistingType.Warning && delisting.Time != Time.Date)
|
||||
{
|
||||
throw new Exception($"Delisting warning received at an unexpected date: {Time} - expected {delisting.Time}");
|
||||
}
|
||||
if (delisting.Type == DelistingType.Delisted &&
|
||||
delisting.Time != _expectedExpiryDelistingTime)
|
||||
{
|
||||
throw new Exception($"Delisting occurred at unexpected time: {delisting.Time} - expected: {_expectedExpiryDelistingTime}");
|
||||
}
|
||||
if (delisting.Type == DelistingType.Delisted &&
|
||||
delisting.Time != Time.Date)
|
||||
{
|
||||
throw new Exception($"Delisting notice received at an unexpected date: {Time} - expected {delisting.Time}");
|
||||
}
|
||||
}
|
||||
|
||||
if (!_invested &&
|
||||
(data.Bars.ContainsKey(_esFuture) || data.QuoteBars.ContainsKey(_esFuture)) &&
|
||||
(data.Bars.ContainsKey(_esFutureOption) || data.QuoteBars.ContainsKey(_esFutureOption)))
|
||||
{
|
||||
_invested = true;
|
||||
|
||||
MarketOrder(_esFuture, 1);
|
||||
MarketOrder(_esFutureOption, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
if (orderEvent.Direction != OrderDirection.Sell || orderEvent.Status != OrderStatus.Filled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// * Future Liquidation
|
||||
// * Future Option Exercise
|
||||
|
||||
// * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven
|
||||
_liquidated++;
|
||||
if (orderEvent.Symbol.SecurityType == SecurityType.FutureOption && _expectedLiquidationTime != Time)
|
||||
{
|
||||
throw new Exception($"Expected to liquidate option {orderEvent.Symbol} at {_expectedLiquidationTime}, instead liquidated at {Time}");
|
||||
}
|
||||
if (orderEvent.Symbol.SecurityType == SecurityType.Future && _expectedLiquidationTime.AddMinutes(-1) != Time && _expectedLiquidationTime != Time)
|
||||
{
|
||||
throw new Exception($"Expected to liquidate future {orderEvent.Symbol} at {_expectedLiquidationTime} (+1 minute), instead liquidated at {Time}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_invested)
|
||||
{
|
||||
throw new Exception("Never invested in ES futures and FOPs");
|
||||
}
|
||||
if (_delistingsReceived != 4)
|
||||
{
|
||||
throw new Exception($"Expected 4 delisting events received, found: {_delistingsReceived}");
|
||||
}
|
||||
if (_liquidated != 2)
|
||||
{
|
||||
throw new Exception($"Expected 3 liquidation events, found {_liquidated}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "3"},
|
||||
{"Average Win", "10.15%"},
|
||||
{"Average Loss", "-11.34%"},
|
||||
{"Compounding Annual Return", "-5.054%"},
|
||||
{"Drawdown", "2.300%"},
|
||||
{"Expectancy", "-0.053"},
|
||||
{"Net Profit", "-2.345%"},
|
||||
{"Sharpe Ratio", "-1.289"},
|
||||
{"Probabilistic Sharpe Ratio", "0.028%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0.89"},
|
||||
{"Alpha", "-0.031"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.024"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "1.155"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "29.128"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Fitness Score", "0.007"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.354"},
|
||||
{"Return Over Maximum Drawdown", "-2.155"},
|
||||
{"Portfolio Turnover", "0.024"},
|
||||
{"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", "2109976361"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing GH issue #5232
|
||||
/// </summary>
|
||||
public class HourResolutionMappingEventRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private DateTime _dateTime;
|
||||
private SymbolChangedEvent _changedEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2008, 08, 20);
|
||||
SetEndDate(2008, 10, 1);
|
||||
|
||||
AddEquity("SPWR", Resolution.Hour, fillDataForward: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)
|
||||
{
|
||||
_dateTime = Time.Date;
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings("SPWR", 1);
|
||||
}
|
||||
|
||||
foreach (var symbolChangedEvent in data.SymbolChangedEvents.Values)
|
||||
{
|
||||
_changedEvent = symbolChangedEvent;
|
||||
Log($"{Time}: {symbolChangedEvent.OldSymbol} -> {symbolChangedEvent.NewSymbol}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_dateTime != EndDate.Date)
|
||||
{
|
||||
throw new Exception($"Last day was {_dateTime}, should be algorithm end date: {EndDate.Date}");
|
||||
}
|
||||
if (_changedEvent == null)
|
||||
{
|
||||
throw new Exception("We got not symbol change event! 'SPWR' should of been mapped");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "-78.316%"},
|
||||
{"Drawdown", "31.700%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-16.363%"},
|
||||
{"Sharpe Ratio", "-0.506"},
|
||||
{"Probabilistic Sharpe Ratio", "27.578%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.431"},
|
||||
{"Beta", "1.976"},
|
||||
{"Annual Standard Deviation", "1.118"},
|
||||
{"Annual Variance", "1.25"},
|
||||
{"Information Ratio", "-0.071"},
|
||||
{"Tracking Error", "0.866"},
|
||||
{"Treynor Ratio", "-0.286"},
|
||||
{"Total Fees", "$5.40"},
|
||||
{"Fitness Score", "0.008"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.038"},
|
||||
{"Return Over Maximum Drawdown", "-2.536"},
|
||||
{"Portfolio Turnover", "0.033"},
|
||||
{"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", "1990864398"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetCash(100000);
|
||||
SetBenchmark(x => 0);
|
||||
|
||||
_symbol = AddEquity("VXX", Resolution.Hour).Symbol;
|
||||
_symbol = AddEquity("VXX.1", Resolution.Hour).Symbol;
|
||||
}
|
||||
|
||||
public void OnData(TradeBars tradeBars)
|
||||
@@ -103,7 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1795141360"}
|
||||
{"OrderListHash", "105744170"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Annual Variance", "0.013"},
|
||||
{"Information Ratio", "-0.234"},
|
||||
{"Tracking Error", "0.214"},
|
||||
{"Treynor Ratio", "-0.775"},
|
||||
{"Treynor Ratio", "-0.774"},
|
||||
{"Total Fees", "$443.74"},
|
||||
{"Fitness Score", "0.013"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Annual Variance", "0.038"},
|
||||
{"Information Ratio", "0.262"},
|
||||
{"Tracking Error", "0.346"},
|
||||
{"Treynor Ratio", "-0.862"},
|
||||
{"Treynor Ratio", "-0.863"},
|
||||
{"Total Fees", "$13.69"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "22"},
|
||||
{"Total Trades", "24"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
@@ -101,8 +101,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-50.218"},
|
||||
{"Portfolio Turnover", "6.713"},
|
||||
{"Return Over Maximum Drawdown", "-50.725"},
|
||||
{"Portfolio Turnover", "8.14"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -116,7 +116,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1597098916"}
|
||||
{"OrderListHash", "-2017313615"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "2037056244"}
|
||||
{"OrderListHash", "1393663292"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing GH issue #3914 where the option chain subscriptions wouldn't get removed
|
||||
/// </summary>
|
||||
public class OptionChainSubscriptionRemovalRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private int _optionCount;
|
||||
public override void Initialize()
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
SetStartDate(2014, 06, 05);
|
||||
SetEndDate(2014, 06, 09);
|
||||
|
||||
// this line is the key of this test it changed the behavior if the resolution used
|
||||
// is < that Minute which is the Option resolution
|
||||
AddEquity("SPY", Resolution.Second);
|
||||
SetUniverseSelection(new TestOptionUniverseSelectionModel(SelectOptionChainSymbols));
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
_optionCount += changes.AddedSecurities.Count(security => security.Symbol.SecurityType == SecurityType.Option);
|
||||
|
||||
Log($"{GetStatusLog()} CHANGES: {changes}");
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_optionCount != 30)
|
||||
{
|
||||
throw new Exception($"Unexpected option count {_optionCount}, expected 30");
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<Symbol> SelectOptionChainSymbols(DateTime utcTime)
|
||||
{
|
||||
var newYorkTime = utcTime.ConvertFromUtc(TimeZones.NewYork);
|
||||
if (newYorkTime.Date < new DateTime(2014, 06, 06))
|
||||
{
|
||||
yield return QuantConnect.Symbol.Create("TWX", SecurityType.Option, Market.USA, "?TWX");
|
||||
}
|
||||
|
||||
if (newYorkTime.Date >= new DateTime(2014, 06, 06))
|
||||
{
|
||||
yield return QuantConnect.Symbol.Create("AAPL", SecurityType.Option, Market.USA, "?AAPL");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetStatusLog()
|
||||
{
|
||||
Plot("Status", "UniverseCount", UniverseManager.Count);
|
||||
Plot("Status", "SubscriptionCount", SubscriptionManager.Subscriptions.Count());
|
||||
Plot("Status", "ActiveSymbolsCount", UniverseManager.ActiveSecurities.Count);
|
||||
|
||||
// why 50? we select 15 option contracts, which add trade/quote/openInterest = 45 + SPY & underlying trade/quote + universe subscription => 50
|
||||
if (SubscriptionManager.Subscriptions.Count() > 50)
|
||||
{
|
||||
throw new Exception("Subscriptions aren't getting removed as expected!");
|
||||
}
|
||||
|
||||
return $"{Time} | UniverseCount {UniverseManager.Count}. " +
|
||||
$"SubscriptionCount {SubscriptionManager.Subscriptions.Count()}. " +
|
||||
$"ActiveSymbols {string.Join(",", UniverseManager.ActiveSecurities.Keys)}";
|
||||
}
|
||||
|
||||
class TestOptionUniverseSelectionModel : OptionUniverseSelectionModel
|
||||
{
|
||||
public TestOptionUniverseSelectionModel(Func<DateTime, IEnumerable<Symbol>> optionChainSymbolSelector)
|
||||
: base(TimeSpan.FromDays(1), optionChainSymbolSelector)
|
||||
{
|
||||
}
|
||||
|
||||
protected override OptionFilterUniverse Filter(OptionFilterUniverse filter)
|
||||
{
|
||||
return filter.BackMonth().Contracts(filter.Take(15));
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "-25.506"},
|
||||
{"Tracking Error", "0.042"},
|
||||
{"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"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/*
|
||||
* 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>
|
||||
/// Regression algorithm which reproduces GH issue #5079, where option chain universes would sometimes not get removed from the
|
||||
/// UniverseManager causing new universes not to get added
|
||||
/// </summary>
|
||||
public class OptionChainUniverseRemovalRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
// initialize our changes to nothing
|
||||
private SecurityChanges _changes = SecurityChanges.None;
|
||||
private int _optionCount;
|
||||
private Symbol _lastEquityAdded;
|
||||
private Symbol _aapl;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
SetStartDate(2014, 06, 06);
|
||||
SetEndDate(2014, 06, 10);
|
||||
|
||||
var toggle = true;
|
||||
var selectionUniverse = AddUniverse(enumerable =>
|
||||
{
|
||||
if (toggle)
|
||||
{
|
||||
toggle = false;
|
||||
return new []{ _aapl };
|
||||
}
|
||||
toggle = true;
|
||||
return Enumerable.Empty<Symbol>();
|
||||
});
|
||||
|
||||
AddUniverseOptions(selectionUniverse, universe =>
|
||||
{
|
||||
if (universe.Underlying == null)
|
||||
{
|
||||
throw new Exception("Underlying data point is null! This shouldn't happen, each OptionChainUniverse handles and should provide this");
|
||||
}
|
||||
return universe.IncludeWeeklys()
|
||||
.BackMonth() // back month so that they don't get removed because of being delisted
|
||||
.Contracts(universe.Take(5));
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
// if we have no changes, do nothing
|
||||
if (_changes == SecurityChanges.None ||
|
||||
_changes.AddedSecurities.Any(security => security.Price == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug(GetStatusLog());
|
||||
|
||||
foreach (var security in _changes.AddedSecurities)
|
||||
{
|
||||
if (!security.Symbol.HasUnderlying)
|
||||
{
|
||||
_lastEquityAdded = security.Symbol;
|
||||
}
|
||||
else
|
||||
{
|
||||
// options added should all match prev added security
|
||||
if (security.Symbol.Underlying != _lastEquityAdded)
|
||||
{
|
||||
throw new Exception($"Unexpected symbol added {security.Symbol}");
|
||||
}
|
||||
|
||||
_optionCount++;
|
||||
}
|
||||
}
|
||||
_changes = SecurityChanges.None;
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
Debug($"{GetStatusLog()}. CHANGES {changes}");
|
||||
if (Time.Day == 6)
|
||||
{
|
||||
if (Time.Hour != 0 && Time.Hour != 9)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges time: {Time} {changes}");
|
||||
}
|
||||
|
||||
if (changes.RemovedSecurities.Count != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected removals: {changes}");
|
||||
}
|
||||
|
||||
if (Time.Hour == 0)
|
||||
{
|
||||
// first we expect the equity to get Added
|
||||
if (changes.AddedSecurities.Count != 1 || changes.AddedSecurities[0].Symbol != _aapl)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges: {changes}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// later we expect the options to be Added
|
||||
if (changes.AddedSecurities.Count != 5 || changes.AddedSecurities.Any(security => security.Symbol.SecurityType != SecurityType.Option))
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges: {changes}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// We expect the equity to get Removed
|
||||
else if (Time.Day == 7)
|
||||
{
|
||||
if (Time.Hour != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges time: {Time} {changes}");
|
||||
}
|
||||
|
||||
if (changes.AddedSecurities.Count != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected additions: {changes}");
|
||||
}
|
||||
|
||||
if (changes.RemovedSecurities.Count != 1 || changes.RemovedSecurities[0].Symbol != _aapl)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges: {changes}");
|
||||
}
|
||||
}
|
||||
// We expect the options to get Removed, happens in the next loop after removing the equity
|
||||
else if (Time.Day == 9)
|
||||
{
|
||||
if (Time.Hour != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges time: {Time} {changes}");
|
||||
}
|
||||
|
||||
// later we expect the options to be Removed
|
||||
if (changes.RemovedSecurities.Count != 6
|
||||
// the removal of the raw underlying subscription from the option chain universe
|
||||
|| changes.RemovedSecurities.Single(security => security.Symbol.SecurityType != SecurityType.Option).Symbol != _aapl
|
||||
// the removal of the 5 option contracts
|
||||
|| changes.RemovedSecurities.Count(security => security.Symbol.SecurityType == SecurityType.Option) != 5)
|
||||
{
|
||||
throw new Exception($"Unexpected SecurityChanges: {changes}");
|
||||
}
|
||||
}
|
||||
|
||||
_changes += changes;
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_optionCount == 0)
|
||||
{
|
||||
throw new Exception("Option universe chain did not add any option!");
|
||||
}
|
||||
if (UniverseManager.Any(pair => pair.Value.DisposeRequested))
|
||||
{
|
||||
throw new Exception("There shouldn't be any disposed universe, they should be removed and replaced by new universes");
|
||||
}
|
||||
}
|
||||
|
||||
private string GetStatusLog()
|
||||
{
|
||||
Plot("Status", "UniverseCount", UniverseManager.Count);
|
||||
Plot("Status", "SubscriptionCount", SubscriptionManager.Subscriptions.Count());
|
||||
Plot("Status", "ActiveSymbolsCount", UniverseManager.ActiveSecurities.Count);
|
||||
|
||||
return $"{Time} | UniverseCount {UniverseManager.Count}. " +
|
||||
$"SubscriptionCount {SubscriptionManager.Subscriptions.Count()}. " +
|
||||
$"ActiveSymbols {string.Join(",", UniverseManager.ActiveSecurities.Keys)}";
|
||||
}
|
||||
|
||||
/// <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", "-9.31"},
|
||||
{"Tracking Error", "0.008"},
|
||||
{"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"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-1726463684"}
|
||||
{"OrderListHash", "-1004315474"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,14 +40,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2013, 07, 02);
|
||||
SetCash(1000000);
|
||||
|
||||
var option = AddOption("FOXA");
|
||||
var option = AddOption("TFCFA");
|
||||
_optionSymbol = option.Symbol;
|
||||
|
||||
// set our strike/expiry filter for this option chain
|
||||
option.SetFilter(-1, +1, TimeSpan.Zero, TimeSpan.MaxValue);
|
||||
|
||||
// use the underlying equity as the benchmark
|
||||
SetBenchmark("FOXA");
|
||||
SetBenchmark("TFCFA");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -182,7 +182,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "-932374"}
|
||||
{"OrderListHash", "-1383033718"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{39A81C16-A1E8-425E-A8F2-1433ADB80228}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuantConnect.Algorithm.CSharp</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm.CSharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<LangVersion>6</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Accord, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.3.6.0\lib\net462\Accord.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Fuzzy, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Fuzzy.3.6.0\lib\net462\Accord.Fuzzy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.MachineLearning, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.MachineLearning.3.6.0\lib\net462\Accord.MachineLearning.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Math, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Math.3.6.0\lib\net462\Accord.Math.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Math.Core, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Math.3.6.0\lib\net462\Accord.Math.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Statistics, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Statistics.3.6.0\lib\net462\Accord.Statistics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DynamicInterop, Version=0.7.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DynamicInterop.0.7.4\lib\net40\DynamicInterop.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MathNet.Numerics, Version=3.19.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MathNet.Numerics.3.19.0\lib\net40\MathNet.Numerics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NodaTime.1.3.4\lib\net35-Client\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RDotNet, Version=1.6.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\R.NET.Community.1.6.5\lib\net40\RDotNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RDotNet.NativeLibrary, Version=1.6.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\R.NET.Community.1.6.5\lib\net40\RDotNet.NativeLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
@@ -99,14 +34,9 @@
|
||||
<IsLinux Condition="'$(IsWindows)' != 'true' AND '$(IsOSX)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugDocker|AnyCPU'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>portable</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<LangVersion>6</LangVersion>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<Target Name="PrintRID" BeforeTargets="Build">
|
||||
<Message Text="IsWindows $(IsWindows)" Importance="high" />
|
||||
@@ -118,367 +48,58 @@
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AddAlphaModelAlgorithm.cs" />
|
||||
<Compile Include="CustomBuyingPowerModelAlgorithm.cs" />
|
||||
<Compile Include="AddFutureOptionContractDataStreamingRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddFutureOptionSingleOptionChainSelectedInUniverseFilterRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddOptionContractExpiresRegressionAlgorithm.cs" />
|
||||
<Compile Include="AltData\QuiverWallStreetBetsDataAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionCallITMGreeksExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="OnOrderEventExceptionRegression.cs" />
|
||||
<Compile Include="FutureOptionCallITMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionCallOTMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionPutITMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionPutOTMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionBuySellCallIntradayRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionShortCallITMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionShortCallOTMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionShortPutOTMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureOptionShortPutITMExpiryRegressionAlgorithm.cs" />
|
||||
<Compile Include="ScaledFillForwardDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="DailyHistoryForDailyResolutionRegressionAlgorithm.cs" />
|
||||
<Compile Include="DailyHistoryForMinuteResolutionRegressionAlgorithm.cs" />
|
||||
<Compile Include="ExtendedMarketHoursHistoryRegressionAlgorithm.cs" />
|
||||
<Compile Include="EquityTickQuoteAdjustedModeRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddOptionContractFromUniverseRegressionAlgorithm.cs" />
|
||||
<Compile Include="CoarseFineOptionUniverseChainRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionChainedAndUniverseSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionAssignmentRegressionAlgorithm.cs" />
|
||||
<Compile Include="SwitchDataModeRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddRemoveOptionUniverseRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddRemoveSecurityRegressionAlgorithm.cs" />
|
||||
<Compile Include="AddRiskManagementAlgorithm.cs" />
|
||||
<Compile Include="AddUniverseSelectionModelAlgorithm.cs" />
|
||||
<Compile Include="AddUniverseSelectionModelCoarseAlgorithm.cs" />
|
||||
<Compile Include="Alphas\GasAndCrudeOilEnergyCorrelationAlpha.cs" />
|
||||
<Compile Include="Alphas\GreenblattMagicFormulaAlpha.cs" />
|
||||
<Compile Include="Alphas\IntradayReversalCurrencyMarketsAlpha.cs" />
|
||||
<Compile Include="Alphas\ShareClassMeanReversionAlpha.cs" />
|
||||
<Compile Include="Alphas\SykesShortMicroCapAlpha.cs" />
|
||||
<Compile Include="Alphas\GlobalEquityMeanReversionIBSAlpha.cs" />
|
||||
<Compile Include="Alphas\MeanReversionLunchBreakAlpha.cs" />
|
||||
<Compile Include="Alphas\RebalancingLeveragedETFAlpha.cs" />
|
||||
<Compile Include="Alphas\TriangleExchangeRateArbitrageAlpha.cs" />
|
||||
<Compile Include="Alphas\TripleLeveragedETFPairVolatilityDecayAlpha.cs" />
|
||||
<Compile Include="Alphas\VixDualThrustAlpha.cs" />
|
||||
<Compile Include="AltData\CachedAlternativeDataAlgorithm.cs" />
|
||||
<Compile Include="AltData\BenzingaNewsAlgorithm.cs" />
|
||||
<Compile Include="AltData\SECReport8KAlgorithm.cs" />
|
||||
<Compile Include="AltData\SmartInsiderTransactionAlgorithm.cs" />
|
||||
<Compile Include="AltData\USTreasuryYieldCurveRateAlgorithm.cs" />
|
||||
<Compile Include="AltData\TradingEconomicsAlgorithm.cs" />
|
||||
<Compile Include="AltData\TiingoNewsAlgorithm.cs" />
|
||||
<Compile Include="AutomaticIndicatorWarmupDataTypeRegressionAlgorithm.cs" />
|
||||
<Compile Include="AutomaticIndicatorWarmupRegressionAlgorithm.cs" />
|
||||
<Compile Include="BacktestingBrokerageRegressionAlgorithm.cs" />
|
||||
<Compile Include="ExtendedMarketTradingRegressionAlgorithm.cs" />
|
||||
<Compile Include="CoarseTiingoNewsUniverseSelectionAlgorithm.cs" />
|
||||
<Compile Include="DelistedFutureLiquidateRegressionAlgorithm.cs" />
|
||||
<Compile Include="EmaCrossFuturesFrontMonthAlgorithm.cs" />
|
||||
<Compile Include="OpenInterestFuturesRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomPartialFillModelAlgorithm.cs" />
|
||||
<Compile Include="EquityTradeAndQuotesRegressionAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateConstituentUniverseAlgorithm.cs" />
|
||||
<Compile Include="ConsolidateRegressionAlgorithm.cs" />
|
||||
<Compile Include="DefaultResolutionRegressionAlgorithm.cs" />
|
||||
<Compile Include="BasicPythonIntegrationTemplateAlgorithm.cs" />
|
||||
<Compile Include="BasicSetAccountCurrencyAlgorithm.cs" />
|
||||
<Compile Include="FineFundamentalFilteredUniverseRegressionAlgorithm.cs" />
|
||||
<Compile Include="FutureSharingTickerRegressionAlgorithm.cs" />
|
||||
<Compile Include="LongOnlyAlphaStreamAlgorithm.cs" />
|
||||
<Compile Include="Benchmarks\SECReportBenchmarkAlgorithm.cs" />
|
||||
<Compile Include="Benchmarks\SmartInsiderEventBenchmarkAlgorithm.cs" />
|
||||
<Compile Include="CustomBenchmarkRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomDataAddDataCoarseSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomDataAddDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="DynamicSecurityDataAlgorithm.cs" />
|
||||
<Compile Include="ConfidenceWeightedFrameworkAlgorithm.cs" />
|
||||
<Compile Include="AccumulativeInsightPortfolioRegressionAlgorithm.cs" />
|
||||
<Compile Include="EqualWeightingPortfolioConstructionModelFutureRegressionAlgorithm.cs" />
|
||||
<Compile Include="FreePortfolioValueRegressionAlgorithm.cs" />
|
||||
<Compile Include="LeveragePrecedenceRegressionAlgorithm.cs" />
|
||||
<Compile Include="LiquidETFUniverseFrameworkAlgorithm.cs" />
|
||||
<Compile Include="MarginCallClosedMarketRegressionAlgorithm.cs" />
|
||||
<Compile Include="MarginRemainingRegressionAlgorithm.cs" />
|
||||
<Compile Include="NoMarginCallExpectedRegressionAlgorithm.cs" />
|
||||
<Compile Include="ObjectStoreExampleAlgorithm.cs" />
|
||||
<Compile Include="OrderImmutabilityRegressionAlgorithm.cs" />
|
||||
<Compile Include="OrderSubmissionDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="RegisterIndicatorRegressionAlgorithm.cs" />
|
||||
<Compile Include="ScheduledEventsOrderRegressionAlgorithm.cs" />
|
||||
<Compile Include="SectorWeightingFrameworkAlgorithm.cs" />
|
||||
<Compile Include="OnEndOfDayAddDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="PortfolioRebalanceOnCustomFuncRegressionAlgorithm.cs" />
|
||||
<Compile Include="PortfolioRebalanceOnDateRulesRegressionAlgorithm.cs" />
|
||||
<Compile Include="PortfolioRebalanceOnInsightChangesRegressionAlgorithm.cs" />
|
||||
<Compile Include="PortfolioRebalanceOnSecurityChangesRegressionAlgorithm.cs" />
|
||||
<Compile Include="ResolutionSwitchingAlgorithm.cs" />
|
||||
<Compile Include="SetHoldingsFutureRegressionAlgorithm.cs" />
|
||||
<Compile Include="StringToSymbolImplicitConversionRegressionAlgorithm.cs" />
|
||||
<Compile Include="TimeRulesDefaultTimeZoneRegressionAlgorithm.cs" />
|
||||
<Compile Include="SetHoldingsMultipleTargetsRegressionAlgorithm.cs" />
|
||||
<Compile Include="SetHoldingsMarketOnOpenRegressionAlgorithm.cs" />
|
||||
<Compile Include="SmartInsiderDataAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateAlgorithm.cs" />
|
||||
<Compile Include="Benchmarks\StatefulCoarseUniverseSelectionBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\StatelessCoarseUniverseSelectionBenchmark.cs" />
|
||||
<Compile Include="CapmAlphaRankingFrameworkAlgorithm.cs" />
|
||||
<Compile Include="CustomUniverseWithBenchmarkRegressionAlgorithm.cs" />
|
||||
<Compile Include="CoarseSelectionTimeRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomUniverseSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="OnEndOfDayRegressionAlgorithm.cs" />
|
||||
<Compile Include="TrainingInitializeRegressionAlgorithm.cs" />
|
||||
<Compile Include="TrainingExampleAlgorithm.cs" />
|
||||
<Compile Include="UniverseSharingSubscriptionTradableRegressionAlgorithm.cs" />
|
||||
<Compile Include="UniverseUnchangedRegressionAlgorithm.cs" />
|
||||
<Compile Include="USTreasuryYieldCurveDataAlgorithm.cs" />
|
||||
<Compile Include="SECReportDataAlgorithm.cs" />
|
||||
<Compile Include="CustomDataUsingMapFileRegressionAlgorithm.cs" />
|
||||
<Compile Include="ConstituentsUniverseDataGeneratorAlgorithm.cs" />
|
||||
<Compile Include="ConstituentsUniverseRegressionAlgorithm.cs" />
|
||||
<Compile Include="G10CurrencySelectionModelFrameworkAlgorithm.cs" />
|
||||
<Compile Include="ExpiryHelperAlphaModelFrameworkAlgorithm.cs" />
|
||||
<Compile Include="CfdTimeZonesRegressionAlgorithm.cs" />
|
||||
<Compile Include="EmitInsightCryptoCashAccountType.cs" />
|
||||
<Compile Include="EmitInsightsAlgorithm.cs" />
|
||||
<Compile Include="EmitInsightNoAlphaModelAlgorithm.cs" />
|
||||
<Compile Include="CoarseNoLookAheadBiasAlgorithm.cs" />
|
||||
<Compile Include="ConvertToFrameworkAlgorithm.cs" />
|
||||
<Compile Include="HistoryWithSymbolChangesRegressionAlgorithm.cs" />
|
||||
<Compile Include="FeeModelNotUsingAccountCurrency.cs" />
|
||||
<Compile Include="InsightWeightingFrameworkAlgorithm.cs" />
|
||||
<Compile Include="MaximumPortfolioDrawdownFrameworkAlgorithm.cs" />
|
||||
<Compile Include="CompositeRiskManagementModelFrameworkAlgorithm.cs" />
|
||||
<Compile Include="ProcessSplitSymbolsRegressionAlgorithm.cs" />
|
||||
<Compile Include="RawPricesUniverseRegressionAlgorithm.cs" />
|
||||
<Compile Include="SetAccountCurrencyCashBuyingPowerModelRegressionAlgorithm.cs" />
|
||||
<Compile Include="SetAccountCurrencySecurityMarginModelRegressionAlgorithm.cs" />
|
||||
<Compile Include="SetCashOnDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="SmaCrossUniverseSelectionAlgorithm.cs" />
|
||||
<Compile Include="StartingCapitalRegressionAlgorithm.cs" />
|
||||
<Compile Include="StopLossOnOrderEventRegressionAlgorithm.cs" />
|
||||
<Compile Include="TotalPortfolioValueRegressionAlgorithm.cs" />
|
||||
<Compile Include="TradingEconomicsCalendarIndicatorAlgorithm.cs" />
|
||||
<Compile Include="TrailingStopRiskFrameworkAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateFuturesFrameworkAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionsFrameworkAlgorithm.cs" />
|
||||
<Compile Include="BlackLittermanPortfolioOptimizationFrameworkAlgorithm.cs" />
|
||||
<Compile Include="DailyResolutionSplitRegressionAlgorithm.cs" />
|
||||
<Compile Include="MeanVarianceOptimizationFrameworkAlgorithm.cs" />
|
||||
<Compile Include="TiingoPriceAlgorithm.cs" />
|
||||
<Compile Include="OptionExpiryDateOnHolidayCase.cs" />
|
||||
<Compile Include="OptionDataNullReferenceRegressionAlgorithm.cs" />
|
||||
<Compile Include="CancelOpenOrdersRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionDelistedDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm.cs" />
|
||||
<Compile Include="RawPricesCoarseUniverseAlgorithm.cs" />
|
||||
<Compile Include="CompositeAlphaModelFrameworkAlgorithm.cs" />
|
||||
<Compile Include="SectorExposureRiskFrameworkAlgorithm.cs" />
|
||||
<Compile Include="DuplicateSecurityWithBenchmarkRegressionAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateCryptoAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateCryptoFrameworkAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateIntrinioEconomicData.cs" />
|
||||
<Compile Include="BasicTemplateFrameworkAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateLibrary.cs" />
|
||||
<Compile Include="Benchmarks\EmptyMinute400EquityBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\BasicTemplateBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\EmptySingleSecuritySecondEquityBenchmark.cs" />
|
||||
<Compile Include="CustomFrameworkModelsAlgorithm.cs" />
|
||||
<Compile Include="EmaCrossUniverseSelectionFrameworkAlgorithm.cs" />
|
||||
<Compile Include="FinancialAdvisorDemoAlgorithm.cs" />
|
||||
<Compile Include="ForexInternalFeedOnDataHigherResolutionRegressionAlgorithm.cs" />
|
||||
<Compile Include="ForexInternalFeedOnDataSameResolutionRegressionAlgorithm.cs" />
|
||||
<Compile Include="RollingWindowAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateDailyAlgorithm.cs" />
|
||||
<Compile Include="CallingRFromCSharp.cs" />
|
||||
<Compile Include="FuturesMomentumAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateFuturesConsolidationAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateFuturesHistoryAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateMultiAssetAlgorithm.cs" />
|
||||
<Compile Include="FilteredIdentityAlgorithm.cs" />
|
||||
<Compile Include="OptionExerciseAssignRegressionAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionsFilterUniverseAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionsHistoryAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionTradesAlgorithm.cs" />
|
||||
<Compile Include="OptionChainConsistencyRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionOpenInterestRegressionAlgorithm.cs" />
|
||||
<Compile Include="RegressionChannelAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateFuturesAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionStrategyAlgorithm.cs" />
|
||||
<Compile Include="CoarseFineFundamentalRegressionAlgorithm.cs" />
|
||||
<Compile Include="CoarseFineFundamentalComboAlgorithm.cs" />
|
||||
<Compile Include="FuzzyInferenceAlgorithm.cs" />
|
||||
<Compile Include="OptionRenameRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionSplitRegressionAlgorithm.cs" />
|
||||
<Compile Include="PortfolioOptimizationNumericsAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateForexAlgorithm.cs" />
|
||||
<Compile Include="AccordVectorMachinesAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateOptionsAlgorithm.cs" />
|
||||
<Compile Include="CoarseFundamentalTop3Algorithm.cs" />
|
||||
<Compile Include="CustomBenchmarkAlgorithm.cs" />
|
||||
<Compile Include="CustomBrokerageMessageHandlerAlgorithm.cs" />
|
||||
<Compile Include="FractionalQuantityRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomDataRegressionAlgorithm.cs" />
|
||||
<Compile Include="CustomDataUniverseAlgorithm.cs" />
|
||||
<Compile Include="CustomModelsAlgorithm.cs" />
|
||||
<Compile Include="CustomSecurityInitializerAlgorithm.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DelistingEventsAlgorithm.cs" />
|
||||
<Compile Include="DropboxBaseDataUniverseSelectionAlgorithm.cs" />
|
||||
<Compile Include="HistoryAlgorithm.cs" />
|
||||
<Compile Include="IndicatorWarmupAlgorithm.cs" />
|
||||
<Compile Include="LimitFillRegressionAlgorithm.cs" />
|
||||
<Compile Include="BasicTemplateFillForwardAlgorithm.cs" />
|
||||
<Compile Include="BrokerageModelAlgorithm.cs" />
|
||||
<Compile Include="BubbleAlgorithm.cs" />
|
||||
<Compile Include="CustomChartingAlgorithm.cs" />
|
||||
<Compile Include="CustomDataBitcoinAlgorithm.cs" />
|
||||
<Compile Include="CustomDataNIFTYAlgorithm.cs" />
|
||||
<Compile Include="DailyAlgorithm.cs" />
|
||||
<Compile Include="DataConsolidationAlgorithm.cs" />
|
||||
<Compile Include="DisplacedMovingAverageRibbon.cs" />
|
||||
<Compile Include="DividendAlgorithm.cs" />
|
||||
<Compile Include="ETFGlobalRotationAlgorithm.cs" />
|
||||
<Compile Include="IndicatorSuiteAlgorithm.cs" />
|
||||
<Compile Include="LiveFeaturesAlgorithm.cs" />
|
||||
<Compile Include="OpeningBreakoutAlgorithm.cs" />
|
||||
<Compile Include="DropboxUniverseSelectionAlgorithm.cs" />
|
||||
<Compile Include="ParameterizedAlgorithm.cs" />
|
||||
<Compile Include="HourReverseSplitRegressionAlgorithm.cs" />
|
||||
<Compile Include="HourSplitRegressionAlgorithm.cs" />
|
||||
<Compile Include="ScheduledUniverseSelectionModelRegressionAlgorithm.cs" />
|
||||
<Compile Include="StandardDeviationExecutionModelRegressionAlgorithm.cs" />
|
||||
<Compile Include="TimeInForceAlgorithm.cs" />
|
||||
<Compile Include="UniverseSelectionDefinitionsAlgorithm.cs" />
|
||||
<Compile Include="UniverseSharingSecurityDifferentSubscriptionRequestRegressionAlgorithm.cs" />
|
||||
<Compile Include="UniverseSharingSubscriptionRequestRegressionAlgorithm.cs" />
|
||||
<Compile Include="EstimizeDataAlgorithm.cs" />
|
||||
<Compile Include="USEnergyInformationAdministrationAlgorithm.cs" />
|
||||
<Compile Include="UserDefinedUniverseAlgorithm.cs" />
|
||||
<Compile Include="VolumeWeightedAveragePriceExecutionModelRegressionAlgorithm.cs" />
|
||||
<Compile Include="WarmUpAfterIntializeRegression.cs" />
|
||||
<Compile Include="WarmupAlgorithm.cs" />
|
||||
<Compile Include="WarmupConversionRatesRegressionAlgorithm.cs" />
|
||||
<Compile Include="WarmupHistoryAlgorithm.cs" />
|
||||
<Compile Include="MACDTrendAlgorithm.cs" />
|
||||
<Compile Include="MarginCallEventsAlgorithm.cs" />
|
||||
<Compile Include="MarketOnOpenOnCloseAlgorithm.cs" />
|
||||
<Compile Include="MovingAverageCrossAlgorithm.cs" />
|
||||
<Compile Include="MultipleSymbolConsolidationAlgorithm.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QuandlFuturesDataAlgorithm.cs" />
|
||||
<Compile Include="QuandlImporterAlgorithm.cs" />
|
||||
<Compile Include="RegressionAlgorithm.cs" />
|
||||
<Compile Include="RenkoConsolidatorAlgorithm.cs" />
|
||||
<Compile Include="ScheduledEventsAlgorithm.cs" />
|
||||
<Compile Include="ScheduledQueuingAlgorithm.cs" />
|
||||
<Compile Include="StressSymbolsAlgorithm.cs" />
|
||||
<Compile Include="StressSymbols.cs" />
|
||||
<Compile Include="TickDataFilteringAlgorithm.cs" />
|
||||
<Compile Include="EmaCrossUniverseSelectionAlgorithm.cs" />
|
||||
<Compile Include="UniverseSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="UpdateOrderLiveTestAlgorithm.cs" />
|
||||
<Compile Include="UpdateOrderRegressionAlgorithm.cs" />
|
||||
<Compile Include="OrderTicketDemoAlgorithm.cs" />
|
||||
<Compile Include="WarmupIndicatorRegressionAlgorithm.cs" />
|
||||
<Compile Include="InceptionDateSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="WeeklyUniverseSelectionRegressionAlgorithm.cs" />
|
||||
<Compile Include="OptionChainProviderAlgorithm.cs" />
|
||||
<Compile Include="ConstituentsQC500GeneratorAlgorithm.cs" />
|
||||
<Compile Include="CustomDataIndicatorExtensionsAlgorithm.cs" />
|
||||
<Compile Include="Benchmarks\ScheduledEventsBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\HistoryRequestBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\CoarseFineUniverseSelectionBenchmark.cs" />
|
||||
<Compile Include="Benchmarks\IndicatorRibbonBenchmark.cs" />
|
||||
<Compile Include="ZeroFeeRegressionAlgorithm.cs" />
|
||||
<PackageReference Include="Accord" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Fuzzy" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.MachineLearning" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Math" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Statistics" Version="3.6.0" />
|
||||
<PackageReference Include="DynamicInterop" Version="0.7.4" />
|
||||
<PackageReference Include="MathNet.Numerics" Version="3.19.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers" Version="2.10.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NodaTime" Version="3.0.5" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="1.0.5.30" />
|
||||
<PackageReference Include="R.NET.Community" Version="1.6.5" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm.Framework\QuantConnect.Algorithm.Framework.csproj">
|
||||
<Project>{75981418-7246-4b91-b136-482728e02901}</Project>
|
||||
<Name>QuantConnect.Algorithm.Framework</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Project>{3240aca4-bdd4-4d24-ac36-bbb651c39212}</Project>
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
</ProjectReference>
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
<ProjectReference Include="..\Algorithm.Framework\QuantConnect.Algorithm.Framework.csproj" />
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj" />
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj" />
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Humanizer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DaylightSavingTimeHistoryRegressionAlgorithm.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Accord.3.6.0\build\Accord.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.3.6.0\build\Accord.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Import Project="..\packages\Accord.3.6.0\build\Accord.targets" Condition="Exists('..\packages\Accord.3.6.0\build\Accord.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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.Brokerages;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Shortable;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests that orders are denied if they exceed the max shortable quantity.
|
||||
/// </summary>
|
||||
public class ShortableProviderOrdersRejectedRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
private Symbol _aig;
|
||||
private readonly List<OrderTicket> _ordersAllowed = new List<OrderTicket>();
|
||||
private readonly List<OrderTicket> _ordersDenied = new List<OrderTicket>();
|
||||
private bool _initialize;
|
||||
private bool _invalidatedAllowedOrder;
|
||||
private bool _invalidatedNewOrderWithPortfolioHoldings;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 4);
|
||||
SetEndDate(2013, 10, 11);
|
||||
SetCash(10000000);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Minute).Symbol;
|
||||
_aig = AddEquity("AIG", Resolution.Minute).Symbol;
|
||||
|
||||
SetBrokerageModel(new RegressionTestShortableBrokerageModel());
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!_initialize)
|
||||
{
|
||||
HandleOrder(LimitOrder(_spy, -1001, 10000m)); // Should be canceled, exceeds the max shortable quantity
|
||||
HandleOrder(LimitOrder(_spy, -1000, 10000m)); // Allowed, orders at or below 1000 should be accepted
|
||||
HandleOrder(LimitOrder(_spy, -10, 0.01m)); // Should be canceled, the total quantity we would be short would exceed the max shortable quantity.
|
||||
_initialize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_invalidatedAllowedOrder)
|
||||
{
|
||||
if (_ordersAllowed.Count != 1)
|
||||
{
|
||||
throw new Exception($"Expected 1 successful order, found: {_ordersAllowed.Count}");
|
||||
}
|
||||
if (_ordersDenied.Count != 2)
|
||||
{
|
||||
throw new Exception($"Expected 2 failed orders, found: {_ordersDenied.Count}");
|
||||
}
|
||||
|
||||
var allowedOrder = _ordersAllowed[0];
|
||||
var orderUpdate = new UpdateOrderFields()
|
||||
{
|
||||
LimitPrice = 0.01m,
|
||||
Quantity = -1001,
|
||||
Tag = "Testing updating and exceeding maximum quantity"
|
||||
};
|
||||
|
||||
var response = allowedOrder.Update(orderUpdate);
|
||||
if (response.ErrorCode != OrderResponseErrorCode.ExceedsShortableQuantity)
|
||||
{
|
||||
throw new Exception($"Expected order to fail due to exceeded shortable quantity, found: {response.ErrorCode.ToString()}");
|
||||
}
|
||||
|
||||
var cancelResponse = allowedOrder.Cancel();
|
||||
if (cancelResponse.IsError)
|
||||
{
|
||||
throw new Exception("Expected to be able to cancel open order after bad qty update");
|
||||
}
|
||||
|
||||
_invalidatedAllowedOrder = true;
|
||||
_ordersDenied.Clear();
|
||||
_ordersAllowed.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_invalidatedNewOrderWithPortfolioHoldings)
|
||||
{
|
||||
HandleOrder(MarketOrder(_spy, -1000)); // Should succeed, no holdings and no open orders to stop this
|
||||
var spyShares = Portfolio[_spy].Quantity;
|
||||
if (spyShares != -1000m)
|
||||
{
|
||||
throw new Exception($"Expected -1000 shares in portfolio, found: {spyShares}");
|
||||
}
|
||||
|
||||
HandleOrder(LimitOrder(_spy, -1, 0.01m)); // Should fail, portfolio holdings are at the max shortable quantity.
|
||||
if (_ordersDenied.Count != 1)
|
||||
{
|
||||
throw new Exception($"Expected limit order to fail due to existing holdings, but found {_ordersDenied.Count} failures");
|
||||
}
|
||||
|
||||
_ordersAllowed.Clear();
|
||||
_ordersDenied.Clear();
|
||||
|
||||
HandleOrder(MarketOrder(_aig, -1001));
|
||||
if (_ordersAllowed.Count != 1)
|
||||
{
|
||||
throw new Exception($"Expected market order of -1001 BAC to not fail");
|
||||
}
|
||||
|
||||
_invalidatedNewOrderWithPortfolioHoldings = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleOrder(OrderTicket orderTicket)
|
||||
{
|
||||
if (orderTicket.SubmitRequest.Status == OrderRequestStatus.Error)
|
||||
{
|
||||
_ordersDenied.Add(orderTicket);
|
||||
return;
|
||||
}
|
||||
|
||||
_ordersAllowed.Add(orderTicket);
|
||||
}
|
||||
|
||||
private class RegressionTestShortableProvider : LocalDiskShortableProvider
|
||||
{
|
||||
public RegressionTestShortableProvider() : base(SecurityType.Equity, "testbrokerage", Market.USA)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class RegressionTestShortableBrokerageModel : DefaultBrokerageModel
|
||||
{
|
||||
public RegressionTestShortableBrokerageModel() : base()
|
||||
{
|
||||
ShortableProvider = new RegressionTestShortableProvider();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-1.719%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-0.036%"},
|
||||
{"Sharpe Ratio", "-1.741"},
|
||||
{"Probabilistic Sharpe Ratio", "35.789%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.004"},
|
||||
{"Beta", "-0.023"},
|
||||
{"Annual Standard Deviation", "0.005"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.512"},
|
||||
{"Tracking Error", "0.216"},
|
||||
{"Treynor Ratio", "0.367"},
|
||||
{"Total Fees", "$10.01"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-4.849"},
|
||||
{"Return Over Maximum Drawdown", "-21.738"},
|
||||
{"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", "1777297925"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing github issue #5191 where the symbol was removed from the cache
|
||||
/// even if a subscription is still present
|
||||
/// </summary>
|
||||
public class UniverseSelectionSymbolCacheRemovalRegressionTest : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private bool _optionWasRemoved;
|
||||
private Symbol _optionContract;
|
||||
private Symbol _equitySymbol;
|
||||
|
||||
/// <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, 06, 05);
|
||||
SetEndDate(2014, 06, 23);
|
||||
|
||||
AddEquity("AAPL", Resolution.Daily);
|
||||
_equitySymbol = AddEquity("TWX", Resolution.Minute).Symbol;
|
||||
|
||||
var contracts = OptionChainProvider.GetOptionContractList(_equitySymbol, UtcTime).ToList();
|
||||
|
||||
var callOptionSymbol = contracts
|
||||
.Where(c => c.ID.OptionRight == OptionRight.Call)
|
||||
.OrderBy(c => c.ID.Date)
|
||||
.First();
|
||||
_optionContract = AddOptionContract(callOptionSymbol).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)
|
||||
{
|
||||
var symbol = SymbolCache.GetSymbol("TWX");
|
||||
if (symbol == null)
|
||||
{
|
||||
throw new Exception("Unexpected removal of symbol from cache!");
|
||||
}
|
||||
|
||||
foreach (var dataDelisting in data.Delistings.Where(pair => pair.Value.Type == DelistingType.Delisted))
|
||||
{
|
||||
if (dataDelisting.Key != _optionContract)
|
||||
{
|
||||
throw new Exception("Unexpected delisting event!");
|
||||
}
|
||||
_optionWasRemoved = true;
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings("AAPL", 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_optionWasRemoved)
|
||||
{
|
||||
throw new Exception("Option contract was not removed!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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", "-3.072%"},
|
||||
{"Drawdown", "0.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-0.162%"},
|
||||
{"Sharpe Ratio", "-2.017"},
|
||||
{"Probabilistic Sharpe Ratio", "23.009%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.024"},
|
||||
{"Beta", "-0.007"},
|
||||
{"Annual Standard Deviation", "0.012"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-4.487"},
|
||||
{"Tracking Error", "0.053"},
|
||||
{"Treynor Ratio", "3.645"},
|
||||
{"Total Fees", "$1.00"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-3.347"},
|
||||
{"Return Over Maximum Drawdown", "-8.314"},
|
||||
{"Portfolio Turnover", "0.006"},
|
||||
{"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", "112416549"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// Regression algorithm to test warming up after initialize behavior, should throw if used outside of initialize
|
||||
/// Reference GH Issue #4939
|
||||
/// </summary>
|
||||
public class WarmUpAfterIntializeRegression : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
public class WarmUpAfterInitializeRegression : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
117
Algorithm.CSharp/ZeroedBenchmarkRegressionAlgorithm.cs
Normal file
117
Algorithm.CSharp/ZeroedBenchmarkRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Benchmarks;
|
||||
using QuantConnect.Brokerages;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm to test zeroed benchmark through BrokerageModel override
|
||||
/// </summary>
|
||||
public class ZeroedBenchmarkRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
|
||||
/// <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, 08); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
// Add equity
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
|
||||
// Use our Test Brokerage Model with zeroed default benchmark
|
||||
SetBrokerageModel(new TestBrokerageModel());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_spy, 1);
|
||||
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, 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", "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"},
|
||||
{"Total Fees", "$3.25"},
|
||||
{"Fitness Score", "0.498"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"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", "-1491193070"}
|
||||
};
|
||||
|
||||
internal class TestBrokerageModel : DefaultBrokerageModel
|
||||
{
|
||||
public override IBenchmark GetBenchmark(SecurityManager securities)
|
||||
{
|
||||
return new FuncBenchmark(x => 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Accord" publicKeyToken="fa1a88e29555ccf7" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Accord" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.Fuzzy" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.MachineLearning" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.Math" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.Statistics" version="3.6.0" targetFramework="net462" />
|
||||
<package id="DynamicInterop" version="0.7.4" targetFramework="net452" />
|
||||
<package id="MathNet.Numerics" version="3.19.0" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
||||
<package id="NodaTime" version="1.3.4" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
<package id="R.NET.Community" version="1.6.5" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -1,47 +0,0 @@
|
||||
// QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
// Lean Algorithmic Trading Engine v2.0. Copyright 2015 QuantConnect Corporation.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace System
|
||||
namespace System.Collections.Generic
|
||||
namespace QuantConnnect
|
||||
namespace QuantConnect.Orders
|
||||
namespace QuantConnect.Algorithm
|
||||
namespace QuantConnect.Securities
|
||||
namespace QuantConnect.Algorithm.FSharp
|
||||
|
||||
open System
|
||||
open QuantConnect
|
||||
open QuantConnect.Data.Market
|
||||
open QuantConnect.Algorithm
|
||||
|
||||
|
||||
// Declare algorithm name
|
||||
type BasicTemplateAlgorithm() =
|
||||
|
||||
//Reuse all the base class of QCAlgorithm
|
||||
inherit QCAlgorithm()
|
||||
|
||||
//Implement core methods:
|
||||
override this.Initialize() =
|
||||
this.SetCash(100000)
|
||||
this.SetStartDate(2013, 10, 07)
|
||||
this.SetEndDate(2013, 10, 11)
|
||||
this.AddSecurity(SecurityType.Equity, "SPY", Nullable Resolution.Second) |> ignore
|
||||
|
||||
//TradeBars Data Event
|
||||
member this.OnData(bar:TradeBars) =
|
||||
|
||||
if not this.Portfolio.Invested then
|
||||
this.SetHoldings(this.Symbol("SPY"), 1);
|
||||
else
|
||||
()
|
||||
@@ -1,149 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>7702711a-0c09-40d4-b151-e308d1520738</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>QuantConnect.Algorithm.FSharp</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm.FSharp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
|
||||
<Name>QuantConnect.Algorithm.FSharp</Name>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<Tailcalls>false</Tailcalls>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\QuantConnect.Algorithm.FSharp.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<Tailcalls>true</Tailcalls>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
<DocumentationFile>bin\Release\QuantConnect.Algorithm.FSharp.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NodaTime">
|
||||
<HintPath>..\packages\NodaTime.1.3.4\lib\net35-Client\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
<IsOSX>false</IsOSX>
|
||||
<IsOSX Condition="'$(IsWindows)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux>false</IsLinux>
|
||||
<IsLinux Condition="'$(IsWindows)' != 'true' AND '$(IsOSX)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<Target Name="PrintRID" BeforeTargets="Build">
|
||||
<Message Text="IsWindows $(IsWindows)" Importance="high" />
|
||||
<Message Text="IsOSX $(IsOSX)" Importance="high" />
|
||||
<Message Text="IsLinux $(IsLinux)" Importance="high" />
|
||||
<Message Text="ForceLinuxBuild $(ForceLinuxBuild)" Importance="high" />
|
||||
</Target>
|
||||
<Choose>
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="BasicTemplateAlgorithm.fs" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
<Project>{3240aca4-bdd4-4d24-ac36-bbb651c39212}</Project>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Name>QuantConnect</Name>
|
||||
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '11.0'">
|
||||
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
|
||||
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
|
||||
</PropertyGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
|
||||
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
|
||||
</PropertyGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<Import Project="$(FSharpTargetsPath)" />
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="NodaTime" version="1.3.4" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -1,76 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{75981418-7246-4B91-B136-482728E02901}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuantConnect.Algorithm.Framework</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm.Framework</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<DocumentationFile>bin\$(Configuration)\QuantConnect.Algorithm.Framework.xml</DocumentationFile>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<PackageTags>Library</PackageTags>
|
||||
<LangVersion>6</LangVersion>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<DocumentationFile>bin\Debug\QuantConnect.Algorithm.Framework.xml</DocumentationFile>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\QuantConnect.Algorithm.Framework.xml</DocumentationFile>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Accord, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.3.6.0\lib\net462\Accord.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Math, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Math.3.6.0\lib\net462\Accord.Math.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Math.Core, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Math.3.6.0\lib\net462\Accord.Math.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Accord.Statistics, Version=3.6.0.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Accord.Statistics.3.6.0\lib\net462\Accord.Statistics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MathNet.Numerics, Version=3.19.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MathNet.Numerics.3.19.0\lib\net40\MathNet.Numerics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NodaTime.1.3.4\lib\net35-Client\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
@@ -85,94 +41,59 @@
|
||||
<Message Text="IsLinux $(IsLinux)" Importance="high" />
|
||||
<Message Text="ForceLinuxBuild $(ForceLinuxBuild)" Importance="high" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Accord" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Math" Version="3.6.0" />
|
||||
<PackageReference Include="Accord.Statistics" Version="3.6.0" />
|
||||
<PackageReference Include="MathNet.Numerics" Version="3.19.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers" Version="2.10.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="NodaTime" Version="3.0.5" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="1.0.5.30" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Alphas\PearsonCorrelationPairsTradingAlphaModel.cs" />
|
||||
<Compile Include="Alphas\EmaCrossAlphaModel.cs" />
|
||||
<Compile Include="Alphas\BasePairsTradingAlphaModel.cs" />
|
||||
<Compile Include="Alphas\RsiAlphaModel.cs" />
|
||||
<Compile Include="Execution\StandardDeviationExecutionModel.cs" />
|
||||
<Compile Include="Execution\VolumeWeightedAveragePriceExecutionModel.cs" />
|
||||
<Compile Include="NotifiedSecurityChanges.cs" />
|
||||
<Compile Include="Portfolio\BlackLittermanOptimizationPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\ConfidenceWeightedPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\SectorWeightingPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\InsightWeightingPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\UnconstrainedMeanVariancePortfolioOptimizer.cs" />
|
||||
<Compile Include="Portfolio\MaximumSharpeRatioPortfolioOptimizer.cs" />
|
||||
<Compile Include="Portfolio\MeanVarianceOptimizationPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\MinimumVariancePortfolioOptimizer.cs" />
|
||||
<Compile Include="Portfolio\EqualWeightingPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\AccumulativeInsightPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\ReturnsSymbolData.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Risk\MaximumDrawdownPercentPortfolio.cs" />
|
||||
<Compile Include="Risk\MaximumDrawdownPercentPerSecurity.cs" />
|
||||
<Compile Include="Risk\MaximumSectorExposureRiskManagementModel.cs" />
|
||||
<Compile Include="Risk\MaximumUnrealizedProfitPercentPerSecurity.cs" />
|
||||
<Compile Include="Risk\TrailingStopRiskManagementModel.cs" />
|
||||
<Compile Include="Selection\CoarseFundamentalUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\LiquidETFUniverse.cs" />
|
||||
<Compile Include="Selection\FineFundamentalUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\FundamentalUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\EmaCrossUniverseSelectionModel.cs" />
|
||||
<Compile Include="Alphas\ConstantAlphaModel.cs" />
|
||||
<Compile Include="Alphas\MacdAlphaModel.cs" />
|
||||
<Compile Include="Selection\FutureUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\OpenInterestFutureUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\OptionUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\ScheduledUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\QC500UniverseSelectionModel.cs" />
|
||||
<Compile Include="Alphas\HistoricalReturnsAlphaModel.cs" />
|
||||
<Compile Include="Selection\InceptionDateUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\EnergyETFUniverse.cs" />
|
||||
<Compile Include="Selection\MetalsETFUniverse.cs" />
|
||||
<Compile Include="Selection\SP500SectorsETFUniverse.cs" />
|
||||
<Compile Include="Selection\TechnologyETFUniverse.cs" />
|
||||
<Compile Include="Selection\USTreasuriesETFUniverse.cs" />
|
||||
<Compile Include="Selection\VolatilityETFUniverse.cs" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Project>{3240ACA4-BDD4-4D24-AC36-BBB651C39212}</Project>
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545C0B4-FABB-49C9-8DD1-9AD7EE23F86B}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
</ProjectReference>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj" />
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj" />
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<Content Include="Portfolio\BlackLittermanOptimizationPortfolioConstructionModel.py">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@@ -268,29 +189,4 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Humanizer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Accord.3.6.0\build\Accord.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Accord.3.6.0\build\Accord.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\Accord.3.6.0\build\Accord.targets" Condition="Exists('..\packages\Accord.3.6.0\build\Accord.targets')" />
|
||||
</Project>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Accord" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.Math" version="3.6.0" targetFramework="net462" />
|
||||
<package id="Accord.Statistics" version="3.6.0" targetFramework="net462" />
|
||||
<package id="MathNet.Numerics" version="3.19.0" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="NodaTime" version="1.3.4" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -0,0 +1,111 @@
|
||||
### QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
### Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
###
|
||||
### Licensed under the Apache License, Version 2.0 (the "License");
|
||||
### you may not use this file except in compliance with the License.
|
||||
### You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
###
|
||||
### Unless required by applicable law or agreed to in writing, software
|
||||
### distributed under the License is distributed on an "AS IS" BASIS,
|
||||
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
### See the License for the specific language governing permissions and
|
||||
### limitations under the License.
|
||||
|
||||
from datetime import date
|
||||
|
||||
import QuantConnect
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Brokerages import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Data.Shortable import *
|
||||
from QuantConnect.Data.UniverseSelection import *
|
||||
from QuantConnect.Interfaces import *
|
||||
from QuantConnect import *
|
||||
|
||||
|
||||
class AllShortableSymbolsRegressionAlgorithmBrokerageModel(DefaultBrokerageModel):
|
||||
def __init__(self):
|
||||
self.ShortableProvider = LocalDiskShortableProvider(SecurityType.Equity, "testbrokerage", Market.USA)
|
||||
|
||||
### <summary>
|
||||
### Tests filtering in coarse selection by shortable quantity
|
||||
### </summary>
|
||||
class AllShortableSymbolsCoarseSelectionRegressionAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
self._20140325 = date(2014, 3, 25);
|
||||
self._20140326 = date(2014, 3, 26);
|
||||
self._20140327 = date(2014, 3, 27);
|
||||
self._20140328 = date(2014, 3, 28);
|
||||
self._20140329 = date(2014, 3, 29);
|
||||
|
||||
self.aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
self.bac = QuantConnect.Symbol.Create("BAC", SecurityType.Equity, Market.USA);
|
||||
self.gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
|
||||
self.goog = QuantConnect.Symbol.Create("GOOG", SecurityType.Equity, Market.USA);
|
||||
self.qqq = QuantConnect.Symbol.Create("QQQ", SecurityType.Equity, Market.USA);
|
||||
self.spy = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
self.lastTradeDate = date(1, 1, 1);
|
||||
|
||||
self.coarseSelected = {
|
||||
self._20140325: False,
|
||||
self._20140326: False,
|
||||
self._20140327: False,
|
||||
self._20140328: False
|
||||
}
|
||||
|
||||
self.expectedSymbols = {
|
||||
self._20140325: [self.bac, self.qqq, self.spy],
|
||||
self._20140326: [self.spy],
|
||||
self._20140327: [self.aapl, self.bac, self.gme, self.qqq, self.spy],
|
||||
self._20140328: [self.goog],
|
||||
self._20140329: []
|
||||
}
|
||||
|
||||
self.SetStartDate(2014, 3, 25);
|
||||
self.SetEndDate(2014, 3, 29);
|
||||
self.SetCash(10000000);
|
||||
|
||||
self.AddUniverse(self.CoarseSelectionFunc);
|
||||
self.UniverseSettings.Resolution = QuantConnect.Resolution.Daily;
|
||||
|
||||
self.SetBrokerageModel(AllShortableSymbolsRegressionAlgorithmBrokerageModel());
|
||||
|
||||
def OnData(self, data):
|
||||
if self.Time.date() == self.lastTradeDate:
|
||||
return
|
||||
|
||||
for symbol in self.ActiveSecurities.Keys:
|
||||
if not symbol in self.Portfolio or not self.Portfolio[symbol].Invested:
|
||||
if not self.Shortable(symbol):
|
||||
raise Exception(f"Expected {symbol} to be shortable on {self.Time}")
|
||||
|
||||
# Buy at least once into all Symbols. Since daily data will always use
|
||||
# MOO orders, it makes the testing of liquidating buying into Symbols difficult
|
||||
self.MarketOrder(symbol, -float(self.ShortableQuantity(symbol)))
|
||||
self.lastTradeDate = self.Time.date()
|
||||
|
||||
def CoarseSelectionFunc(self, coarse):
|
||||
shortableSymbols = self.AllShortableSymbols();
|
||||
selectedSymbols = list(sorted([x.Symbol for x in coarse if x.Symbol in shortableSymbols and shortableSymbols[x.Symbol] >= 500]))
|
||||
|
||||
expectedMissing = 0;
|
||||
if self.Time.date() == self._20140327:
|
||||
gme = QuantConnect.Symbol.Create("GME", SecurityType.Equity, Market.USA);
|
||||
if gme not in shortableSymbols:
|
||||
raise Exception("Expected unmapped GME in shortable symbols list on 2014-03-27");
|
||||
if len([x.Symbol.Value for x in coarse if x.Symbol.Value == "GME"]) == 0:
|
||||
raise Exception("Expected mapped GME in coarse symbols on 2014-03-27");
|
||||
|
||||
expectedMissing = 1;
|
||||
|
||||
missing = [i for i in self.expectedSymbols[self.Time.date()] if i not in selectedSymbols]
|
||||
if (len(missing) != expectedMissing):
|
||||
raise Exception(f"Expected Symbols selected on {self.Time.date()} to match expected Symbols, but the following Symbols were missing: {', '.join([str(s) for s in missing])}")
|
||||
|
||||
self.coarseSelected[self.Time.date()] = True;
|
||||
return selectedSymbols
|
||||
|
||||
def OnEndOfAlgorithm(self):
|
||||
if not all(list(self.coarseSelected.values())):
|
||||
raise Exception(f"Expected coarse selection on all dates, but didn't run on: {', '.join([str(k) for k, v in self.coarseSelected.items() if not v])}")
|
||||
@@ -0,0 +1,51 @@
|
||||
# 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.
|
||||
|
||||
from clr import AddReference
|
||||
|
||||
AddReference("System")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
AddReference("QuantConnect.Common")
|
||||
|
||||
from System import *
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
|
||||
# <summary>
|
||||
# Regression algorithm to test the behaviour of ARMA versus AR models at the same order of differencing.
|
||||
# In particular, an ARIMA(1,1,1) and ARIMA(1,1,0) are instantiated while orders are placed if their difference
|
||||
# is sufficiently large (which would be due to the inclusion of the MA(1) term).
|
||||
# </summary>
|
||||
class AutoRegressiveIntegratedMovingAverageRegressionAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
|
||||
self.SetStartDate(2013, 1, 7)
|
||||
self.SetEndDate(2013, 12, 11)
|
||||
self.EnableAutomaticIndicatorWarmUp = True
|
||||
self.AddEquity("SPY", Resolution.Daily)
|
||||
self.arima = self.ARIMA("SPY", 1, 1, 1, 50)
|
||||
self.ar = self.ARIMA("SPY", 1, 1, 0, 50)
|
||||
|
||||
def OnData(self, data):
|
||||
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
|
||||
Arguments:
|
||||
data: Slice object keyed by symbol containing the stock data
|
||||
'''
|
||||
if self.arima.IsReady:
|
||||
if abs(self.arima.Current.Value - self.ar.Current.Value) > 1:
|
||||
if self.arima.Current.Value > self.last:
|
||||
self.MarketOrder("SPY", 1)
|
||||
else:
|
||||
self.MarketOrder("SPY", -1)
|
||||
self.last = self.arima.Current.Value
|
||||
@@ -35,7 +35,11 @@ class CustomBenchmarkAlgorithm(QCAlgorithm):
|
||||
self.SetCash(100000) #Set Strategy Cash
|
||||
# Find more symbols here: http://quantconnect.com/data
|
||||
self.AddEquity("SPY", Resolution.Second)
|
||||
|
||||
|
||||
# Disabling the benchmark / setting to a fixed value
|
||||
# self.SetBenchmark(lambda x: 0)
|
||||
|
||||
# Set the benchmark to AAPL US Equity
|
||||
self.SetBenchmark(Symbol.Create("AAPL", SecurityType.Equity, Market.USA))
|
||||
|
||||
def OnData(self, data):
|
||||
@@ -46,4 +50,4 @@ class CustomBenchmarkAlgorithm(QCAlgorithm):
|
||||
|
||||
tupleResult = SymbolCache.TryGetSymbol("AAPL", None)
|
||||
if tupleResult[0]:
|
||||
raise Exception("Benchmark Symbol is not expected to be added to the Symbol cache")
|
||||
raise Exception("Benchmark Symbol is not expected to be added to the Symbol cache")
|
||||
|
||||
140
Algorithm.Python/CustomDataPropertiesRegressionAlgorithm.py
Normal file
140
Algorithm.Python/CustomDataPropertiesRegressionAlgorithm.py
Normal file
@@ -0,0 +1,140 @@
|
||||
# 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.
|
||||
|
||||
from clr import AddReference
|
||||
AddReference("System.Core")
|
||||
AddReference("QuantConnect.Common")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
AddReference("QuantConnect.Algorithm.Framework")
|
||||
|
||||
from System import *
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Algorithm.Framework import *
|
||||
from QuantConnect.Data import SubscriptionDataSource
|
||||
from QuantConnect.Python import PythonData
|
||||
from QuantConnect.Securities import *
|
||||
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
### <summary>
|
||||
### Regression test to demonstrate setting custom Symbol Properties and Market Hours for a custom data import
|
||||
### </summary>
|
||||
### <meta name="tag" content="using data" />
|
||||
### <meta name="tag" content="importing data" />
|
||||
### <meta name="tag" content="custom data" />
|
||||
### <meta name="tag" content="crypto" />
|
||||
### <meta name="tag" content="regression test" />
|
||||
class CustomDataPropertiesRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetStartDate(2011,9,13) # Set Start Date
|
||||
self.SetEndDate(2015,12,1) # Set End Date
|
||||
self.SetCash(100000) # Set Strategy Cash
|
||||
|
||||
# Define our custom data properties and exchange hours
|
||||
self.ticker = 'BTC'
|
||||
properties = SymbolProperties("Bitcoin", "USD", 1, 0.01, 0.01, self.ticker)
|
||||
exchangeHours = SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork)
|
||||
|
||||
# Add the custom data to our algorithm with our custom properties and exchange hours
|
||||
self.bitcoin = self.AddData(Bitcoin, self.ticker, properties, exchangeHours)
|
||||
|
||||
# Verify our symbol properties were changed and loaded into this security
|
||||
if self.bitcoin.SymbolProperties != properties :
|
||||
raise Exception("Failed to set and retrieve custom SymbolProperties for BTC")
|
||||
|
||||
# Verify our exchange hours were changed and loaded into this security
|
||||
if self.bitcoin.Exchange.Hours != exchangeHours :
|
||||
raise Exception("Failed to set and retrieve custom ExchangeHours for BTC")
|
||||
|
||||
# For regression purposes on AddData overloads, this call is simply to ensure Lean can accept this
|
||||
# with default params and is not routed to a breaking function.
|
||||
self.AddData(Bitcoin, "BTCUSD");
|
||||
|
||||
|
||||
def OnData(self, data):
|
||||
if not self.Portfolio.Invested:
|
||||
if data['BTC'].Close != 0 :
|
||||
self.Order('BTC', self.Portfolio.MarginRemaining/abs(data['BTC'].Close + 1))
|
||||
|
||||
def OnEndOfAlgorithm(self):
|
||||
#Reset our Symbol property value, for testing purposes.
|
||||
self.SymbolPropertiesDatabase.SetEntry(Market.USA, self.MarketHoursDatabase.GetDatabaseSymbolKey(self.bitcoin.Symbol), SecurityType.Base,
|
||||
SymbolProperties.GetDefault("USD"));
|
||||
|
||||
|
||||
|
||||
class Bitcoin(PythonData):
|
||||
'''Custom Data Type: Bitcoin data from Quandl - http://www.quandl.com/help/api-for-bitcoin-data'''
|
||||
|
||||
def GetSource(self, config, date, isLiveMode):
|
||||
if isLiveMode:
|
||||
return SubscriptionDataSource("https://www.bitstamp.net/api/ticker/", SubscriptionTransportMedium.Rest)
|
||||
|
||||
#return "http://my-ftp-server.com/futures-data-" + date.ToString("Ymd") + ".zip"
|
||||
# OR simply return a fixed small data file. Large files will slow down your backtest
|
||||
return SubscriptionDataSource("https://www.quantconnect.com/api/v2/proxy/quandl/api/v3/datasets/BCHARTS/BITSTAMPUSD.csv?order=asc&api_key=WyAazVXnq7ATy_fefTqm", SubscriptionTransportMedium.RemoteFile)
|
||||
|
||||
|
||||
def Reader(self, config, line, date, isLiveMode):
|
||||
coin = Bitcoin()
|
||||
coin.Symbol = config.Symbol
|
||||
|
||||
if isLiveMode:
|
||||
# Example Line Format:
|
||||
# {"high": "441.00", "last": "421.86", "timestamp": "1411606877", "bid": "421.96", "vwap": "428.58", "volume": "14120.40683975", "low": "418.83", "ask": "421.99"}
|
||||
try:
|
||||
liveBTC = json.loads(line)
|
||||
|
||||
# If value is zero, return None
|
||||
value = liveBTC["last"]
|
||||
if value == 0: return None
|
||||
|
||||
coin.Time = datetime.now()
|
||||
coin.Value = value
|
||||
coin["Open"] = float(liveBTC["open"])
|
||||
coin["High"] = float(liveBTC["high"])
|
||||
coin["Low"] = float(liveBTC["low"])
|
||||
coin["Close"] = float(liveBTC["last"])
|
||||
coin["Ask"] = float(liveBTC["ask"])
|
||||
coin["Bid"] = float(liveBTC["bid"])
|
||||
coin["VolumeBTC"] = float(liveBTC["volume"])
|
||||
coin["WeightedPrice"] = float(liveBTC["vwap"])
|
||||
return coin
|
||||
except ValueError:
|
||||
# Do nothing, possible error in json decoding
|
||||
return None
|
||||
|
||||
# Example Line Format:
|
||||
# Date Open High Low Close Volume (BTC) Volume (Currency) Weighted Price
|
||||
# 2011-09-13 5.8 6.0 5.65 5.97 58.37138238, 346.0973893944 5.929230648356
|
||||
if not (line.strip() and line[0].isdigit()): return None
|
||||
|
||||
try:
|
||||
data = line.split(',')
|
||||
coin.Time = datetime.strptime(data[0], "%Y-%m-%d")
|
||||
coin.Value = float(data[4])
|
||||
coin["Open"] = float(data[1])
|
||||
coin["High"] = float(data[2])
|
||||
coin["Low"] = float(data[3])
|
||||
coin["Close"] = float(data[4])
|
||||
coin["VolumeBTC"] = float(data[5])
|
||||
coin["VolumeUSD"] = float(data[6])
|
||||
coin["WeightedPrice"] = float(data[7])
|
||||
return coin
|
||||
|
||||
except ValueError:
|
||||
# Do nothing, possible error in json decoding
|
||||
return None
|
||||
@@ -39,7 +39,7 @@ class DelistingEventsAlgorithm(QCAlgorithm):
|
||||
self.SetEndDate(2007, 5, 25) #Set End Date
|
||||
self.SetCash(100000) #Set Strategy Cash
|
||||
# Find more symbols here: http://quantconnect.com/data
|
||||
self.AddEquity("AAA", Resolution.Daily)
|
||||
self.AddEquity("AAA.1", Resolution.Daily)
|
||||
self.AddEquity("SPY", Resolution.Daily)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class DelistingEventsAlgorithm(QCAlgorithm):
|
||||
data: Slice object keyed by symbol containing the stock data
|
||||
'''
|
||||
if self.Transactions.OrdersCount == 0:
|
||||
self.SetHoldings("AAA", 1)
|
||||
self.SetHoldings("AAA.1", 1)
|
||||
self.Debug("Purchased stock")
|
||||
|
||||
for kvp in data.Bars:
|
||||
@@ -61,7 +61,7 @@ class DelistingEventsAlgorithm(QCAlgorithm):
|
||||
|
||||
# the slice can also contain delisting data: data.Delistings in a dictionary string->Delisting
|
||||
|
||||
aaa = self.Securities["AAA"]
|
||||
aaa = self.Securities["AAA.1"]
|
||||
if aaa.IsDelisted and aaa.IsTradable:
|
||||
raise Exception("Delisted security must NOT be tradable")
|
||||
|
||||
|
||||
@@ -46,11 +46,6 @@ class FutureOptionBuySellCallIntradayRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es20h20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -43,11 +43,6 @@ class FutureOptionCallITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -102,12 +97,7 @@ class FutureOptionCallITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.Log(f"{self.Time} -- {orderEvent.Symbol} :: Price: {self.Securities[orderEvent.Symbol].Holdings.Price} Qty: {self.Securities[orderEvent.Symbol].Holdings.Quantity} Direction: {orderEvent.Direction} Msg: {orderEvent.Message}")
|
||||
|
||||
def AssertFutureOptionOrderExercise(self, orderEvent: OrderEvent, future: Security, optionContract: Security):
|
||||
# We expect the liquidation to occur on the day of the delisting (while the market is open),
|
||||
# but currently we liquidate at the next market open (AAPL open) which happens to be
|
||||
# at 9:30:00 Eastern Time. For unknown reasons, the delisting happens two minutes after the
|
||||
# market open.
|
||||
# Read more about the issue affecting this test here: https://github.com/QuantConnect/Lean/issues/4980
|
||||
expectedLiquidationTimeUtc = datetime(2020, 6, 22, 13, 32, 0)
|
||||
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 20, 0, 0)
|
||||
|
||||
if orderEvent.Direction == OrderDirection.Sell and future.Holdings.Quantity != 0:
|
||||
# We expect the contract to have been liquidated immediately
|
||||
|
||||
@@ -28,11 +28,13 @@ from QuantConnect import Market
|
||||
|
||||
### <summary>
|
||||
### This regression algorithm tests Out of The Money (OTM) future option expiry for calls.
|
||||
### We expect 1 order from the algorithm, which are:
|
||||
### We expect 2 orders from the algorithm, which are:
|
||||
###
|
||||
### * Initial entry, buy ES Call Option (expiring OTM)
|
||||
### - contract expires worthless, not exercised, so never opened a position in the underlying
|
||||
###
|
||||
### * Liquidation of worthless ES call option (expiring OTM)
|
||||
###
|
||||
### Additionally, we test delistings for future options and assert that our
|
||||
### portfolio holdings reflect the orders the algorithm has submitted.
|
||||
### </summary>
|
||||
@@ -45,11 +47,6 @@ class FutureOptionCallOTMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
### 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.
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from System import *
|
||||
from System.Reflection import *
|
||||
import QuantConnect
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Data.Market import *
|
||||
from QuantConnect.Orders import *
|
||||
from QuantConnect.Securities import *
|
||||
from QuantConnect.Securities.Future import *
|
||||
from QuantConnect import Market
|
||||
|
||||
### <summary>
|
||||
### This regression test tests for the loading of futures options contracts with a contract month of 2020-03 can live
|
||||
### and be loaded from the same ZIP file that the 2020-04 contract month Future Option contract lives in.
|
||||
### </summary>
|
||||
class FutureOptionMultipleContractsInDifferentContractMonthsWithSameUnderlyingFutureRegressionAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
self.expectedSymbols = {
|
||||
self._createOption(datetime(2020, 3, 26), OptionRight.Call, 1650.0): False,
|
||||
self._createOption(datetime(2020, 3, 26), OptionRight.Put, 1540.0): False,
|
||||
self._createOption(datetime(2020, 2, 25), OptionRight.Call, 1600.0): False,
|
||||
self._createOption(datetime(2020, 2, 25), OptionRight.Put, 1545.0): False
|
||||
}
|
||||
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 1, 6)
|
||||
|
||||
goldFutures = self.AddFuture("GC", Resolution.Minute, QuantConnect.Market.COMEX)
|
||||
goldFutures.SetFilter(0, 365)
|
||||
|
||||
self.AddFutureOption(goldFutures.Symbol)
|
||||
|
||||
def OnData(self, data: Slice):
|
||||
for symbol in data.QuoteBars.Keys:
|
||||
if symbol in self.expectedSymbols:
|
||||
invested = self.expectedSymbols[symbol]
|
||||
if not invested:
|
||||
self.MarketOrder(symbol, 1)
|
||||
|
||||
self.expectedSymbols[symbol] = True
|
||||
|
||||
def OnEndOfAlgorithm(self):
|
||||
notEncountered = [str(k) for k,v in self.expectedSymbols.items() if not v]
|
||||
if any(notEncountered):
|
||||
raise AggregateException(f"Expected all Symbols encountered and invested in, but the following were not found: {', '.join(notEncountered)}")
|
||||
|
||||
if not self.Portfolio.Invested:
|
||||
raise AggregateException("Expected holdings at the end of algorithm, but none were found.")
|
||||
|
||||
|
||||
def _createOption(self, expiry: datetime, optionRight: OptionRight, strikePrice: float) -> Symbol:
|
||||
return QuantConnect.Symbol.CreateOption(
|
||||
QuantConnect.Symbol.CreateFuture("GC", QuantConnect.Market.COMEX, datetime(2020, 4, 28)),
|
||||
QuantConnect.Market.COMEX,
|
||||
OptionStyle.American,
|
||||
optionRight,
|
||||
strikePrice,
|
||||
expiry
|
||||
)
|
||||
@@ -42,11 +42,6 @@ class FutureOptionPutITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
@@ -101,12 +96,7 @@ class FutureOptionPutITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.Log(f"{self.Time} -- {orderEvent.Symbol} :: Price: {self.Securities[orderEvent.Symbol].Holdings.Price} Qty: {self.Securities[orderEvent.Symbol].Holdings.Quantity} Direction: {orderEvent.Direction} Msg: {orderEvent.Message}")
|
||||
|
||||
def AssertFutureOptionOrderExercise(self, orderEvent: OrderEvent, future: Security, optionContract: Security):
|
||||
# We expect the liquidation to occur on the day of the delisting (while the market is open),
|
||||
# but currently we liquidate at the next market open (AAPL open) which happens to be
|
||||
# at 9:30:00 Eastern Time. For unknown reasons, the delisting happens two minutes after the
|
||||
# market open.
|
||||
# Read more about the issue affecting this test here: https://github.com/QuantConnect/Lean/issues/4980
|
||||
expectedLiquidationTimeUtc = datetime(2020, 6, 22, 13, 32, 0)
|
||||
expectedLiquidationTimeUtc = datetime(2020, 6, 19, 20, 0, 0)
|
||||
|
||||
if orderEvent.Direction == OrderDirection.Buy and future.Holdings.Quantity != 0:
|
||||
# We expect the contract to have been liquidated immediately
|
||||
|
||||
@@ -28,10 +28,12 @@ from QuantConnect import Market
|
||||
|
||||
### <summary>
|
||||
### This regression algorithm tests Out of The Money (OTM) future option expiry for puts.
|
||||
### We expect 1 order from the algorithm, which are:
|
||||
### We expect 2 orders from the algorithm, which are:
|
||||
###
|
||||
### * Initial entry, buy ES Put Option (expiring OTM)
|
||||
### - contract expires worthless, not exercised, so never opened a position in the underlying
|
||||
###
|
||||
### * Liquidation of worthless ES Put OTM contract
|
||||
###
|
||||
### Additionally, we test delistings for future options and assert that our
|
||||
### portfolio holdings reflect the orders the algorithm has submitted.
|
||||
@@ -44,11 +46,6 @@ class FutureOptionPutOTMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -42,11 +42,6 @@ class FutureOptionShortCallITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -28,11 +28,13 @@ from QuantConnect import Market
|
||||
|
||||
### <summary>
|
||||
### This regression algorithm tests Out of The Money (OTM) future option expiry for short calls.
|
||||
### We expect 1 order from the algorithm, which are:
|
||||
### We expect 2 orders from the algorithm, which are:
|
||||
###
|
||||
### * Initial entry, sell ES Call Option (expiring OTM)
|
||||
### - Profit the option premium, since the option was not assigned.
|
||||
###
|
||||
### * Liquidation of ES call OTM contract on the last trade date
|
||||
###
|
||||
### Additionally, we test delistings for future options and assert that our
|
||||
### portfolio holdings reflect the orders the algorithm has submitted.
|
||||
### </summary>
|
||||
@@ -41,11 +43,6 @@ class FutureOptionShortCallOTMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -42,11 +42,6 @@ class FutureOptionShortPutITMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -28,11 +28,13 @@ from QuantConnect import Market
|
||||
|
||||
### <summary>
|
||||
### This regression algorithm tests Out of The Money (OTM) future option expiry for short puts.
|
||||
### We expect 1 order from the algorithm, which are:
|
||||
### We expect 2 orders from the algorithm, which are:
|
||||
###
|
||||
### * Initial entry, sell ES Put Option (expiring OTM)
|
||||
### - Profit the option premium, since the option was not assigned.
|
||||
###
|
||||
### * Liquidation of ES put OTM contract on the last trade date
|
||||
###
|
||||
### Additionally, we test delistings for future options and assert that our
|
||||
### portfolio holdings reflect the orders the algorithm has submitted.
|
||||
### </summary>
|
||||
@@ -41,11 +43,6 @@ class FutureOptionShortPutOTMExpiryRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 6, 30)
|
||||
|
||||
# We add AAPL as a temporary workaround for https://github.com/QuantConnect/Lean/issues/4872
|
||||
# which causes delisting events to never be processed, thus leading to options that might never
|
||||
# be exercised until the next data point arrives.
|
||||
self.AddEquity("AAPL", Resolution.Daily)
|
||||
|
||||
self.es19m20 = self.AddFutureContract(
|
||||
Symbol.CreateFuture(
|
||||
Futures.Indices.SP500EMini,
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Data.Market import *
|
||||
from QuantConnect.Orders import *
|
||||
from QuantConnect import *
|
||||
|
||||
### <summary>
|
||||
### Tests delistings for Futures and Futures Options to ensure that they are delisted at the expected times.
|
||||
### </summary>
|
||||
class FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
self.invested = False
|
||||
self.liquidated = 0
|
||||
self.delistingsReceived = 0
|
||||
|
||||
self.expectedExpiryWarningTime = datetime(2020, 6, 19)
|
||||
self.expectedExpiryDelistingTime = datetime(2020, 6, 20)
|
||||
self.expectedLiquidationTime = datetime(2020, 6, 19, 16, 0, 0)
|
||||
|
||||
self.SetStartDate(2020, 1, 5)
|
||||
self.SetEndDate(2020, 12, 1)
|
||||
self.SetCash(100000)
|
||||
|
||||
es = Symbol.CreateFuture(
|
||||
"ES",
|
||||
Market.CME,
|
||||
datetime(2020, 6, 19)
|
||||
)
|
||||
|
||||
esOption = Symbol.CreateOption(
|
||||
es,
|
||||
Market.CME,
|
||||
OptionStyle.American,
|
||||
OptionRight.Put,
|
||||
3400.0,
|
||||
datetime(2020, 6, 19)
|
||||
)
|
||||
|
||||
self.esFuture = self.AddFutureContract(es, Resolution.Minute).Symbol
|
||||
self.esFutureOption = self.AddFutureOptionContract(esOption, Resolution.Minute).Symbol
|
||||
|
||||
def OnData(self, data: Slice):
|
||||
for delisting in data.Delistings.Values:
|
||||
self.delistingsReceived += 1
|
||||
|
||||
if delisting.Type == DelistingType.Warning and delisting.Time != self.expectedExpiryWarningTime:
|
||||
raise AssertionError(f"Expiry warning with time {delisting.Time} but is expected to be {self.expectedExpiryWarningTime}")
|
||||
|
||||
if delisting.Type == DelistingType.Warning and delisting.Time != datetime(self.Time.year, self.Time.month, self.Time.day):
|
||||
raise AssertionError(f"Delisting warning received at an unexpected date: {self.Time} - expected {delisting.Time}")
|
||||
|
||||
if delisting.Type == DelistingType.Delisted and delisting.Time != self.expectedExpiryDelistingTime:
|
||||
raise AssertionError(f"Delisting occurred at unexpected time: {delisting.Time} - expected: {self.expectedExpiryDelistingTime}")
|
||||
|
||||
if delisting.Type == DelistingType.Delisted and delisting.Time != datetime(self.Time.year, self.Time.month, self.Time.day):
|
||||
raise AssertionError(f"Delisting notice received at an unexpected date: {self.Time} - expected {delisting.Time}")
|
||||
|
||||
if not self.invested and \
|
||||
(self.esFuture in data.Bars or self.esFuture in data.QuoteBars) and \
|
||||
(self.esFutureOption in data.Bars or self.esFutureOption in data.QuoteBars):
|
||||
|
||||
self.invested = True
|
||||
|
||||
self.MarketOrder(self.esFuture, 1)
|
||||
self.MarketOrder(self.esFutureOption, 1)
|
||||
|
||||
def OnOrderEvent(self, orderEvent: OrderEvent):
|
||||
if orderEvent.Direction != OrderDirection.Sell or orderEvent.Status != OrderStatus.Filled:
|
||||
return
|
||||
|
||||
# * Future Liquidation
|
||||
# * Future Option Exercise
|
||||
# * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven
|
||||
self.liquidated += 1
|
||||
if orderEvent.Symbol.SecurityType == SecurityType.FutureOption and self.expectedLiquidationTime != self.Time:
|
||||
raise AssertionError(f"Expected to liquidate option {orderEvent.Symbol} at {self.expectedLiquidationTime}, instead liquidated at {self.Time}")
|
||||
|
||||
if orderEvent.Symbol.SecurityType == SecurityType.Future and \
|
||||
(self.expectedLiquidationTime - timedelta(minutes=1)) != self.Time and \
|
||||
self.expectedLiquidationTime != self.Time:
|
||||
|
||||
raise AssertionError(f"Expected to liquidate future {orderEvent.Symbol} at {self.expectedLiquidationTime} (+1 minute), instead liquidated at {self.Time}")
|
||||
|
||||
|
||||
def OnEndOfAlgorithm(self):
|
||||
if not self.invested:
|
||||
raise AssertionError("Never invested in ES futures and FOPs")
|
||||
|
||||
if self.delistingsReceived != 4:
|
||||
raise AssertionError(f"Expected 4 delisting events received, found: {self.delistingsReceived}")
|
||||
|
||||
if self.liquidated != 2:
|
||||
raise AssertionError(f"Expected 3 liquidation events, found {self.liquidated}")
|
||||
@@ -34,7 +34,7 @@ class HourReverseSplitRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetCash(100000)
|
||||
self.SetBenchmark(lambda x: 0)
|
||||
|
||||
self.symbol = self.AddEquity("VXX", Resolution.Hour).Symbol
|
||||
self.symbol = self.AddEquity("VXX.1", Resolution.Hour).Symbol
|
||||
|
||||
def OnData(self, slice):
|
||||
if slice.Bars.Count == 0: return
|
||||
|
||||
@@ -33,12 +33,12 @@ class OptionRenameRegressionAlgorithm(QCAlgorithm):
|
||||
self.SetCash(1000000)
|
||||
self.SetStartDate(2013,6,28)
|
||||
self.SetEndDate(2013,7,2)
|
||||
option = self.AddOption("FOXA")
|
||||
option = self.AddOption("TFCFA")
|
||||
|
||||
# set our strike/expiry filter for this option chain
|
||||
option.SetFilter(-1, 1, timedelta(0), timedelta(3650))
|
||||
# use the underlying equity as the benchmark
|
||||
self.SetBenchmark("FOXA")
|
||||
self.SetBenchmark("TFCFA")
|
||||
|
||||
def OnData(self, slice):
|
||||
''' Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
@@ -17,10 +16,8 @@ using System.Runtime.InteropServices;
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("7007a02a-8d01-4a85-84e4-fcd58dc943e2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
|
||||
@@ -1,48 +1,63 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{48289996-CE56-4EDF-B451-4A2B1519EBC3}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuantConnect.Algorithm.Python</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm.Python</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<LangVersion>6</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
<IsOSX>false</IsOSX>
|
||||
<IsOSX Condition="'$(IsWindows)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux>false</IsLinux>
|
||||
<IsLinux Condition="'$(IsWindows)' != 'true' AND '$(IsOSX)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' ">
|
||||
build
|
||||
</PostBuildEvent>
|
||||
<PostBuildEvent Condition="'$(OS)' != 'Windows_NT'">
|
||||
./build.sh
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Target Name="PrintRID" BeforeTargets="Build">
|
||||
<Message Text="IsWindows $(IsWindows)" Importance="high" />
|
||||
<Message Text="IsOSX $(IsOSX)" Importance="high" />
|
||||
<Message Text="IsLinux $(IsLinux)" Importance="high" />
|
||||
<Message Text="ForceLinuxBuild $(ForceLinuxBuild)" Importance="high" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers" Version="2.10.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="1.0.5.30" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AccumulativeInsightPortfolioRegressionAlgorithm.py" />
|
||||
<Content Include="AddAlphaModelAlgorithm.py" />
|
||||
@@ -95,6 +110,7 @@
|
||||
<Content Include="CustomDataAddDataOnSecuritiesChangedRegressionAlgorithm.py" />
|
||||
<Content Include="CustomDataAddDataCoarseSelectionRegressionAlgorithm.py" />
|
||||
<None Include="CustomBuyingPowerModelAlgorithm.py" />
|
||||
<Content Include="CustomDataPropertiesRegressionAlgorithm.py" />
|
||||
<Content Include="DynamicSecurityDataAlgorithm.py" />
|
||||
<Content Include="ConfidenceWeightedFrameworkAlgorithm.py" />
|
||||
<Content Include="ExtendedMarketTradingRegressionAlgorithm.py" />
|
||||
@@ -103,12 +119,14 @@
|
||||
<Content Include="FutureOptionBuySellCallIntradayRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionCallITMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionCallOTMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionMultipleContractsInDifferentContractMonthsWithSameUnderlyingFutureRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionPutITMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionPutOTMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionShortCallITMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionShortCallOTMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionShortPutITMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FutureOptionShortPutOTMExpiryRegressionAlgorithm.py" />
|
||||
<Content Include="FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py" />
|
||||
<Content Include="KerasNeuralNetworkAlgorithm.py" />
|
||||
<Content Include="CustomDataUsingMapFileRegressionAlgorithm.py" />
|
||||
<Content Include="LiquidETFUniverseFrameworkAlgorithm.py" />
|
||||
@@ -120,6 +138,7 @@
|
||||
<Content Include="RegisterIndicatorRegressionAlgorithm.py" />
|
||||
<Content Include="SectorWeightingFrameworkAlgorithm.py" />
|
||||
<Content Include="SetHoldingsMultipleTargetsRegressionAlgorithm.py" />
|
||||
<Content Include="ShortableProviderOrdersRejectedRegressionAlgorithm.py" />
|
||||
<Content Include="SliceGetByTypeRegressionAlgorithm.py" />
|
||||
<Content Include="StringToSymbolImplicitConversionRegressionAlgorithm.py" />
|
||||
<Content Include="TalibIndicatorsAlgorithm.py" />
|
||||
@@ -142,20 +161,15 @@
|
||||
<Content Include="ExpiryHelperAlphaModelFrameworkAlgorithm.py" />
|
||||
<Content Include="BasicTemplateFuturesFrameworkAlgorithm.py" />
|
||||
<Content Include="BasicTemplateOptionsFrameworkAlgorithm.py" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Content Include="InsightWeightingFrameworkAlgorithm.py" />
|
||||
<None Include="CompositeRiskManagementModelFrameworkAlgorithm.py" />
|
||||
<None Include="BlackLittermanPortfolioOptimizationFrameworkAlgorithm.py" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="TensorFlowNeuralNetworkAlgorithm.py" />
|
||||
<None Include="TiingoPriceAlgorithm.py" />
|
||||
<None Include="PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="AddRemoveSecurityRegressionAlgorithm.py" />
|
||||
<None Include="app.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="BasicTemplateAlgorithm.py" />
|
||||
<None Include="BasicTemplateCryptoAlgorithm.py" />
|
||||
<None Include="BasicTemplateDailyAlgorithm.py" />
|
||||
@@ -267,18 +281,9 @@
|
||||
<None Include="Benchmarks\ScheduledEventsBenchmark.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Project>{3240aca4-bdd4-4d24-ac36-bbb651c39212}</Project>
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj" />
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj" />
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ConvertToFrameworkAlgorithm.py" />
|
||||
@@ -286,54 +291,29 @@
|
||||
<ItemGroup>
|
||||
<None Include="OptionDataNullReferenceRegressionAlgorithm.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Humanizer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
<IsOSX>false</IsOSX>
|
||||
<IsOSX Condition="'$(IsWindows)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux>false</IsLinux>
|
||||
<IsLinux Condition="'$(IsWindows)' != 'true' AND '$(IsOSX)' != 'true' AND '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<Target Name="PrintRID" BeforeTargets="Build">
|
||||
<Message Text="IsWindows $(IsWindows)" Importance="high" />
|
||||
<Message Text="IsOSX $(IsOSX)" Importance="high" />
|
||||
<Message Text="IsLinux $(IsLinux)" Importance="high" />
|
||||
<Message Text="ForceLinuxBuild $(ForceLinuxBuild)" Importance="high" />
|
||||
</Target>
|
||||
<Choose>
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent Condition="'$(OS)' == 'Windows_NT' ">
|
||||
build
|
||||
@@ -342,23 +322,4 @@
|
||||
./build.sh
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
### QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
### Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
###
|
||||
### Licensed under the Apache License, Version 2.0 (the "License");
|
||||
### you may not use this file except in compliance with the License.
|
||||
### You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
###
|
||||
### Unless required by applicable law or agreed to in writing, software
|
||||
### distributed under the License is distributed on an "AS IS" BASIS,
|
||||
### WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
### See the License for the specific language governing permissions and
|
||||
### limitations under the License.
|
||||
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import *
|
||||
from QuantConnect.Brokerages import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Data.Shortable import *
|
||||
from QuantConnect.Interfaces import *
|
||||
from QuantConnect.Orders import *
|
||||
|
||||
class RegressionTestShortableBrokerageModel(DefaultBrokerageModel):
|
||||
def __init__(self):
|
||||
self.ShortableProvider = LocalDiskShortableProvider(SecurityType.Equity, "testbrokerage", Market.USA)
|
||||
|
||||
### <summary>
|
||||
### Tests that orders are denied if they exceed the max shortable quantity.
|
||||
### </summary>
|
||||
class ShortableProviderOrdersRejectedRegressionAlgorithm(QCAlgorithm):
|
||||
def Initialize(self):
|
||||
self.ordersAllowed = []
|
||||
self.ordersDenied = []
|
||||
self.initialize = False
|
||||
self.invalidatedAllowedOrder = False
|
||||
self.invalidatedNewOrderWithPortfolioHoldings = False
|
||||
|
||||
self.SetStartDate(2013, 10, 4)
|
||||
self.SetEndDate(2013, 10, 11)
|
||||
self.SetCash(10000000)
|
||||
|
||||
self.spy = self.AddEquity("SPY", Resolution.Minute).Symbol
|
||||
self.aig = self.AddEquity("AIG", Resolution.Minute).Symbol
|
||||
|
||||
self.SetBrokerageModel(RegressionTestShortableBrokerageModel())
|
||||
|
||||
def OnData(self, data):
|
||||
if not self.initialize:
|
||||
self.HandleOrder(self.LimitOrder(self.spy, -1001, 10000)) # Should be canceled, exceeds the max shortable quantity
|
||||
self.HandleOrder(self.LimitOrder(self.spy, -1000, 10000)) # Allowed, orders at or below 1000 should be accepted
|
||||
self.HandleOrder(self.LimitOrder(self.spy, -10, 0.01)) # Should be canceled, the total quantity we would be short would exceed the max shortable quantity.
|
||||
self.initialize = True
|
||||
return
|
||||
|
||||
if not self.invalidatedAllowedOrder:
|
||||
if len(self.ordersAllowed) != 1:
|
||||
raise Exception(f"Expected 1 successful order, found: {len(self.ordersAllowed)}")
|
||||
if len(self.ordersDenied) != 2:
|
||||
raise Exception(f"Expected 2 failed orders, found: {len(self.ordersDenied)}")
|
||||
|
||||
allowedOrder = self.ordersAllowed[0]
|
||||
orderUpdate = UpdateOrderFields()
|
||||
orderUpdate.LimitPrice = 0.01
|
||||
orderUpdate.Quantity = -1001
|
||||
orderUpdate.Tag = "Testing updating and exceeding maximum quantity"
|
||||
|
||||
response = allowedOrder.Update(orderUpdate)
|
||||
if response.ErrorCode != OrderResponseErrorCode.ExceedsShortableQuantity:
|
||||
raise Exception(f"Expected order to fail due to exceeded shortable quantity, found: {response.ErrorCode}")
|
||||
|
||||
cancelResponse = allowedOrder.Cancel()
|
||||
if cancelResponse.IsError:
|
||||
raise Exception("Expected to be able to cancel open order after bad qty update")
|
||||
|
||||
self.invalidatedAllowedOrder = True
|
||||
self.ordersDenied.clear()
|
||||
self.ordersAllowed.clear()
|
||||
return
|
||||
|
||||
if not self.invalidatedNewOrderWithPortfolioHoldings:
|
||||
self.HandleOrder(self.MarketOrder(self.spy, -1000)) # Should succeed, no holdings and no open orders to stop this
|
||||
spyShares = self.Portfolio[self.spy].Quantity
|
||||
if spyShares != -1000:
|
||||
raise Exception(f"Expected -1000 shares in portfolio, found: {spyShares}")
|
||||
|
||||
self.HandleOrder(self.LimitOrder(self.spy, -1, 0.01)) # Should fail, portfolio holdings are at the max shortable quantity.
|
||||
if len(self.ordersDenied) != 1:
|
||||
raise Exception(f"Expected limit order to fail due to existing holdings, but found {len(self.ordersDenied)} failures")
|
||||
|
||||
self.ordersAllowed.clear()
|
||||
self.ordersDenied.clear()
|
||||
|
||||
self.HandleOrder(self.MarketOrder(self.aig, -1001))
|
||||
if len(self.ordersAllowed) != 1:
|
||||
raise Exception(f"Expected market order of -1001 BAC to not fail")
|
||||
|
||||
self.invalidatedNewOrderWithPortfolioHoldings = True
|
||||
|
||||
def HandleOrder(self, orderTicket):
|
||||
if orderTicket.SubmitRequest.Status == OrderRequestStatus.Error:
|
||||
self.ordersDenied.append(orderTicket)
|
||||
return
|
||||
|
||||
self.ordersAllowed.append(orderTicket)
|
||||
59
Algorithm.Python/ZeroedBenchmarkRegressionAlgorithm.py
Normal file
59
Algorithm.Python/ZeroedBenchmarkRegressionAlgorithm.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# 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.
|
||||
|
||||
from clr import AddReference
|
||||
AddReference("System.Core")
|
||||
AddReference("QuantConnect.Common")
|
||||
AddReference("QuantConnect.Algorithm")
|
||||
|
||||
from System import *
|
||||
from QuantConnect import *
|
||||
from QuantConnect.Algorithm import QCAlgorithm
|
||||
from QuantConnect.Brokerages import *
|
||||
from QuantConnect.Benchmarks import *
|
||||
from QuantConnect.Data import *
|
||||
from QuantConnect.Securities import *
|
||||
|
||||
### <summary>
|
||||
### Regression algorithm to test zeroed benchmark through BrokerageModel override
|
||||
### </summary>
|
||||
### <meta name="tag" content="regression test" />
|
||||
class ZeroedBenchmarkRegressionAlgorithm(QCAlgorithm):
|
||||
|
||||
def Initialize(self):
|
||||
self.SetCash(100000)
|
||||
self.SetStartDate(2013,10,7)
|
||||
self.SetEndDate(2013,10,8)
|
||||
|
||||
# Add Equity
|
||||
self.AddEquity("SPY", Resolution.Hour)
|
||||
|
||||
# Use our Test Brokerage Model with zerod default benchmark
|
||||
self.SetBrokerageModel(TestBrokerageModel())
|
||||
|
||||
def OnData(self, data):
|
||||
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
|
||||
Arguments:
|
||||
data: Slice object keyed by symbol containing the stock data
|
||||
'''
|
||||
if not self.Portfolio.Invested:
|
||||
self.SetHoldings("SPY", 1)
|
||||
|
||||
class TestBrokerageModel(DefaultBrokerageModel):
|
||||
|
||||
def GetBenchmark(self, securities):
|
||||
return FuncBenchmark(self.func)
|
||||
|
||||
def func(self, datetime):
|
||||
return 0;
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Accord" publicKeyToken="fa1a88e29555ccf7" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -41,12 +41,12 @@ Before we enable python support, follow the [installation instructions](https://
|
||||
2. Install [pandas=0.25.3](https://pandas.pydata.org/) and its [dependencies](https://pandas.pydata.org/pandas-docs/stable/install.html#dependencies).
|
||||
3. Install [wrapt=1.11.2](https://pypi.org/project/wrapt/) module.
|
||||
|
||||
*Note:* If you encounter the "System.DllNotFoundException: python3.6m" runtime error when running Python algorithms on macOS:
|
||||
*Note:* If you encounter the "System.DllNotFoundException: python3.6m" runtime error when running Python algorithms, or generating reports, on macOS:
|
||||
1. Find `libpython3.6m.dylib` in your Python installation folder. If you installed Python with Anaconda, it may be found at
|
||||
```
|
||||
/Users/{your_user_name}/anaconda3/lib/libpython3.6m.dylib
|
||||
```
|
||||
2. Open `Lean/Launcher/bin/Debug/Python.Runtime.dll.config`, add the following text under `<configuration> ... </configuration>` and save:
|
||||
2. Open `Lean/Common/Python/Python.Runtime.dll.config`, add the following text under `<configuration> ... </configuration>` and save:
|
||||
```
|
||||
<dllmap dll="python3.6m" target="{the path in step 1 including libpython3.6m.dylib}" os="osx"/>
|
||||
```
|
||||
@@ -81,7 +81,7 @@ conda install -y wrapt=1.11.2
|
||||
conda create -n qc_environment python=3.6.8 cython=0.29.11 pandas=0.25.3 wrapt=1.11.2
|
||||
|
||||
```
|
||||
2. Open `Lean/Launcher/bin/Debug/Python.Runtime.dll.config`, add the following text under `<configuration> ... </configuration>` and save:
|
||||
2. Open `Lean/Common/Python/Python.Runtime.dll.config`, add the following text under `<configuration> ... </configuration>` and save:
|
||||
```
|
||||
<dllmap dll="python3.6m" target="{the path in step 1 including libpython3.6m.so}" os="linux"/>
|
||||
```
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' General Information about an assembly is controlled through the following
|
||||
' set of attributes. Change these attribute values to modify the information
|
||||
' associated with an assembly.
|
||||
|
||||
' Review the values of the assembly attributes
|
||||
|
||||
<Assembly: AssemblyTitle("QuantConnect.Algorithm.VisualBasic")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("")>
|
||||
<Assembly: AssemblyProduct("QuantConnect.Algorithm.VisualBasic")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2015")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("9a4acee7-b4e5-41a4-9cea-d645ea4e4ede")>
|
||||
|
||||
' Version information for an assembly consists of the following four values:
|
||||
'
|
||||
' Major Version
|
||||
' Minor Version
|
||||
' Build Number
|
||||
' Revision
|
||||
'
|
||||
' You can specify all the values or you can default the Build and Revision Numbers
|
||||
' by using the '*' as shown below:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
' QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
' Lean Algorithmic Trading Engine v2.0. Copyright 2015 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.
|
||||
|
||||
'BasicTemplate Algorithm Class in Visual Basic
|
||||
Imports QuantConnect.Data.Market
|
||||
|
||||
Public Class BasicTemplateAlgorithm
|
||||
Inherits QCAlgorithm
|
||||
|
||||
' Initialize your algorithm
|
||||
Public Overrides Sub Initialize()
|
||||
SetCash(100000)
|
||||
SetStartDate(2013, 10, 7)
|
||||
SetEndDate(2013, 10, 11)
|
||||
AddSecurity(SecurityType.Equity, "SPY", Resolution.Second)
|
||||
End Sub
|
||||
|
||||
' Handle TradeBar Data Eventss
|
||||
Public Sub OnData(data As TradeBars)
|
||||
If Not Portfolio.Invested Then
|
||||
SetHoldings("SPY", 1)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
@@ -1,99 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AF8F124B-B441-4AA7-92B7-CEA72BDB4118}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>QuantConnect.Algorithm.VisualBasic</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm.VisualBasic</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>Windows</MyType>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>QuantConnect.Algorithm.VisualBasic.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>QuantConnect.Algorithm.VisualBasic.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
<Import Include="System.Threading.Tasks" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.vb" />
|
||||
<Compile Include="BasicTemplateAlgorithm.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Project>{3240aca4-bdd4-4d24-ac36-bbb651c39212}</Project>
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Project>{73fb2522-c3ed-4e47-8e3d-afad48a6b888}</Project>
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="My Project\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Alphas.Analysis;
|
||||
@@ -31,6 +32,7 @@ namespace QuantConnect.Algorithm
|
||||
{
|
||||
private readonly ISecurityValuesProvider _securityValuesProvider;
|
||||
private bool _isEmitWarmupInsightWarningSent;
|
||||
private bool _isEmitDelistedInsightWarningSent;
|
||||
|
||||
/// <summary>
|
||||
/// Enables additional logging of framework models including:
|
||||
@@ -111,14 +113,21 @@ namespace QuantConnect.Algorithm
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ukvp.Value.DisposeRequested)
|
||||
{
|
||||
// have to remove in the next loop after the universe is marked as disposed, when 'Dispose()' is called it will trigger universe selection
|
||||
// and deselect all symbols, sending the removed security changes, which are picked up by the AlgorithmManager and tags securities
|
||||
// as non tradable as long as they are not active in any universe (uses UniverseManager.ActiveSecurities)
|
||||
// but they will remain tradable if a position is still being hold since they won't be remove from the UniverseManager
|
||||
// but this last part will not happen if we remove the universe from the UniverseManager right away, since it won't be part of 'UniverseManager'.
|
||||
// And we have to remove the universe even if it's present at 'universes' because that one is another New universe that should get added!
|
||||
// 'UniverseManager' will skip duplicate entries getting added.
|
||||
UniverseManager.Remove(universeSymbol);
|
||||
}
|
||||
|
||||
Universe universe;
|
||||
if (!universes.TryGetValue(universeSymbol, out universe))
|
||||
{
|
||||
if (ukvp.Value.DisposeRequested)
|
||||
{
|
||||
UniverseManager.Remove(universeSymbol);
|
||||
}
|
||||
|
||||
// mark this universe as disposed to remove all child subscriptions
|
||||
ukvp.Value.Dispose();
|
||||
}
|
||||
@@ -147,7 +156,8 @@ namespace QuantConnect.Algorithm
|
||||
// only fire insights generated event if we actually have insights
|
||||
if (insights.Length != 0)
|
||||
{
|
||||
OnInsightsGenerated(insights.Select(InitializeInsightFields));
|
||||
insights = InitializeInsights(insights);
|
||||
OnInsightsGenerated(insights);
|
||||
}
|
||||
|
||||
ProcessInsights(insights);
|
||||
@@ -226,7 +236,7 @@ namespace QuantConnect.Algorithm
|
||||
Log($"{Time}: RISK ADJUSTED TARGETS: {string.Join(" | ", riskAdjustedTargets.Select(t => t.ToString()).OrderBy(t => t))}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Execution.Execute(this, riskAdjustedTargets);
|
||||
}
|
||||
|
||||
@@ -382,7 +392,8 @@ namespace QuantConnect.Algorithm
|
||||
return;
|
||||
}
|
||||
|
||||
OnInsightsGenerated(insights.Select(InitializeInsightFields));
|
||||
insights = InitializeInsights(insights);
|
||||
OnInsightsGenerated(insights);
|
||||
ProcessInsights(insights);
|
||||
}
|
||||
|
||||
@@ -394,7 +405,52 @@ namespace QuantConnect.Algorithm
|
||||
/// <param name="insight">The insight to be emitted</param>
|
||||
public void EmitInsights(Insight insight)
|
||||
{
|
||||
EmitInsights(new []{insight});
|
||||
EmitInsights(new[] { insight });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method used to validate insights and prepare them to be emitted
|
||||
/// </summary>
|
||||
/// <param name="insights">insights preparing to be emitted</param>
|
||||
/// <returns>Validated insights</returns>
|
||||
private Insight[] InitializeInsights(Insight[] insights)
|
||||
{
|
||||
List<Insight> validInsights = null;
|
||||
for (var i = 0; i < insights.Length; i++)
|
||||
{
|
||||
if (Securities[insights[i].Symbol].IsDelisted)
|
||||
{
|
||||
if (!_isEmitDelistedInsightWarningSent)
|
||||
{
|
||||
Error($"QCAlgorithm.EmitInsights(): Warning: cannot emit insights for delisted securities, these will be discarded");
|
||||
_isEmitDelistedInsightWarningSent = true;
|
||||
}
|
||||
|
||||
// If this is our first invalid insight, create the list and fill it with previous values
|
||||
if (validInsights == null)
|
||||
{
|
||||
validInsights = new List<Insight>() {};
|
||||
for (var j = 0; j < i; j++)
|
||||
{
|
||||
validInsights.Add(insights[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initialize the insight fields
|
||||
insights[i] = InitializeInsightFields(insights[i]);
|
||||
|
||||
// If we already had an invalid insight, this will have been initialized storing the valid ones.
|
||||
if (validInsights != null)
|
||||
{
|
||||
validInsights.Add(insights[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validInsights == null ? insights : validInsights.ToArray();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -103,6 +103,30 @@ namespace QuantConnect.Algorithm
|
||||
return accumulationDistributionOscillator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ARIMA indicator.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol whose ARIMA indicator we want</param>
|
||||
/// <param name="arOrder">AR order (p) -- defines the number of past values to consider in the AR component of the model.</param>
|
||||
/// <param name="diffOrder">Difference order (d) -- defines how many times to difference the model before fitting parameters.</param>
|
||||
/// <param name="maOrder">MA order (q) -- defines the number of past values to consider in the MA component of the model.</param>
|
||||
/// <param name="period">Size of the rolling series to fit onto</param>
|
||||
/// <param name="resolution">The resolution</param>
|
||||
/// <returns>The ARIMA indicator for the requested symbol over the specified period</returns>
|
||||
public AutoRegressiveIntegratedMovingAverage ARIMA(Symbol symbol, int arOrder, int diffOrder, int maOrder, int period, Resolution? resolution = null)
|
||||
{
|
||||
var name = CreateIndicatorName(symbol, $"ARIMA({arOrder},{diffOrder},{maOrder},{period})", resolution);
|
||||
var arimaIndicator = new AutoRegressiveIntegratedMovingAverage(name, arOrder, diffOrder, maOrder, period);
|
||||
RegisterIndicator(symbol, arimaIndicator, resolution);
|
||||
|
||||
if (EnableAutomaticIndicatorWarmUp)
|
||||
{
|
||||
WarmUpIndicator(symbol, arimaIndicator, resolution);
|
||||
}
|
||||
|
||||
return arimaIndicator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Average Directional Index indicator.
|
||||
/// The indicator will be automatically updated on the given resolution.
|
||||
@@ -126,6 +150,28 @@ namespace QuantConnect.Algorithm
|
||||
return averageDirectionalIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Awesome Oscillator from the specified periods.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol whose Awesome Oscillator we seek</param>
|
||||
/// <param name="resolution">The resolution.</param>
|
||||
/// <param name="fastPeriod">The period of the fast moving average associated with the AO</param>
|
||||
/// <param name="slowPeriod">The period of the slow moving average associated with the AO</param>
|
||||
/// <param name="type">The type of moving average used when computing the fast and slow term. Defaults to simple moving average.</param>
|
||||
public AwesomeOscillator AO(Symbol symbol, int slowPeriod, int fastPeriod, MovingAverageType type, Resolution? resolution = null, Func<IBaseData, IBaseDataBar> selector = null)
|
||||
{
|
||||
var name = CreateIndicatorName(symbol, $"AO({fastPeriod},{slowPeriod},{type})", resolution);
|
||||
var awesomeOscillator = new AwesomeOscillator(name, fastPeriod, slowPeriod, type);
|
||||
RegisterIndicator(symbol, awesomeOscillator, resolution, selector);
|
||||
|
||||
if (EnableAutomaticIndicatorWarmUp)
|
||||
{
|
||||
WarmUpIndicator(symbol, awesomeOscillator, resolution);
|
||||
}
|
||||
|
||||
return awesomeOscillator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new AverageDirectionalMovementIndexRating indicator.
|
||||
/// </summary>
|
||||
@@ -354,6 +400,28 @@ namespace QuantConnect.Algorithm
|
||||
|
||||
return commodityChannelIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ChaikinMoneyFlow indicator.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol whose CMF we want</param>
|
||||
/// <param name="period">The period over which to compute the CMF</param>
|
||||
/// <param name="resolution">The resolution</param>
|
||||
/// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param>
|
||||
/// <returns>The ChaikinMoneyFlow indicator for the requested symbol over the specified period</returns>
|
||||
public ChaikinMoneyFlow CMF(Symbol symbol, int period, Resolution? resolution = null, Func<IBaseData, TradeBar> selector = null)
|
||||
{
|
||||
var name = CreateIndicatorName(symbol, $"CMF({period})", resolution);
|
||||
var chaikinMoneyFlow = new ChaikinMoneyFlow(name, period);
|
||||
RegisterIndicator(symbol, chaikinMoneyFlow, resolution, selector);
|
||||
if (EnableAutomaticIndicatorWarmUp)
|
||||
{
|
||||
WarmUpIndicator(symbol, chaikinMoneyFlow, resolution);
|
||||
}
|
||||
|
||||
return chaikinMoneyFlow;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ChandeMomentumOscillator indicator.
|
||||
@@ -376,7 +444,31 @@ namespace QuantConnect.Algorithm
|
||||
|
||||
return chandeMomentumOscillator;
|
||||
}
|
||||
|
||||
///<summary>
|
||||
/// Creates a new DeMarker Indicator (DEM), an oscillator-type indicator measuring changes in terms of an asset's
|
||||
/// High and Low tradebar values.
|
||||
///</summary>
|
||||
/// <param name="symbol">The symbol whose DEM we seek.</param>
|
||||
/// <param name="period">The period of the moving average implemented</param>
|
||||
/// <param name="movingAverageType">Specifies the type of moving average to be used</param>
|
||||
/// <param name="resolution">The resolution.</param>
|
||||
/// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param>
|
||||
/// <returns>The DeMarker indicator for the requested symbol.</returns>
|
||||
public DeMarkerIndicator DEM(Symbol symbol, int period, MovingAverageType type, Resolution? resolution = null, Func<IBaseData, TradeBar> selector = null)
|
||||
{
|
||||
var name = CreateIndicatorName(symbol, $"DEM({period},{type})", resolution);
|
||||
var deMarkerIndicator = new DeMarkerIndicator(name, period, type);
|
||||
RegisterIndicator(symbol, deMarkerIndicator, resolution, selector);
|
||||
|
||||
if (EnableAutomaticIndicatorWarmUp)
|
||||
{
|
||||
WarmUpIndicator(symbol, deMarkerIndicator, resolution);
|
||||
}
|
||||
|
||||
return deMarkerIndicator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Donchian Channel indicator which will compute the Upper Band and Lower Band.
|
||||
/// The indicator will be automatically updated on the given resolution.
|
||||
@@ -1350,6 +1442,28 @@ namespace QuantConnect.Algorithm
|
||||
|
||||
return relativeStrengthIndex;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new RelativeVigorIndex indicator.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The symbol whose RVI we want</param>
|
||||
/// <param name="period">The period over which to compute the RVI</param>
|
||||
/// <param name="movingAverageType">The type of moving average to use</param>
|
||||
/// <param name="resolution">The resolution</param>
|
||||
/// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to the Value property of BaseData (x => x.Value)</param>
|
||||
/// <returns>The RelativeVigorIndex indicator for the requested symbol over the specified period</returns>
|
||||
public RelativeVigorIndex RVI(Symbol symbol, int period, MovingAverageType movingAverageType = MovingAverageType.Simple, Resolution? resolution = null, Func<IBaseData, TradeBar> selector = null)
|
||||
{
|
||||
var name = CreateIndicatorName(symbol, $"RVI({period},{movingAverageType})", resolution);
|
||||
var relativeVigorIndex = new RelativeVigorIndex(name, period, movingAverageType);
|
||||
RegisterIndicator(symbol, relativeVigorIndex, resolution, selector);
|
||||
|
||||
if (EnableAutomaticIndicatorWarmUp)
|
||||
{
|
||||
WarmUpIndicator(symbol, relativeVigorIndex, resolution);
|
||||
}
|
||||
|
||||
return relativeVigorIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an SimpleMovingAverage indicator for the symbol. The indicator will be automatically
|
||||
@@ -2543,4 +2657,4 @@ namespace QuantConnect.Algorithm
|
||||
return new BaseDataConsolidator(calendar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,32 @@ namespace QuantConnect.Algorithm
|
||||
return AddDataImpl(dataType, symbol, resolution, timeZone, fillDataForward, leverage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddData a new user defined data source including symbol properties and exchange hours,
|
||||
/// all other vars are not required and will use defaults.
|
||||
/// This overload reflects the C# equivalent for custom properties and market hours
|
||||
/// </summary>
|
||||
/// <param name="type">Data source type</param>
|
||||
/// <param name="ticker">Key/Ticker for data</param>
|
||||
/// <param name="properties">The properties of this new custom data</param>
|
||||
/// <param name="exchangeHours">The Exchange hours of this symbol</param>
|
||||
/// <param name="resolution">Resolution of the Data Required</param>
|
||||
/// <param name="fillDataForward">When no data available on a tradebar, return the last data that was generated</param>
|
||||
/// <param name="leverage">Custom leverage per security</param>
|
||||
/// <returns>The new <see cref="Security"/></returns>
|
||||
public Security AddData(PyObject type, string ticker, SymbolProperties properties, SecurityExchangeHours exchangeHours, Resolution? resolution = null, bool fillDataForward = false, decimal leverage = 1.0m)
|
||||
{
|
||||
// Get the right key for storage of base type symbols
|
||||
var dataType = type.CreateType();
|
||||
var key = SecurityIdentifier.GenerateBaseSymbol(dataType, ticker);
|
||||
|
||||
// Add entries to our Symbol Properties DB and MarketHours DB
|
||||
SetDatabaseEntries(key, properties, exchangeHours);
|
||||
|
||||
// Then add the data
|
||||
return AddData(dataType, ticker, resolution, null, fillDataForward, leverage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and adds a new Future Option contract to the algorithm.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -46,6 +46,7 @@ using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Risk;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Algorithm.Selection;
|
||||
using QuantConnect.Data.Shortable;
|
||||
using QuantConnect.Storage;
|
||||
|
||||
namespace QuantConnect.Algorithm
|
||||
@@ -87,9 +88,6 @@ namespace QuantConnect.Algorithm
|
||||
private bool _checkedForOnDataSlice;
|
||||
private Action<Slice> _onDataSlice;
|
||||
|
||||
// set by SetBenchmark helper API functions
|
||||
private Symbol _benchmarkSymbol = QuantConnect.Symbol.Empty;
|
||||
|
||||
// flips to true when the user
|
||||
private bool _userSetSecurityInitializer = false;
|
||||
|
||||
@@ -554,20 +552,10 @@ namespace QuantConnect.Algorithm
|
||||
|
||||
FrameworkPostInitialize();
|
||||
|
||||
// if the benchmark hasn't been set yet, set it
|
||||
// if the benchmark hasn't been set yet, load in the default from the brokerage model
|
||||
if (Benchmark == null)
|
||||
{
|
||||
if (_benchmarkSymbol == null)
|
||||
{
|
||||
_benchmarkSymbol = QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA);
|
||||
}
|
||||
|
||||
var security = Securities.CreateSecurity(_benchmarkSymbol,
|
||||
new List<SubscriptionDataConfig>(),
|
||||
leverage: 1,
|
||||
addToSymbolCache:false);
|
||||
|
||||
Benchmark = new SecurityBenchmark(security);
|
||||
Benchmark = BrokerageModel.GetBenchmark(Securities);
|
||||
}
|
||||
|
||||
// perform end of time step checks, such as enforcing underlying securities are in raw data mode
|
||||
@@ -1055,7 +1043,8 @@ namespace QuantConnect.Algorithm
|
||||
market = Market.USA;
|
||||
}
|
||||
|
||||
_benchmarkSymbol = QuantConnect.Symbol.Create(symbol, securityType, market);
|
||||
var benchmarkSymbol = QuantConnect.Symbol.Create(symbol, securityType, market);
|
||||
SetBenchmark(benchmarkSymbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1068,31 +1057,24 @@ namespace QuantConnect.Algorithm
|
||||
/// </remarks>
|
||||
public void SetBenchmark(string ticker)
|
||||
{
|
||||
if (_locked)
|
||||
{
|
||||
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
|
||||
}
|
||||
|
||||
Symbol symbol;
|
||||
Security security;
|
||||
// lets first check the cache and use that symbol to check the securities collection
|
||||
// else use the first matching the given ticker in the collection
|
||||
if (!SymbolCache.TryGetSymbol(ticker, out symbol)
|
||||
|| !Securities.TryGetValue(symbol, out security))
|
||||
|
||||
// Check the cache for the symbol
|
||||
if (!SymbolCache.TryGetSymbol(ticker, out symbol))
|
||||
{
|
||||
ticker = ticker.LazyToUpper();
|
||||
security = Securities.FirstOrDefault(x => x.Key.Value == ticker).Value;
|
||||
// Check our securities for a symbol matched with this ticker
|
||||
symbol = Securities.FirstOrDefault(x => x.Key.Value == ticker).Key;
|
||||
|
||||
// If we didn't find a symbol matching our ticker, create one.
|
||||
if (symbol == null)
|
||||
{
|
||||
Debug($"Warning: SetBenchmark({ticker}): no existing symbol found, benchmark security will be added with {SecurityType.Equity} type.");
|
||||
symbol = QuantConnect.Symbol.Create(ticker, SecurityType.Equity, Market.USA);
|
||||
}
|
||||
}
|
||||
|
||||
if (security == null)
|
||||
{
|
||||
Debug($"Warning: SetBenchmark({ticker}): no existing security found, benchmark security will be added with {SecurityType.Equity} type.");
|
||||
_benchmarkSymbol = QuantConnect.Symbol.Create(ticker, SecurityType.Equity, Market.USA);
|
||||
}
|
||||
else
|
||||
{
|
||||
_benchmarkSymbol = security.Symbol;
|
||||
}
|
||||
// Send our symbol through
|
||||
SetBenchmark(symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1105,7 +1087,9 @@ namespace QuantConnect.Algorithm
|
||||
{
|
||||
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
|
||||
}
|
||||
_benchmarkSymbol = symbol;
|
||||
|
||||
// Create our security benchmark
|
||||
Benchmark = SecurityBenchmark.CreateInstance(Securities, symbol);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1119,6 +1103,7 @@ namespace QuantConnect.Algorithm
|
||||
{
|
||||
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
|
||||
}
|
||||
|
||||
Benchmark = new FuncBenchmark(benchmark);
|
||||
}
|
||||
|
||||
@@ -1978,6 +1963,30 @@ namespace QuantConnect.Algorithm
|
||||
return AddData(typeof(T), underlying, resolution, timeZone, fillDataForward, leverage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddData<typeparam name="T"/> a new user defined data source including symbol properties and exchange hours,
|
||||
/// all other vars are not required and will use defaults.
|
||||
/// </summary>
|
||||
/// <param name="ticker">Key/Ticker for data</param>
|
||||
/// <param name="properties">The properties of this new custom data</param>
|
||||
/// <param name="exchangeHours">The Exchange hours of this symbol</param>
|
||||
/// <param name="resolution">Resolution of the Data Required</param>
|
||||
/// <param name="fillDataForward">When no data available on a tradebar, return the last data that was generated</param>
|
||||
/// <param name="leverage">Custom leverage per security</param>
|
||||
/// <returns>The new <see cref="Security"/></returns>
|
||||
public Security AddData<T>(string ticker, SymbolProperties properties, SecurityExchangeHours exchangeHours, Resolution? resolution = null, bool fillDataForward = false, decimal leverage = 1.0m)
|
||||
where T : IBaseData, new()
|
||||
{
|
||||
// Get the right key for storage of base type symbols
|
||||
var key = SecurityIdentifier.GenerateBaseSymbol(typeof(T), ticker);
|
||||
|
||||
// Set our database entries for this data type
|
||||
SetDatabaseEntries(key, properties, exchangeHours);
|
||||
|
||||
// Then add the data
|
||||
return AddData(typeof(T), ticker, resolution, null, fillDataForward, leverage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a debug message to the web console:
|
||||
/// </summary>
|
||||
@@ -2286,17 +2295,15 @@ namespace QuantConnect.Algorithm
|
||||
/// </summary>
|
||||
/// <param name="insights">The collection of insights generaed at the current time step</param>
|
||||
/// <param name="clone">Will emit a clone of the generated insights</param>
|
||||
private void OnInsightsGenerated(IEnumerable<Insight> insights, bool clone = true)
|
||||
private void OnInsightsGenerated(Insight[] insights, bool clone = true)
|
||||
{
|
||||
var insightCollection = insights.ToArray();
|
||||
|
||||
// debug printing of generated insights
|
||||
if (DebugMode)
|
||||
{
|
||||
Log($"{Time}: ALPHA: {string.Join(" | ", insightCollection.Select(i => i.ToString()).OrderBy(i => i))}");
|
||||
Log($"{Time}: ALPHA: {string.Join(" | ", insights.Select(i => i.ToString()).OrderBy(i => i))}");
|
||||
}
|
||||
|
||||
InsightsGenerated?.Invoke(this, new GeneratedInsightsCollection(UtcTime, insightCollection, clone: clone));
|
||||
InsightsGenerated?.Invoke(this, new GeneratedInsightsCollection(UtcTime, insights, clone: clone));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2326,5 +2333,76 @@ namespace QuantConnect.Algorithm
|
||||
{
|
||||
ObjectStore = new ObjectStore(objectStore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the Symbol is shortable at the brokerage
|
||||
/// </summary>
|
||||
/// <param name="symbol">Symbol to check if shortable</param>
|
||||
/// <returns>True if shortable</returns>
|
||||
public bool Shortable(Symbol symbol)
|
||||
{
|
||||
return Shortable(symbol, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the Symbol is shortable at the brokerage
|
||||
/// </summary>
|
||||
/// <param name="symbol">Symbol to check if shortable</param>
|
||||
/// <param name="shortQuantity">Order's quantity to check if it is currently shortable, taking into account current holdings and open orders</param>
|
||||
/// <returns>True if shortable</returns>
|
||||
public bool Shortable(Symbol symbol, decimal shortQuantity)
|
||||
{
|
||||
var shortableQuantity = BrokerageModel.GetShortableProvider().ShortableQuantity(symbol, Time);
|
||||
if (shortableQuantity == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var openOrderQuantity = Transactions.GetOpenOrdersRemainingQuantity(symbol);
|
||||
var portfolioQuantity = Portfolio.ContainsKey(symbol) ? Portfolio[symbol].Quantity : 0;
|
||||
// We check portfolio and open orders beforehand to ensure that orderQuantity == 0 case does not return
|
||||
// a true result whenever we have no more shares left to short.
|
||||
if (portfolioQuantity + openOrderQuantity <= -shortableQuantity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
shortQuantity = -Math.Abs(shortQuantity);
|
||||
return portfolioQuantity + shortQuantity + openOrderQuantity >= -shortableQuantity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the quantity shortable for the given asset
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Quantity shortable for the given asset. Zero if not
|
||||
/// shortable, or a number greater than zero if shortable.
|
||||
/// </returns>
|
||||
public long ShortableQuantity(Symbol symbol)
|
||||
{
|
||||
var shortableSymbols = AllShortableSymbols();
|
||||
return shortableSymbols.ContainsKey(symbol) ? shortableSymbols[symbol] : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all Symbols that are shortable, as well as the quantity shortable for them
|
||||
/// </summary>
|
||||
/// <returns>All shortable Symbols, null if all Symbols are shortable</returns>
|
||||
public Dictionary<Symbol, long> AllShortableSymbols()
|
||||
{
|
||||
return BrokerageModel.GetShortableProvider().AllShortableSymbols(Time);
|
||||
}
|
||||
|
||||
/// Set the properties and exchange hours for a given key into our databases
|
||||
/// </summary>
|
||||
/// <param name="key">Key for database storage</param>
|
||||
/// <param name="properties">Properties to store</param>
|
||||
/// <param name="exchangeHours">Exchange hours to store</param>
|
||||
private void SetDatabaseEntries(string key, SymbolProperties properties, SecurityExchangeHours exchangeHours)
|
||||
{
|
||||
// Add entries to our Symbol Properties DB and MarketHours DB
|
||||
SymbolPropertiesDatabase.SetEntry(Market.USA, key, SecurityType.Base, properties);
|
||||
MarketHoursDatabase.SetEntry(Market.USA, key, SecurityType.Base, exchangeHours);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{3240ACA4-BDD4-4D24-AC36-BBB651C39212}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuantConnect.Algorithm</RootNamespace>
|
||||
<AssemblyName>QuantConnect.Algorithm</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
<LangVersion>6</LangVersion>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<DocumentationFile>bin\$(Configuration)\QuantConnect.Algorithm.xml</DocumentationFile>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\QuantConnect.Algorithm.xml</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<DocumentationFile>bin\Release\QuantConnect.Algorithm.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile>bin\Debug\QuantConnect.Algorithm.XML</DocumentationFile>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MathNet.Numerics, Version=3.19.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MathNet.Numerics.3.19.0\lib\net40\MathNet.Numerics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NodaTime.1.3.4\lib\net35-Client\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
@@ -111,102 +58,51 @@
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Alphas\AlphaModel.cs" />
|
||||
<Compile Include="Alphas\AlphaModelExtensions.cs" />
|
||||
<Compile Include="Alphas\AlphaModelPythonWrapper.cs" />
|
||||
<Compile Include="Alphas\CompositeAlphaModel.cs" />
|
||||
<Compile Include="Alphas\IAlphaModel.cs" />
|
||||
<Compile Include="Alphas\INamedModel.cs" />
|
||||
<Compile Include="Alphas\NullAlphaModel.cs" />
|
||||
<Compile Include="CandlestickPatterns.cs" />
|
||||
<Compile Include="ConstituentUniverseDefinitions.cs" />
|
||||
<Compile Include="Execution\ExecutionModel.cs" />
|
||||
<Compile Include="Execution\ExecutionModelPythonWrapper.cs" />
|
||||
<Compile Include="Execution\IExecutionModel.cs" />
|
||||
<Compile Include="Execution\ImmediateExecutionModel.cs" />
|
||||
<Compile Include="Execution\NullExecutionModel.cs" />
|
||||
<Compile Include="IndexUniverseDefinitions.cs" />
|
||||
<Compile Include="DollarVolumeUniverseDefinitions.cs" />
|
||||
<Compile Include="INotifiedSecurityChanges.cs" />
|
||||
<Compile Include="Portfolio\PortfolioBias.cs" />
|
||||
<Compile Include="Portfolio\IPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\IPortfolioOptimizer.cs" />
|
||||
<Compile Include="Portfolio\NullPortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\PortfolioConstructionModel.cs" />
|
||||
<Compile Include="Portfolio\PortfolioConstructionModelPythonWrapper.cs" />
|
||||
<Compile Include="QCAlgorithm.Framework.Python.cs" />
|
||||
<Compile Include="Risk\CompositeRiskManagementModel.cs" />
|
||||
<Compile Include="Risk\IRiskManagementModel.cs" />
|
||||
<Compile Include="Risk\NullRiskManagementModel.cs" />
|
||||
<Compile Include="Risk\RiskManagementModel.cs" />
|
||||
<Compile Include="Risk\RiskManagementModelPythonWrapper.cs" />
|
||||
<Compile Include="QCAlgorithm.cs" />
|
||||
<Compile Include="QCAlgorithm.Framework.cs" />
|
||||
<Compile Include="QCAlgorithm.History.cs" />
|
||||
<Compile Include="QCAlgorithm.Python.cs" />
|
||||
<Compile Include="QCAlgorithm.Trading.cs" />
|
||||
<Compile Include="QCAlgorithm.Indicators.cs" />
|
||||
<Compile Include="QCAlgorithm.Plotting.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QCAlgorithm.Universe.cs" />
|
||||
<Compile Include="Selection\CompositeUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\CustomUniverse.cs" />
|
||||
<Compile Include="Selection\CustomUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\IUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\ManualUniverse.cs" />
|
||||
<Compile Include="Selection\ManualUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\NullUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\OptionChainedUniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\OptionContractUniverse.cs" />
|
||||
<Compile Include="Selection\UniverseSelectionModel.cs" />
|
||||
<Compile Include="Selection\UniverseSelectionModelPythonWrapper.cs" />
|
||||
<Compile Include="UniverseDefinitions.cs" />
|
||||
<PackageReference Include="MathNet.Numerics" Version="3.19.0" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers" Version="2.10.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NodaTime" Version="3.0.5" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="1.0.5.30" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Configuration\QuantConnect.Configuration.csproj">
|
||||
<Project>{0AEB4EA3-28C8-476E-89FD-926F06590B4C}</Project>
|
||||
<Name>QuantConnect.Configuration</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj">
|
||||
<Project>{73FB2522-C3ED-4E47-8E3D-AFAD48A6B888}</Project>
|
||||
<Name>QuantConnect.Indicators</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545C0B4-FABB-49C9-8DD1-9AD7EE23F86B}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Logging\QuantConnect.Logging.csproj">
|
||||
<Project>{01911409-86BE-4E7D-9947-DF714138610D}</Project>
|
||||
<Name>QuantConnect.Logging</Name>
|
||||
</ProjectReference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Configuration\QuantConnect.Configuration.csproj" />
|
||||
<ProjectReference Include="..\Indicators\QuantConnect.Indicators.csproj" />
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj" />
|
||||
<ProjectReference Include="..\Logging\QuantConnect.Logging.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Alphas\NullAlphaModel.py">
|
||||
@@ -234,35 +130,4 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Humanizer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MathNet.Numerics" version="3.19.0" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
||||
<package id="NodaTime" version="1.3.4" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -101,21 +101,21 @@ while not sys.gettrace():
|
||||
count = 1
|
||||
while count <= 10:
|
||||
try:
|
||||
pydevd_pycharm.settrace('localhost', port=5678, stdoutToServer=True, stderrToServer=True, suspend=False)
|
||||
pydevd_pycharm.settrace('localhost', port=6000, stdoutToServer=True, stderrToServer=True, suspend=False)
|
||||
print('SUCCESS: Connected to local program')
|
||||
break
|
||||
except ConnectionRefusedError:
|
||||
pass
|
||||
|
||||
try:
|
||||
pydevd_pycharm.settrace('host.docker.internal', port=5678, stdoutToServer=True, stderrToServer=True, suspend=False)
|
||||
pydevd_pycharm.settrace('host.docker.internal', port=6000, stdoutToServer=True, stderrToServer=True, suspend=False)
|
||||
print('SUCCESS: Connected to docker container')
|
||||
break
|
||||
except ConnectionRefusedError:
|
||||
pass
|
||||
|
||||
print('\n')
|
||||
print('Failed: Ensure your PyCharm Debugger is actively waiting for a connection at port 5678!')
|
||||
print('Failed: Ensure your PyCharm Debugger is actively waiting for a connection at port 6000!')
|
||||
print('Try ' + count.__str__() + ' out of 10')
|
||||
print('\n')
|
||||
count += 1
|
||||
|
||||
@@ -368,7 +368,7 @@ logging.captureWarnings(True)"
|
||||
var complete = isolator.ExecuteWithTimeLimit(_loaderTimeLimit, () =>
|
||||
{
|
||||
success = TryCreateAlgorithmInstance(assemblyPath, out instance, out error);
|
||||
}, ramLimit, sleepIntervalMillis:50, workerThread:_workerThread);
|
||||
}, ramLimit, sleepIntervalMillis:100, workerThread:_workerThread);
|
||||
|
||||
algorithmInstance = instance;
|
||||
errorMessage = error;
|
||||
|
||||
@@ -930,5 +930,16 @@ namespace QuantConnect.AlgorithmFactory.Python.Wrappers
|
||||
/// </summary>
|
||||
/// <param name="objectStore">The object store</param>
|
||||
public void SetObjectStore(IObjectStore objectStore) => _baseAlgorithm.SetObjectStore(objectStore);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the asset is shortable at the brokerage
|
||||
/// </summary>
|
||||
/// <param name="symbol">Symbol to check if it is shortable</param>
|
||||
/// <param name="quantity">Quantity to short</param>
|
||||
/// <returns>True if shortable at the brokerage</returns>
|
||||
public bool Shortable(Symbol symbol, decimal quantity)
|
||||
{
|
||||
return _baseAlgorithm.Shortable(symbol, quantity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props" Condition="Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E99D056A-B6FB-48D2-9F7C-683C54CEBBF9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QuantConnect.AlgorithmFactory</RootNamespace>
|
||||
<AssemblyName>QuantConnect.AlgorithmFactory</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFramework>net462</TargetFramework>
|
||||
<LangVersion>6</LangVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<OutputPath>bin\$(Configuration)\</OutputPath>
|
||||
<DocumentationFile>bin\$(Configuration)\QuantConnect.AlgorithmFactory.xml</DocumentationFile>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\QuantConnect.AlgorithmFactory.xml</DocumentationFile>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<LangVersion>6</LangVersion>
|
||||
<CodeAnalysisRuleSet>..\QuantConnect.ruleset</CodeAnalysisRuleSet>
|
||||
<DocumentationFile>bin\Release\QuantConnect.AlgorithmFactory.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NodaTime.1.3.4\lib\net35-Client\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows>false</IsWindows>
|
||||
<IsWindows Condition="'$(OS)' == 'Windows_NT'">true</IsWindows>
|
||||
@@ -71,89 +39,53 @@
|
||||
<Message Text="IsLinux $(IsLinux)" Importance="high" />
|
||||
<Message Text="ForceLinuxBuild $(ForceLinuxBuild)" Importance="high" />
|
||||
</Target>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.VersionCheckAnalyzer" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers" Version="2.10.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="Microsoft.NetFramework.Analyzers" Version="2.9.3" />
|
||||
<PackageReference Include="NodaTime" Version="3.0.5" />
|
||||
<PackageReference Include="QuantConnect.pythonnet" Version="1.0.5.30" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="$(IsWindows) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\win\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsLinux) OR '$(ForceLinuxBuild)' == 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\linux\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<When Condition="$(IsOSX) AND '$(ForceLinuxBuild)' != 'true'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Python.Runtime, Version=1.0.5.30, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\QuantConnect.pythonnet.1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
<HintPath>$(NuGetPackageRoot)\quantconnect.pythonnet\1.0.5.30\lib\osx\Python.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="DebuggerHelper.cs" />
|
||||
<Compile Include="Loader.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Python\Wrappers\AlgorithmPythonWrapper.cs" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj">
|
||||
<Project>{3240ACA4-BDD4-4D24-AC36-BBB651C39212}</Project>
|
||||
<Name>QuantConnect.Algorithm</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj">
|
||||
<Project>{2545c0b4-fabb-49c9-8dd1-9ad7ee23f86b}</Project>
|
||||
<Name>QuantConnect</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Configuration\QuantConnect.Configuration.csproj">
|
||||
<Project>{0aeb4ea3-28c8-476e-89fd-926f06590b4c}</Project>
|
||||
<Name>QuantConnect.Configuration</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Logging\QuantConnect.Logging.csproj">
|
||||
<Project>{01911409-86be-4e7d-9947-df714138610d}</Project>
|
||||
<Name>QuantConnect.Logging</Name>
|
||||
</ProjectReference>
|
||||
<Compile Include="..\Common\Properties\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<ProjectReference Include="..\Algorithm\QuantConnect.Algorithm.csproj" />
|
||||
<ProjectReference Include="..\Common\QuantConnect.csproj" />
|
||||
<ProjectReference Include="..\Configuration\QuantConnect.Configuration.csproj" />
|
||||
<ProjectReference Include="..\Logging\QuantConnect.Logging.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\analyzers\dotnet\Microsoft.CodeAnalysis.VersionCheckAnalyzer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Humanizer.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.CodeQuality.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetCore.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetCore.CSharp.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.Analyzers.dll" />
|
||||
<Analyzer Include="..\packages\Microsoft.NetFramework.Analyzers.2.9.3\analyzers\dotnet\cs\Microsoft.NetFramework.CSharp.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets" Condition="Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\QuantConnect.pythonnet.1.0.5.30\build\QuantConnect.pythonnet.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.VersionCheckAnalyzer.2.9.3\build\Microsoft.CodeAnalysis.VersionCheckAnalyzer.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeQuality.Analyzers.2.9.3\build\Microsoft.CodeQuality.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetCore.Analyzers.2.9.3\build\Microsoft.NetCore.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.3\build\Microsoft.NetFramework.Analyzers.props'))" />
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.3\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.CodeAnalysis.FxCopAnalyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeAnalysis.VersionCheckAnalyzer" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.CodeQuality.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetCore.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="Microsoft.NetFramework.Analyzers" version="2.9.3" targetFramework="net452" />
|
||||
<package id="NodaTime" version="1.3.4" targetFramework="net452" />
|
||||
<package id="QuantConnect.pythonnet" version="1.0.5.30" targetFramework="net452" />
|
||||
</packages>
|
||||
110
Api/Api.cs
110
Api/Api.cs
@@ -20,6 +20,7 @@ using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Logging;
|
||||
using QuantConnect.Orders;
|
||||
using RestSharp;
|
||||
using RestSharp.Extensions;
|
||||
@@ -383,9 +384,15 @@ namespace QuantConnect.Api
|
||||
backtestName
|
||||
}), ParameterType.RequestBody);
|
||||
|
||||
Backtest result;
|
||||
BacktestResponseWrapper result;
|
||||
ApiConnection.TryRequest(request, out result);
|
||||
return result;
|
||||
|
||||
// Use API Response values for Backtest Values
|
||||
result.Backtest.Success = result.Success;
|
||||
result.Backtest.Errors = result.Errors;
|
||||
|
||||
// Return only the backtest object
|
||||
return result.Backtest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -393,9 +400,10 @@ namespace QuantConnect.Api
|
||||
/// </summary>
|
||||
/// <param name="projectId">Project id to read</param>
|
||||
/// <param name="backtestId">Specific backtest id to read</param>
|
||||
/// <param name="getCharts">True will return backtest charts</param>
|
||||
/// <returns><see cref="Backtest"/></returns>
|
||||
|
||||
public Backtest ReadBacktest(int projectId, string backtestId)
|
||||
public Backtest ReadBacktest(int projectId, string backtestId, bool getCharts = true)
|
||||
{
|
||||
var request = new RestRequest("backtests/read", Method.POST)
|
||||
{
|
||||
@@ -408,9 +416,63 @@ namespace QuantConnect.Api
|
||||
backtestId
|
||||
}), ParameterType.RequestBody);
|
||||
|
||||
Backtest result;
|
||||
BacktestResponseWrapper result;
|
||||
ApiConnection.TryRequest(request, out result);
|
||||
return result;
|
||||
|
||||
if (!result.Success)
|
||||
{
|
||||
// place an empty place holder so we can return any errors back to the user and not just null
|
||||
result.Backtest = new Backtest { BacktestId = backtestId };
|
||||
}
|
||||
// Go fetch the charts if the backtest is completed and success
|
||||
else if (getCharts && result.Backtest.Completed)
|
||||
{
|
||||
// For storing our collected charts
|
||||
var updatedCharts = new Dictionary<string, Chart>();
|
||||
|
||||
// Create backtest requests for each chart that is empty
|
||||
foreach (var chart in result.Backtest.Charts)
|
||||
{
|
||||
if (!chart.Value.Series.IsNullOrEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var chartRequest = new RestRequest("backtests/read", Method.POST)
|
||||
{
|
||||
RequestFormat = DataFormat.Json
|
||||
};
|
||||
|
||||
chartRequest.AddParameter("application/json", JsonConvert.SerializeObject(new
|
||||
{
|
||||
projectId,
|
||||
backtestId,
|
||||
chart = chart.Key.Replace(' ', '+')
|
||||
}), ParameterType.RequestBody);
|
||||
|
||||
BacktestResponseWrapper chartResponse;
|
||||
ApiConnection.TryRequest(chartRequest, out chartResponse);
|
||||
|
||||
// Add this chart to our updated collection
|
||||
if (chartResponse.Success)
|
||||
{
|
||||
updatedCharts.Add(chart.Key, chartResponse.Backtest.Charts[chart.Key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Update our result
|
||||
foreach(var updatedChart in updatedCharts)
|
||||
{
|
||||
result.Backtest.Charts[updatedChart.Key] = updatedChart.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// Use API Response values for Backtest Values
|
||||
result.Backtest.Success = result.Success;
|
||||
result.Backtest.Errors = result.Errors;
|
||||
|
||||
// Return only the backtest object
|
||||
return result.Backtest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -761,8 +823,29 @@ namespace QuantConnect.Api
|
||||
var uri = new Uri(link.DataLink);
|
||||
var client = new RestClient(uri.Scheme + "://" + uri.Host);
|
||||
var request = new RestRequest(uri.PathAndQuery, Method.GET);
|
||||
client.DownloadData(request).SaveAs(path);
|
||||
|
||||
// MAke a request for the data at the link
|
||||
var response = client.Execute(request);
|
||||
|
||||
// If the response is JSON it doesn't contain any data, try and extract the message and write it
|
||||
if (response.ContentType.ToLowerInvariant() == "application/json")
|
||||
{
|
||||
try
|
||||
{
|
||||
var contentObj = JObject.Parse(response.Content);
|
||||
var message = contentObj["message"].Value<string>();
|
||||
Log.Error($"Api.DownloadData(): Failed to download zip for {symbol} {resolution} data for date {date}, Api response: {message}");
|
||||
}
|
||||
catch
|
||||
{
|
||||
Log.Error($"Api.DownloadData(): Failed to download zip for {symbol} {resolution} data for date {date}. Api response could not be parsed.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Any other case save the content to given path
|
||||
response.RawBytes.SaveAs(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -847,7 +930,20 @@ namespace QuantConnect.Api
|
||||
// Add a user agent header in case the requested URI contains a query.
|
||||
client.Headers.Add("user-agent", "QCAlgorithm.Download(): User Agent Header");
|
||||
|
||||
return client.DownloadString(address);
|
||||
try
|
||||
{
|
||||
return client.DownloadString(address);
|
||||
}
|
||||
catch (WebException exception)
|
||||
{
|
||||
var message = $"Api.Download(): Failed to download data from {address}";
|
||||
if (!userName.IsNullOrEmpty() || !password.IsNullOrEmpty())
|
||||
{
|
||||
message += $" with username: {userName} and password {password}";
|
||||
}
|
||||
|
||||
throw new WebException($"{message}. Please verify the source for missing http:// or https://", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,6 @@ namespace QuantConnect.Api
|
||||
/// </summary>
|
||||
public class ApiConnection
|
||||
{
|
||||
/// <summary>
|
||||
/// The current config api url
|
||||
/// </summary>
|
||||
public static string ApiUrl = Config.Get("cloud-api-url", "https://www.quantconnect.com/api/v2/");
|
||||
|
||||
/// <summary>
|
||||
/// Authorized client to use for requests.
|
||||
/// </summary>
|
||||
@@ -51,7 +46,7 @@ namespace QuantConnect.Api
|
||||
{
|
||||
_token = token;
|
||||
_userId = userId.ToStringInvariant();
|
||||
Client = new RestClient(ApiUrl);
|
||||
Client = new RestClient("https://www.quantconnect.com/api/v2/");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,6 +116,7 @@ namespace QuantConnect.Api
|
||||
|
||||
if (result == null || !result.Success)
|
||||
{
|
||||
Log.Debug($"ApiConnection.TryRequest(): Raw response: '{responseContent}'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user