Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4df4ede29 | ||
|
|
3d0147b9fd | ||
|
|
9892b7a88a | ||
|
|
f2ce77177d | ||
|
|
cd5d4f8bd4 | ||
|
|
73b7064ba6 | ||
|
|
a601f3b77a | ||
|
|
8f98f646eb | ||
|
|
bcd076efa5 | ||
|
|
163ee55e20 | ||
|
|
88c9f57b68 | ||
|
|
9e77d7bf69 | ||
|
|
dab5aa45e0 | ||
|
|
d75f9ad587 | ||
|
|
0cc88be050 | ||
|
|
0077f363de | ||
|
|
2d45f26cb8 | ||
|
|
60bcd30731 | ||
|
|
040bae31d3 | ||
|
|
34d58f9dd6 | ||
|
|
d6520e92f9 | ||
|
|
4bee3b1153 | ||
|
|
ec1ac2bd89 | ||
|
|
52ba16bb07 | ||
|
|
68b2c255ba | ||
|
|
d9f1516ce4 | ||
|
|
0b4903dc0d | ||
|
|
7e635cb013 | ||
|
|
ba889a6685 | ||
|
|
8356b013aa | ||
|
|
a9abe80ef7 | ||
|
|
1f6c7c3008 | ||
|
|
286f6afbcf | ||
|
|
272b8e77e5 | ||
|
|
a53da83ef5 | ||
|
|
bc38c395f4 | ||
|
|
5b022ad05a | ||
|
|
69b259cbbd | ||
|
|
08e91cb30f | ||
|
|
993471dae5 | ||
|
|
2db5fcba79 | ||
|
|
04b49c50a3 | ||
|
|
a13987c349 | ||
|
|
b3bec4a4a6 | ||
|
|
fb76d0a1f3 | ||
|
|
06da07b2c8 | ||
|
|
b160f6e76a | ||
|
|
d92dc155cf | ||
|
|
658c047fdc | ||
|
|
d4afa75f4f | ||
|
|
cc886bca09 | ||
|
|
c871b60911 | ||
|
|
a80ad7495f | ||
|
|
1a52344c40 | ||
|
|
b80ca60b47 | ||
|
|
56a4a2863a | ||
|
|
0e9dc81df4 | ||
|
|
dbb1714380 | ||
|
|
01c8bb2f87 | ||
|
|
b7019c1640 | ||
|
|
d5f0c03699 | ||
|
|
9be02d7fa5 | ||
|
|
55c995e13f | ||
|
|
1d169a19ce | ||
|
|
956ffdfa9c | ||
|
|
0b6255c1fc | ||
|
|
6415de83cf | ||
|
|
e38f3f3aaf | ||
|
|
40e887a106 | ||
|
|
8149c291fc | ||
|
|
de9f9bf309 | ||
|
|
077b6e41d8 | ||
|
|
37d0c42149 | ||
|
|
ac1365cd7c | ||
|
|
c3530a6a7f | ||
|
|
7318c6fc7c | ||
|
|
2e0c3a03a5 | ||
|
|
824a754f81 | ||
|
|
1000669975 | ||
|
|
24a1fbba60 | ||
|
|
25d53fe6ff | ||
|
|
cad5f20a3d | ||
|
|
c5c56bf98e | ||
|
|
9b35411f45 | ||
|
|
2fe7f5b457 | ||
|
|
64f848a7b1 | ||
|
|
0937d08aa8 | ||
|
|
8330dd939e | ||
|
|
1ef66a1083 | ||
|
|
0fccf6017d | ||
|
|
41f9d1bd3a | ||
|
|
c35d6ee194 | ||
|
|
1cb8fcf2d9 | ||
|
|
58b7a9d22a | ||
|
|
2d4ca75670 | ||
|
|
cda769df74 | ||
|
|
5accfd6be3 | ||
|
|
265fd8b3b9 | ||
|
|
d633fed3ff | ||
|
|
f689826051 | ||
|
|
af7a2cfc85 | ||
|
|
6982f6713b | ||
|
|
50f887ca64 | ||
|
|
f08eda3bac | ||
|
|
8ad1016710 | ||
|
|
8937995ee4 | ||
|
|
ca7f7710e7 | ||
|
|
0b1b72e921 | ||
|
|
c44819617f | ||
|
|
3569a1f8d0 | ||
|
|
d71dd86ff5 | ||
|
|
96410b57a0 | ||
|
|
f17726b890 | ||
|
|
7ee297ab77 | ||
|
|
94fd3c8f64 | ||
|
|
50a8de5f67 | ||
|
|
af2043d7d3 | ||
|
|
57ce6958dd | ||
|
|
75d8e710d1 | ||
|
|
f75ea380e7 | ||
|
|
f3ea223f2a | ||
|
|
fb49f5da70 | ||
|
|
0cda5c7f0d | ||
|
|
9175b862d0 | ||
|
|
eca4f5b7f2 | ||
|
|
2bdddc94b4 | ||
|
|
12930c444b | ||
|
|
2ec979940c | ||
|
|
edd1aea8b0 | ||
|
|
be4a34c7e4 | ||
|
|
3b559a5f3f | ||
|
|
d4fd936772 | ||
|
|
a0328426d9 | ||
|
|
890a19c871 | ||
|
|
5359561b9d | ||
|
|
a8592e08b5 | ||
|
|
fcb4ce637d | ||
|
|
ec428c5f6c | ||
|
|
2a62f16833 | ||
|
|
f1c50e41a5 | ||
|
|
7445f7ec5a | ||
|
|
8febb9ac45 | ||
|
|
463044b64a | ||
|
|
9865ce9815 | ||
|
|
81d7774c80 | ||
|
|
22e04913a5 | ||
|
|
8e5893b708 | ||
|
|
99558928f0 | ||
|
|
a2efee8be9 | ||
|
|
a1d0b6cde2 | ||
|
|
8123e76e3c | ||
|
|
a28d1f2ffe | ||
|
|
f4314549c3 | ||
|
|
d416580456 | ||
|
|
93ce62536f | ||
|
|
312392d6ae | ||
|
|
01734e1f61 | ||
|
|
124063a2a4 | ||
|
|
b99da54d5a | ||
|
|
bc5d51806d | ||
|
|
f3ed5b1206 | ||
|
|
eb6c5d20f5 | ||
|
|
b70b5bd5fe | ||
|
|
5ac7d00e24 | ||
|
|
469d960f50 | ||
|
|
7eea365aa1 |
@@ -1,4 +1,11 @@
|
||||
<!--- This template provides sections for bugs and features. Please delete any irrelevant sections before submitting -->
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
#### Expected Behavior
|
||||
<!--- Required. Describe the behavior you expect to see for your case. -->
|
||||
@@ -24,4 +31,4 @@
|
||||
<!--- Required for Bugs, feature request can delete the line below. -->
|
||||
- [ ] I have provided detailed steps to reproduce the issue
|
||||
|
||||
<!--- Template inspired by https://github.com/stevemao/github-issue-templates -->
|
||||
<!--- Template inspired by https://github.com/stevemao/github-issue-templates -->
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
#### Expected Behavior
|
||||
<!--- Required. Describe the behavior you expect to see for your case. -->
|
||||
|
||||
#### Actual Behavior
|
||||
<!--- Required. Describe the actual behavior for your case. -->
|
||||
|
||||
#### Potential Solution
|
||||
<!--- Optional. Describe any potential solutions and/or thoughts as to what may be causing the difference between expected and actual behavior. -->
|
||||
|
||||
#### Checklist
|
||||
<!--- Confirm that you've provided all the required information. -->
|
||||
<!--- Required fields --->
|
||||
- [ ] I have completely filled out this template
|
||||
- [ ] I have confirmed that this issue exists on the current `master` branch
|
||||
- [ ] I have confirmed that this is not a duplicate issue by searching [issues](https://github.com/QuantConnect/Lean/issues)
|
||||
|
||||
<!--- Template inspired by https://github.com/stevemao/github-issue-templates -->
|
||||
11
.github/workflows/api-tests.yml
vendored
11
.github/workflows/api-tests.yml
vendored
@@ -9,14 +9,19 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
# Only run on push events (not on pull_request) for security reasons in order to be able to use secrets
|
||||
if: ${{ github.event_name == 'push' }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
- name: Run API Tests
|
||||
uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
|
||||
12
.github/workflows/gh-actions.yml
vendored
12
.github/workflows/gh-actions.yml
vendored
@@ -9,12 +9,18 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
|
||||
- uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
|
||||
2
.github/workflows/rebase-org-branches.yml
vendored
2
.github/workflows/rebase-org-branches.yml
vendored
@@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
||||
11
.github/workflows/regression-tests.yml
vendored
11
.github/workflows/regression-tests.yml
vendored
@@ -9,12 +9,17 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
|
||||
- uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
|
||||
11
.github/workflows/report-generator.yml
vendored
11
.github/workflows/report-generator.yml
vendored
@@ -9,12 +9,17 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
|
||||
- uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
|
||||
13
.github/workflows/research-regression-tests.yml
vendored
13
.github/workflows/research-regression-tests.yml
vendored
@@ -9,12 +9,17 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
|
||||
- uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
@@ -25,7 +30,7 @@ jobs:
|
||||
# install dependencies
|
||||
pip3 install papermill==2.4.0 clr-loader==0.1.6
|
||||
# install kernel
|
||||
dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.340501
|
||||
dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.607001
|
||||
# Add dotnet tools to Path
|
||||
export PATH="$HOME/.dotnet/tools:$PATH"
|
||||
# activate kernel for jupyter
|
||||
|
||||
17
.github/workflows/virtual-environments.yml
vendored
17
.github/workflows/virtual-environments.yml
vendored
@@ -9,12 +9,17 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Free space
|
||||
run: df -h && rm -rf /usr/share/dotnet && sudo rm -rf /usr/local/lib/android && sudo rm -rf /opt/ghc && rm -rf /opt/hostedtoolcache* && df -h
|
||||
- name: Liberate disk space
|
||||
uses: jlumbroso/free-disk-space@main
|
||||
with:
|
||||
tool-cache: true
|
||||
large-packages: false
|
||||
docker-images: false
|
||||
swap-storage: false
|
||||
|
||||
- uses: addnab/docker-run-action@v3
|
||||
with:
|
||||
@@ -48,10 +53,10 @@ jobs:
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorflowProbabilityTest" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
# Run Hvplot Python Package Test
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.HvplotTest" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
# Run Keras Python Package Test
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.KerasTest" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
# Run Transformers
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.Transformers" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.XTransformers" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
# Run Shap
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.ShapTest" --blame-hang-timeout 120seconds --blame-crash
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.ShapTest|KerasTest|PyvinecopulibTest" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.Mlforecast" --blame-hang-timeout 120seconds --blame-crash && \
|
||||
dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.MlxtendTest|Thinc" --blame-hang-timeout 120seconds --blame-crash
|
||||
|
||||
@@ -12,16 +12,16 @@ This document contains information regarding ways to use Visual Studio to work w
|
||||
|
||||
<h2>Option 1: Lean CLI</h2>
|
||||
|
||||
To use Lean CLI follow the instructions for installation and tutorial for usage in our [documentation](https://www.quantconnect.com/docs/v2/lean-cli/getting-started/lean-cli).
|
||||
To use Lean CLI follow the instructions for installation and tutorial for usage in our [documentation](https://www.quantconnect.com/docs/v2/lean-cli/key-concepts/getting-started).
|
||||
|
||||
<br />
|
||||
|
||||
<h2>Option 2: Install Locally</h2>
|
||||
|
||||
1. Install [.Net 6](https://dotnet.microsoft.com/download) for the project
|
||||
1. Install [.Net 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0) for the project
|
||||
|
||||
2. (Optional) Get [Python 3.8.13](https://www.python.org/downloads/release/python-3813/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-38) for your platform
|
||||
2. (Optional) Get [Python 3.11.11](https://www.python.org/downloads/release/python-31111/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-311) for your platform
|
||||
|
||||
3. Get [Visual Studio](https://visualstudio.microsoft.com/vs/)
|
||||
|
||||
@@ -35,7 +35,7 @@ Your environment is prepared and ready to run lean
|
||||
|
||||
<h1>How to use Lean</h1>
|
||||
|
||||
This section will cover configuring, launching and debugging lean. This is only applicable to option 2 from above. This does not apply to Lean CLI, please refer to [CLI documentation](https://www.quantconnect.com/docs/v2/lean-cli/getting-started/lean-cli)
|
||||
This section will cover configuring, launching and debugging lean. This is only applicable to option 2 from above. This does not apply to Lean CLI, please refer to [CLI documentation](https://www.quantconnect.com/docs/v2/lean-cli/key-concepts/getting-started)
|
||||
|
||||
<br />
|
||||
|
||||
|
||||
6
.vscode/readme.md
vendored
6
.vscode/readme.md
vendored
@@ -51,10 +51,10 @@ If you would like to mount any additional local files to your container, checkou
|
||||
|
||||
<h2>Option 3: Install Dependencies Locally</h2>
|
||||
|
||||
1. Install [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) for the project
|
||||
1. Install [.NET 9](https://dotnet.microsoft.com/en-us/download/dotnet/9.0) for the project
|
||||
|
||||
2. (Optional) Get [Python 3.8.13](https://www.python.org/downloads/release/python-3813/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-38) for your platform
|
||||
2. (Optional) Get [Python 3.11.11](https://www.python.org/downloads/release/python-31111/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-311) for your platform
|
||||
|
||||
3. Get [Visual Studio Code](https://code.visualstudio.com/download)
|
||||
- Get the Extension [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) for C# Debugging
|
||||
|
||||
151
Algorithm.CSharp/AddBetaIndicatorNewAssetsRegressionAlgorithm.cs
Normal file
151
Algorithm.CSharp/AddBetaIndicatorNewAssetsRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Brokerages;
|
||||
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression test to explain how Beta indicator works
|
||||
/// </summary>
|
||||
public class AddBetaIndicatorNewAssetsRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Beta _beta;
|
||||
private SimpleMovingAverage _sma;
|
||||
private decimal _lastSMAValue;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2015, 05, 08);
|
||||
SetEndDate(2017, 06, 15);
|
||||
SetCash(10000);
|
||||
|
||||
AddCrypto("BTCUSD", Resolution.Daily);
|
||||
AddEquity("SPY", Resolution.Daily);
|
||||
|
||||
EnableAutomaticIndicatorWarmUp = true;
|
||||
_beta = B("BTCUSD", "SPY", 3, Resolution.Daily);
|
||||
_sma = SMA("SPY", 3, Resolution.Daily);
|
||||
_lastSMAValue = 0;
|
||||
|
||||
if (!_beta.IsReady)
|
||||
{
|
||||
throw new RegressionTestException("Beta indicator was expected to be ready");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
var price = Securities["BTCUSD"].Price;
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var quantityToBuy = (int)(Portfolio.Cash * 0.05m / price);
|
||||
Buy("BTCUSD", quantityToBuy);
|
||||
}
|
||||
|
||||
if (Math.Abs(_beta.Current.Value) > 2)
|
||||
{
|
||||
Liquidate("BTCUSD");
|
||||
Log("Liquidated BTCUSD due to high Beta");
|
||||
}
|
||||
|
||||
Log($"Beta between BTCUSD and SPY is: {_beta.Current.Value}");
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
var order = Transactions.GetOrderById(orderEvent.OrderId);
|
||||
var goUpwards = _lastSMAValue < _sma.Current.Value;
|
||||
_lastSMAValue = _sma.Current.Value;
|
||||
|
||||
if (order.Status == OrderStatus.Filled)
|
||||
{
|
||||
if (order.Type == OrderType.Limit && Math.Abs(_beta.Current.Value - 1) < 0.2m && goUpwards)
|
||||
{
|
||||
Transactions.CancelOpenOrders(order.Symbol);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.Status == OrderStatus.Canceled)
|
||||
{
|
||||
Log(orderEvent.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
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 virtual List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 5798;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 77;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "436"},
|
||||
{"Average Win", "0.28%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "1.926%"},
|
||||
{"Drawdown", "1.000%"},
|
||||
{"Expectancy", "1.650"},
|
||||
{"Start Equity", "10000.00"},
|
||||
{"End Equity", "10411.11"},
|
||||
{"Net Profit", "4.111%"},
|
||||
{"Sharpe Ratio", "0.332"},
|
||||
{"Sortino Ratio", "0.313"},
|
||||
{"Probabilistic Sharpe Ratio", "74.084%"},
|
||||
{"Loss Rate", "90%"},
|
||||
{"Win Rate", "10%"},
|
||||
{"Profit-Loss Ratio", "25.26"},
|
||||
{"Alpha", "0.003"},
|
||||
{"Beta", "0.001"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-0.495"},
|
||||
{"Tracking Error", "0.111"},
|
||||
{"Treynor Ratio", "2.716"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$87000.00"},
|
||||
{"Lowest Capacity Asset", "BTCUSD 2XR"},
|
||||
{"Portfolio Turnover", "2.22%"},
|
||||
{"OrderListHash", "4fcffc45d82203bb6ded8a0e86070b4f"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
if (!_beta.IsReady)
|
||||
{
|
||||
throw new RegressionTestException("_beta indicator was expected to be ready");
|
||||
throw new RegressionTestException("Beta indicator was expected to be ready");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
LimitOrder("IBM", 10, price * 0.1m);
|
||||
StopMarketOrder("IBM", 10, price / 0.1m);
|
||||
}
|
||||
|
||||
|
||||
if (_beta.Current.Value < 0m || _beta.Current.Value > 2.80m)
|
||||
{
|
||||
throw new RegressionTestException($"_beta value was expected to be between 0 and 2.80 but was {_beta.Current.Value}");
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
contractDepthOffset: 0
|
||||
);
|
||||
|
||||
_futureContract = AddFutureContract(FutureChainProvider.GetFutureContractList(_continuousContract.Symbol, Time).First());
|
||||
_futureContract = AddFutureContract(FuturesChain(_continuousContract.Symbol).First());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,12 +115,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 76;
|
||||
public long DataPoints => 61;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -169,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -93,12 +93,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 12172;
|
||||
public long DataPoints => 9922;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "20"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "386219349.202%"},
|
||||
{"Compounding Annual Return", "88398927.578%"},
|
||||
{"Drawdown", "5.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var chain in slice.OptionChains.Values)
|
||||
foreach (var chain in slice.OptionChains.Values.OrderBy(x => x.Symbol.Underlying.ID.Date))
|
||||
{
|
||||
var futureInvested = false;
|
||||
var optionInvested = false;
|
||||
@@ -220,7 +220,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 608380;
|
||||
public long DataPoints => 319494;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -240,7 +240,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "347.065%"},
|
||||
{"Compounding Annual Return", "309.669%"},
|
||||
{"Drawdown", "0.900%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2013, 10, 10);
|
||||
|
||||
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
|
||||
_symbol = FuturesChain(SP500).First();
|
||||
|
||||
// Test case: custom IndicatorBase<QuoteBar> indicator using Future unsubscribed symbol
|
||||
var indicator1 = new CustomIndicator();
|
||||
@@ -151,7 +151,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 84;
|
||||
public int AlgorithmHistoryDataPoints => 85;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 21;
|
||||
public int AlgorithmHistoryDataPoints => 18;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -18,7 +18,6 @@ using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Securities;
|
||||
@@ -118,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 713371;
|
||||
public long DataPoints => 162575;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -161,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Estimated Strategy Capacity", "$7100000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "2.33%"},
|
||||
{"OrderListHash", "9c524830ffc7354327638142ae62acd2"}
|
||||
{"OrderListHash", "04670183a0a4c9160167415aa5102499"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 2217326;
|
||||
public long DataPoints => 504530;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
_continuousContract.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(180));
|
||||
_mappedSymbol = _continuousContract.Mapped;
|
||||
|
||||
var benchmark = AddIndex("SX5E", market: Market.EUREX);
|
||||
var benchmark = AddIndex("SX5E");
|
||||
SetBenchmark(benchmark.Symbol);
|
||||
|
||||
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
|
||||
@@ -190,12 +190,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 133945;
|
||||
public long DataPoints => 94326;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 26;
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
@@ -233,7 +233,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Estimated Strategy Capacity", "€2300000000.00"},
|
||||
{"Lowest Capacity Asset", "FESX YJHOAMPYKRS5"},
|
||||
{"Portfolio Turnover", "0.40%"},
|
||||
{"OrderListHash", "54040d29a467becaedcf59d79323321b"}
|
||||
{"OrderListHash", "ac9acc478ba1afe53993cdbb92f8ec6e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1199;
|
||||
public long DataPoints => 727;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -219,7 +219,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "0.13%"},
|
||||
{"OrderListHash", "273dd05b937c075b75baf8af46d3c7de"}
|
||||
{"OrderListHash", "7c8700a9baa24f6f76d866e7d88cc19c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 75403;
|
||||
public long DataPoints => 40308;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -169,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "2700"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-99.777%"},
|
||||
{"Compounding Annual Return", "-99.597%"},
|
||||
{"Drawdown", "4.400%"},
|
||||
{"Expectancy", "-0.724"},
|
||||
{"Start Equity", "1000000"},
|
||||
|
||||
@@ -18,8 +18,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
@@ -104,6 +104,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
if (changes.RemovedSecurities.Count > 0 &&
|
||||
Portfolio.Invested &&
|
||||
Securities.Values.Where(x => x.Invested).All(x => x.Exchange.Hours.IsOpen(Time, true)))
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@@ -117,7 +127,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 12453;
|
||||
public virtual long DataPoints => 5861;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -160,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
|
||||
{"Portfolio Turnover", "0.92%"},
|
||||
{"OrderListHash", "7afa589d648c3f24253cd59156a2014e"}
|
||||
{"OrderListHash", "c0713abdc4fb059c2be797fce36e4f36"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 57759;
|
||||
public virtual long DataPoints => 24883;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 163416;
|
||||
public override long DataPoints => 70262;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
@@ -140,12 +140,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 48690;
|
||||
public virtual long DataPoints => 25316;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 5305;
|
||||
public virtual int AlgorithmHistoryDataPoints => 6075;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 147771;
|
||||
public override long DataPoints => 76063;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -14,12 +14,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -41,40 +36,40 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 87290;
|
||||
public override long DataPoints => 25312;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "716"},
|
||||
{"Total Orders", "718"},
|
||||
{"Average Win", "0.03%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-1.716%"},
|
||||
{"Compounding Annual Return", "-1.720%"},
|
||||
{"Drawdown", "1.700%"},
|
||||
{"Expectancy", "-0.770"},
|
||||
{"Start Equity", "1000000"},
|
||||
{"End Equity", "982718.38"},
|
||||
{"Net Profit", "-1.728%"},
|
||||
{"Sharpe Ratio", "-8.845"},
|
||||
{"Sortino Ratio", "-5.449"},
|
||||
{"End Equity", "982676.58"},
|
||||
{"Net Profit", "-1.732%"},
|
||||
{"Sharpe Ratio", "-8.877"},
|
||||
{"Sortino Ratio", "-5.476"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "96%"},
|
||||
{"Win Rate", "4%"},
|
||||
{"Profit-Loss Ratio", "4.89"},
|
||||
{"Profit-Loss Ratio", "4.90"},
|
||||
{"Alpha", "-0.018"},
|
||||
{"Beta", "-0.002"},
|
||||
{"Annual Standard Deviation", "0.002"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.483"},
|
||||
{"Information Ratio", "-1.484"},
|
||||
{"Tracking Error", "0.089"},
|
||||
{"Treynor Ratio", "9.102"},
|
||||
{"Total Fees", "$1634.12"},
|
||||
{"Treynor Ratio", "9.171"},
|
||||
{"Total Fees", "$1638.42"},
|
||||
{"Estimated Strategy Capacity", "$8000.00"},
|
||||
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
|
||||
{"Portfolio Turnover", "20.10%"},
|
||||
{"OrderListHash", "aa7e574f86b70428ca0afae381be80ba"}
|
||||
{"Portfolio Turnover", "20.14%"},
|
||||
{"OrderListHash", "dedcc487d64e2f601990fc70393c89ed"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 224662;
|
||||
public long DataPoints => 117079;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -14,14 +14,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -43,40 +36,40 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 14895;
|
||||
public override long DataPoints => 5965;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "36"},
|
||||
{"Total Orders", "32"},
|
||||
{"Average Win", "0.33%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "0.102%"},
|
||||
{"Average Loss", "-0.04%"},
|
||||
{"Compounding Annual Return", "0.110%"},
|
||||
{"Drawdown", "0.300%"},
|
||||
{"Expectancy", "0.171"},
|
||||
{"Expectancy", "0.184"},
|
||||
{"Start Equity", "1000000"},
|
||||
{"End Equity", "1001024.4"},
|
||||
{"Net Profit", "0.102%"},
|
||||
{"Sharpe Ratio", "-1.702"},
|
||||
{"Sortino Ratio", "-0.836"},
|
||||
{"Probabilistic Sharpe Ratio", "14.653%"},
|
||||
{"Loss Rate", "89%"},
|
||||
{"Win Rate", "11%"},
|
||||
{"Profit-Loss Ratio", "9.54"},
|
||||
{"End Equity", "1001108"},
|
||||
{"Net Profit", "0.111%"},
|
||||
{"Sharpe Ratio", "-1.688"},
|
||||
{"Sortino Ratio", "-0.772"},
|
||||
{"Probabilistic Sharpe Ratio", "14.944%"},
|
||||
{"Loss Rate", "88%"},
|
||||
{"Win Rate", "12%"},
|
||||
{"Profit-Loss Ratio", "8.47"},
|
||||
{"Alpha", "-0.007"},
|
||||
{"Beta", "0.002"},
|
||||
{"Annual Standard Deviation", "0.004"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.353"},
|
||||
{"Tracking Error", "0.089"},
|
||||
{"Treynor Ratio", "-4.126"},
|
||||
{"Total Fees", "$80.60"},
|
||||
{"Treynor Ratio", "-4.099"},
|
||||
{"Total Fees", "$72.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
|
||||
{"Portfolio Turnover", "0.97%"},
|
||||
{"OrderListHash", "52c852d720692fab1e12212b2aba03d4"}
|
||||
{"Portfolio Turnover", "0.87%"},
|
||||
{"OrderListHash", "8b8b733248a21fc717079be54b2e844c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 228934;
|
||||
public override long DataPoints => 67924;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
|
||||
var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>();
|
||||
if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 23, 0, 0))
|
||||
if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 15, 15, 0))
|
||||
{
|
||||
throw new ArgumentException($"Unexpected open interest time: {openInterest.Single().EndTime}");
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 121;
|
||||
public override long DataPoints => 122;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -126,7 +126,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "11"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "621.484%"},
|
||||
{"Compounding Annual Return", "653.545%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "1000000"},
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 356;
|
||||
public override long DataPoints => 360;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -121,20 +121,20 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "5"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.69%"},
|
||||
{"Average Win", "0.63%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "54.478%"},
|
||||
{"Drawdown", "0.400%"},
|
||||
{"Expectancy", "-0.5"},
|
||||
{"Expectancy", "23.219"},
|
||||
{"Start Equity", "1000000"},
|
||||
{"End Equity", "1006025"},
|
||||
{"Net Profit", "0.602%"},
|
||||
{"Sharpe Ratio", "2.62"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "63.221%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "23.22"},
|
||||
{"Alpha", "0.067"},
|
||||
{"Beta", "-0.013"},
|
||||
{"Annual Standard Deviation", "0.004"},
|
||||
|
||||
@@ -127,11 +127,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "10"},
|
||||
{"Average Win", "0.47%"},
|
||||
{"Average Win", "0.46%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "101.998%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "24.484"},
|
||||
{"Expectancy", "24.137"},
|
||||
{"Start Equity", "1000000"},
|
||||
{"End Equity", "1009050"},
|
||||
{"Net Profit", "0.905%"},
|
||||
@@ -140,7 +140,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Probabilistic Sharpe Ratio", "95.546%"},
|
||||
{"Loss Rate", "50%"},
|
||||
{"Win Rate", "50%"},
|
||||
{"Profit-Loss Ratio", "49.97"},
|
||||
{"Profit-Loss Ratio", "49.27"},
|
||||
{"Alpha", "-2.01"},
|
||||
{"Beta", "0.307"},
|
||||
{"Annual Standard Deviation", "0.021"},
|
||||
|
||||
@@ -49,13 +49,13 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
private bool _firstCall = true;
|
||||
|
||||
private PortfolioTarget[] _targets = new PortfolioTarget[4];
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Symbols accepted by Collective2. Collective2 accepts stock,
|
||||
/// future, forex and US stock option symbols
|
||||
/// </summary>
|
||||
private List<Symbol> _symbols = new()
|
||||
{
|
||||
{
|
||||
QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA, null, null),
|
||||
QuantConnect.Symbol.Create("EURUSD", SecurityType.Forex, Market.Oanda, null, null),
|
||||
QuantConnect.Symbol.CreateFuture("ES", Market.CME, new DateTime(2023, 12, 15), null),
|
||||
@@ -95,15 +95,19 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// Initialize this flag, to check when the ema indicators crosses between themselves
|
||||
_emaFastIsNotSet = true;
|
||||
|
||||
// Set Collective2 signal export provider
|
||||
// Set Collective2 signal export provider.
|
||||
// If using the Collective2 white-label API, you can specify it in the constructor with the optional parameter `useWhiteLabelApi`:
|
||||
// e.g. new Collective2SignalExport(_collective2ApiKey, _collective2SystemId, useWhiteLabelApi: true)
|
||||
// The API url can also be overridden by setting the Destination property:
|
||||
// e.g. new Collective2SignalExport(_collective2ApiKey, _collective2SystemId) { Destination = new Uri("your url") }
|
||||
SignalExport.AddSignalExportProviders(new Collective2SignalExport(_collective2ApiKey, _collective2SystemId));
|
||||
|
||||
SetWarmUp(100);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reduce the quantity of holdings for SPY or increase it, depending the case,
|
||||
/// when the EMA's indicators crosses between themselves, then send a signal to
|
||||
/// Reduce the quantity of holdings for SPY or increase it, depending the case,
|
||||
/// when the EMA's indicators crosses between themselves, then send a signal to
|
||||
/// Collective2 API
|
||||
/// </summary>
|
||||
/// <param name="slice"></param>
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data.Market;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm asserts the consolidated US equity daily bars from the hour bars exactly matches
|
||||
/// the daily bars returned from the database
|
||||
/// </summary>
|
||||
public class ConsolidateHourBarsIntoDailyBarsRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _spy;
|
||||
private RelativeStrengthIndex _rsi;
|
||||
private RelativeStrengthIndex _rsiTimeDelta;
|
||||
private Dictionary<DateTime, decimal> _values = new();
|
||||
private int _count;
|
||||
private bool _indicatorsCompared;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 5, 1);
|
||||
SetEndDate(2020, 6, 5);
|
||||
|
||||
_spy = AddEquity("SPY", Resolution.Hour).Symbol;
|
||||
|
||||
// We will use these two indicators to compare the daily consolidated bars equals
|
||||
// the ones returned from the database. We use this specific type of indicator as
|
||||
// it depends on its previous values. Thus, if at some point the bars received by
|
||||
// the indicators differ, so will their final values
|
||||
_rsi = new RelativeStrengthIndex("FIRST", 15, MovingAverageType.Wilders);
|
||||
RegisterIndicator(_spy, _rsi, Resolution.Daily, selector: (bar) =>
|
||||
{
|
||||
var tradeBar = (TradeBar)bar;
|
||||
return (tradeBar.Close + tradeBar.Open) / 2;
|
||||
});
|
||||
|
||||
// We won't register this indicator as we will update it manually at the end of the
|
||||
// month, so that we can compare the values of the indicator that received consolidated
|
||||
// bars and the values of this one
|
||||
_rsiTimeDelta = new RelativeStrengthIndex("SECOND" ,15, MovingAverageType.Wilders);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (IsWarmingUp) return;
|
||||
|
||||
if (slice.ContainsKey(_spy) && slice[_spy] != null)
|
||||
{
|
||||
if (Time.Month == EndDate.Month)
|
||||
{
|
||||
var history = History(_spy, _count, Resolution.Daily);
|
||||
foreach (var bar in history)
|
||||
{
|
||||
var time = bar.EndTime.Date;
|
||||
var average = (bar.Close + bar.Open) / 2;
|
||||
_rsiTimeDelta.Update(bar.EndTime, average);
|
||||
if (_rsiTimeDelta.Current.Value != _values[time])
|
||||
{
|
||||
throw new RegressionTestException($"Both {_rsi.Name} and {_rsiTimeDelta.Name} should have the same values, but they differ. {_rsi.Name}: {_values[time]} | {_rsiTimeDelta.Name}: {_rsiTimeDelta.Current.Value}");
|
||||
}
|
||||
}
|
||||
_indicatorsCompared = true;
|
||||
Quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
_values[Time.Date] = _rsi.Current.Value;
|
||||
|
||||
// Since the symbol resolution is hour and the symbol is equity, we know the last bar received in a day will
|
||||
// be at the market close, this is 16h. We need to count how many daily bars were consolidated in order to know
|
||||
// how many we need to request from the history
|
||||
if (Time.Hour == 16)
|
||||
{
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_indicatorsCompared)
|
||||
{
|
||||
throw new RegressionTestException($"Indicators {_rsi.Name} and {_rsiTimeDelta.Name} should have been compared, but they were not. Please make sure the indicators are getting SPY data");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 290;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 20;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "100000"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "-5.215"},
|
||||
{"Tracking Error", "0.159"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Portfolio Turnover", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(2020, 01, 20);
|
||||
|
||||
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
var symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
|
||||
var symbol = FuturesChain(SP500).First();
|
||||
_future = AddFutureContract(symbol);
|
||||
|
||||
var tradableDatesCount = QuantConnect.Time.EachTradeableDayInTimeZone(_future.Exchange.Hours,
|
||||
@@ -194,7 +194,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 713371;
|
||||
public long DataPoints => 162571;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 723498;
|
||||
public long DataPoints => 172698;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 9951;
|
||||
public virtual long DataPoints => 5469;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -160,7 +160,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$2.15"},
|
||||
{"Estimated Strategy Capacity", "$100000000.00"},
|
||||
{"Estimated Strategy Capacity", "$130000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
|
||||
{"Portfolio Turnover", "41.23%"},
|
||||
{"OrderListHash", "b9f8e1a0704c086944e5df07e0ab04d6"}
|
||||
|
||||
@@ -34,6 +34,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 15813;
|
||||
public override long DataPoints => 9079;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
}
|
||||
|
||||
return universe.Select(x => x);
|
||||
return universe;
|
||||
});
|
||||
|
||||
_milk.SetFilter(universe =>
|
||||
@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
}
|
||||
}
|
||||
|
||||
return universe.Select(x => x);
|
||||
return universe;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 596358;
|
||||
public long DataPoints => 445961;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 19888;
|
||||
public long DataPoints => 10883;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -98,7 +98,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-99.258%"},
|
||||
{"Compounding Annual Return", "-99.012%"},
|
||||
{"Drawdown", "6.300%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* 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;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing GH issue #8386 and other related bugs.
|
||||
/// It asserts that open positions are liquidated when a contract is delisted, even if the contract was added as an internal subscription.
|
||||
/// It also asserts that the contract is not tradable after being delisted.
|
||||
/// </summary>
|
||||
public class ContinuousFutureOpenPositionsLiquidationOnDelistingRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Future _continuousContract;
|
||||
private Symbol _prevContractSymbol;
|
||||
private bool _traded;
|
||||
private bool _mapped;
|
||||
private bool _delistedContractChecked;
|
||||
private DateTime _firstMappedContractRemovalTime;
|
||||
private int _removalCount;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 12, 30);
|
||||
|
||||
_continuousContract = AddFuture(Futures.Indices.SP500EMini,
|
||||
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
|
||||
dataMappingMode: DataMappingMode.OpenInterest,
|
||||
contractDepthOffset: 0
|
||||
);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (!_traded && _continuousContract.HasData)
|
||||
{
|
||||
var ticket = MarketOrder(_continuousContract.Mapped, 1);
|
||||
if (ticket.Status == OrderStatus.Invalid)
|
||||
{
|
||||
throw new RegressionTestException($"Order should be valid: {ticket}");
|
||||
}
|
||||
_traded = true;
|
||||
}
|
||||
|
||||
if (slice.SymbolChangedEvents.Count > 0)
|
||||
{
|
||||
foreach (var change in slice.SymbolChangedEvents.Values)
|
||||
{
|
||||
Debug($"[{Time}] :: Mapping: {change}");
|
||||
_prevContractSymbol = Symbol(change.OldSymbol);
|
||||
_mapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_delistedContractChecked &&
|
||||
_prevContractSymbol != null &&
|
||||
Time.Date > _prevContractSymbol.ID.Date &&
|
||||
IsMarketOpen(_prevContractSymbol))
|
||||
{
|
||||
_delistedContractChecked = true;
|
||||
var delistedContract = Securities.Total.Single(sec => sec.Symbol == _prevContractSymbol);
|
||||
|
||||
if (delistedContract.Invested)
|
||||
{
|
||||
throw new RegressionTestException($"Position should be closed when {_prevContractSymbol} got delisted {_prevContractSymbol.ID.Date}");
|
||||
}
|
||||
|
||||
if (!delistedContract.IsDelisted)
|
||||
{
|
||||
throw new RegressionTestException($"Contract should be delisted: {delistedContract.Symbol}");
|
||||
}
|
||||
|
||||
if (delistedContract.IsTradable)
|
||||
{
|
||||
throw new RegressionTestException($"Contract should not be tradable: {delistedContract.Symbol}");
|
||||
}
|
||||
|
||||
var ticket = MarketOrder(_prevContractSymbol, 1);
|
||||
|
||||
if (ticket.Status != OrderStatus.Invalid)
|
||||
{
|
||||
throw new RegressionTestException($"Delisted contract order should be invalid: {ticket}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
if (_prevContractSymbol != null)
|
||||
{
|
||||
if (changes.RemovedSecurities.Any(x => x.Symbol == _prevContractSymbol))
|
||||
{
|
||||
throw new RegressionTestException($"Previous contract symbol {_prevContractSymbol} should not be removed as a non-internal security");
|
||||
}
|
||||
|
||||
changes.FilterInternalSecurities = false;
|
||||
|
||||
if (!changes.RemovedSecurities.Any(x => x.Symbol == _prevContractSymbol))
|
||||
{
|
||||
throw new RegressionTestException($"Previous contract symbol {_prevContractSymbol} should be removed as an internal security");
|
||||
}
|
||||
|
||||
_firstMappedContractRemovalTime = Time;
|
||||
_removalCount++;
|
||||
}
|
||||
|
||||
changes.FilterInternalSecurities = false;
|
||||
Debug($"[{Time}] :: {changes}");
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug($"[{Time}] :: Order event: {orderEvent}");
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_traded)
|
||||
{
|
||||
throw new RegressionTestException("No trades have been made");
|
||||
}
|
||||
|
||||
if (!_mapped)
|
||||
{
|
||||
throw new RegressionTestException("No mapping events have been fired");
|
||||
}
|
||||
|
||||
if (!_delistedContractChecked)
|
||||
{
|
||||
throw new RegressionTestException("No delisted contract has been checked");
|
||||
}
|
||||
|
||||
if (_prevContractSymbol == null)
|
||||
{
|
||||
throw new RegressionTestException("No previous contract symbol has been set");
|
||||
}
|
||||
|
||||
var tradedContract = Securities.Total.Single(sec => sec.Symbol == _prevContractSymbol);
|
||||
if (tradedContract.Invested)
|
||||
{
|
||||
throw new RegressionTestException($"Position should be closed when {_prevContractSymbol} got delisted on {_prevContractSymbol.ID.Date}");
|
||||
}
|
||||
|
||||
if (_firstMappedContractRemovalTime == default || _firstMappedContractRemovalTime >= _prevContractSymbol.ID.Date)
|
||||
{
|
||||
throw new RegressionTestException($"First mapped contract should have been removed before it's expiry date");
|
||||
}
|
||||
|
||||
if (_removalCount != 1)
|
||||
{
|
||||
throw new RegressionTestException($"The mapped contract should have been removed once only");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 159274;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "2"},
|
||||
{"Average Win", "7.02%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "34.386%"},
|
||||
{"Drawdown", "1.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "107016.6"},
|
||||
{"Net Profit", "7.017%"},
|
||||
{"Sharpe Ratio", "3.217"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "99.828%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.227"},
|
||||
{"Beta", "0.109"},
|
||||
{"Annual Standard Deviation", "0.084"},
|
||||
{"Annual Variance", "0.007"},
|
||||
{"Information Ratio", "-1.122"},
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "2.49"},
|
||||
{"Total Fees", "$2.15"},
|
||||
{"Estimated Strategy Capacity", "$1700000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "2.01%"},
|
||||
{"OrderListHash", "838e662caaa5a385c43ef27df1efbaf4"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Data.Market;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Securities.Future;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
@@ -31,7 +30,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public class ContinuousFutureRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private List<SymbolChangedEvent> _mappings = new();
|
||||
private List<Symbol> _previousMappedContractSymbols = new();
|
||||
private Symbol _currentMappedSymbol;
|
||||
private Future _continuousContract;
|
||||
private DateTime _lastMonth;
|
||||
@@ -77,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
if (changedEvent.Symbol == _continuousContract.Symbol)
|
||||
{
|
||||
_mappings.Add(changedEvent);
|
||||
_previousMappedContractSymbols.Add(Symbol(changedEvent.OldSymbol));
|
||||
Log($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
|
||||
if (_currentMappedSymbol == _continuousContract.Mapped)
|
||||
@@ -144,15 +143,20 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
var expectedMappingCounts = 2;
|
||||
if (_mappings.Count != expectedMappingCounts)
|
||||
if (_previousMappedContractSymbols.Count != expectedMappingCounts)
|
||||
{
|
||||
throw new RegressionTestException($"Unexpected symbol changed events: {_mappings.Count}, was expecting {expectedMappingCounts}");
|
||||
throw new RegressionTestException($"Unexpected symbol changed events: {_previousMappedContractSymbols.Count}, was expecting {expectedMappingCounts}");
|
||||
}
|
||||
|
||||
var securities = Securities.Total.Where(sec => !sec.IsTradable && !sec.Symbol.IsCanonical() && sec.Symbol.SecurityType == SecurityType.Future).ToList();
|
||||
if (securities.Count != 1)
|
||||
var delistedSecurities = _previousMappedContractSymbols
|
||||
.Select(x => Securities.Total.Single(sec => sec.Symbol == x))
|
||||
.Where(x => x.Symbol.ID.Date < Time)
|
||||
.ToList();
|
||||
var markedDelistedSecurities = delistedSecurities.Where(x => x.IsDelisted && !x.IsTradable).ToList();
|
||||
if (markedDelistedSecurities.Count != delistedSecurities.Count)
|
||||
{
|
||||
throw new RegressionTestException($"We should have a single non tradable future contract security! found: {securities.Count}");
|
||||
throw new RegressionTestException($"Not all delisted contracts are properly market as delisted and non-tradable: " +
|
||||
$"only {markedDelistedSecurities.Count} are marked, was expecting {delistedSecurities.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +173,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 713371;
|
||||
public long DataPoints => 162575;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -186,18 +190,18 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "3"},
|
||||
{"Average Win", "1.50%"},
|
||||
{"Total Orders", "4"},
|
||||
{"Average Win", "0.84%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "3.337%"},
|
||||
{"Compounding Annual Return", "3.380%"},
|
||||
{"Drawdown", "1.600%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "101666.4"},
|
||||
{"Net Profit", "1.666%"},
|
||||
{"Sharpe Ratio", "0.594"},
|
||||
{"Sortino Ratio", "0.198"},
|
||||
{"Probabilistic Sharpe Ratio", "44.801%"},
|
||||
{"End Equity", "101687.3"},
|
||||
{"Net Profit", "1.687%"},
|
||||
{"Sharpe Ratio", "0.605"},
|
||||
{"Sortino Ratio", "0.202"},
|
||||
{"Probabilistic Sharpe Ratio", "45.198%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
@@ -205,14 +209,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Beta", "0.134"},
|
||||
{"Annual Standard Deviation", "0.027"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "-2.69"},
|
||||
{"Information Ratio", "-2.687"},
|
||||
{"Tracking Error", "0.075"},
|
||||
{"Treynor Ratio", "0.119"},
|
||||
{"Treynor Ratio", "0.121"},
|
||||
{"Total Fees", "$6.45"},
|
||||
{"Estimated Strategy Capacity", "$8000000000.00"},
|
||||
{"Estimated Strategy Capacity", "$2600000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "1.39%"},
|
||||
{"OrderListHash", "40c1137e0bc83b2bc920495af119c8fc"}
|
||||
{"Portfolio Turnover", "1.88%"},
|
||||
{"OrderListHash", "1287c3b983c5bac6491bb5ac296c4b55"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1022;
|
||||
public override long DataPoints => 483;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1017;
|
||||
public override long DataPoints => 479;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1015;
|
||||
public override long DataPoints => 483;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 18850;
|
||||
public override long DataPoints => 7424;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 18844;
|
||||
public override long DataPoints => 7440;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 18846;
|
||||
public override long DataPoints => 7434;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1127376;
|
||||
public override long DataPoints => 444159;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1127374;
|
||||
public override long DataPoints => 445123;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1127488;
|
||||
public override long DataPoints => 444757;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1267;
|
||||
public long DataPoints => 848;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
134
Algorithm.CSharp/CorrelationTypeComparisonRegressionAlgorithm.cs
Normal file
134
Algorithm.CSharp/CorrelationTypeComparisonRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Compares two correlation types and asserts they are not equal during the algorithm's execution.
|
||||
/// </summary>
|
||||
public class CorrelationTypeComparisonRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Correlation _correlationPearson;
|
||||
private Correlation _correlationSpearman;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08); //Set Start Date
|
||||
SetEndDate(2013, 10, 17); //Set End Date
|
||||
var symbol = AddEquity("AAPL", Resolution.Daily).Symbol;
|
||||
var spy = AddEquity("SPY", Resolution.Daily).Symbol;
|
||||
_correlationPearson = C(symbol, spy, 5, CorrelationType.Pearson);
|
||||
_correlationSpearman = C(symbol, spy, 5, CorrelationType.Spearman);
|
||||
}
|
||||
|
||||
/// <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 slice)
|
||||
{
|
||||
if (_correlationPearson.IsReady && _correlationSpearman.IsReady)
|
||||
{
|
||||
var pearsonValue = _correlationPearson.Current.Value;
|
||||
var spearmanValue = _correlationSpearman.Current.Value;
|
||||
|
||||
// Check that the correlation values are not the same
|
||||
if (pearsonValue == spearmanValue)
|
||||
{
|
||||
// Throw an exception if the correlation values are equal
|
||||
throw new RegressionTestException($"Error: Pearson and Spearman correlation values are the same: Pearson = {pearsonValue}, Spearman = {spearmanValue}. This should not happen.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// End of algorithm run event handler. This method is called at the end of a backtest or live trading operation. Intended for closing out logs.
|
||||
/// </summary>
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_correlationPearson.IsReady || !_correlationSpearman.IsReady)
|
||||
{
|
||||
throw new RegressionTestException("Error: Both correlation values should be ready at the end of the algorithm.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <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 => true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 80;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "100000"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "-19.184"},
|
||||
{"Tracking Error", "0.138"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Portfolio Turnover", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm asserting that the option chain data has valid open interest values for daily resolution.
|
||||
/// Reproduces GH issue #8421.
|
||||
/// </summary>
|
||||
public class DailyOptionChainOpenInterestDataWithStrictDailyEndTimesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _symbol;
|
||||
|
||||
private List<decimal> _openInterests = new();
|
||||
|
||||
public virtual bool DailyPreciseEndTime => true;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Settings.DailyPreciseEndTime = DailyPreciseEndTime;
|
||||
|
||||
SetStartDate(2014, 06, 01);
|
||||
SetEndDate(2014, 07, 06);
|
||||
|
||||
var option = AddOption("AAPL", Resolution.Daily);
|
||||
option.SetFilter(-5, +5, 0, 365);
|
||||
|
||||
_symbol = option.Symbol;
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (slice.OptionChains.TryGetValue(_symbol, out var chain) && chain.Contracts.Count > 0)
|
||||
{
|
||||
var openInterest = chain.Sum(x => x.OpenInterest);
|
||||
_openInterests.Add(openInterest);
|
||||
Debug($"[{Time}] Sum of open interest: {openInterest}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_openInterests.Count == 0)
|
||||
{
|
||||
throw new RegressionTestException("No option chain data was received by the algorithm.");
|
||||
}
|
||||
|
||||
if (_openInterests.All(x => x == 0))
|
||||
{
|
||||
throw new RegressionTestException("Contracts received didn't have valid open interest values.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 List<Language> Languages { get; } = new() { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 47132;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "100000"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "-5.732"},
|
||||
{"Tracking Error", "0.05"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Portfolio Turnover", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm asserting that the option chain data has valid open interest values for daily resolution.
|
||||
/// Reproduces GH issue #8421.
|
||||
/// </summary>
|
||||
public class DailyOptionChainOpenInterestDataWithoutStrictDailyEndTimesRegressionAlgorithm : DailyOptionChainOpenInterestDataWithStrictDailyEndTimesRegressionAlgorithm
|
||||
{
|
||||
public override bool DailyPreciseEndTime => false;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 46264;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 516622;
|
||||
public long DataPoints => 70735;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 1679;
|
||||
public override long DataPoints => 1235;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
@@ -38,30 +38,30 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "2"},
|
||||
{"Average Win", "7.78%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "38.564%"},
|
||||
{"Compounding Annual Return", "38.609%"},
|
||||
{"Drawdown", "0.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "107779.1"},
|
||||
{"Net Profit", "7.779%"},
|
||||
{"Sharpe Ratio", "3.132"},
|
||||
{"Sharpe Ratio", "3.128"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "99.474%"},
|
||||
{"Probabilistic Sharpe Ratio", "99.450%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.145"},
|
||||
{"Beta", "0.271"},
|
||||
{"Annual Standard Deviation", "0.081"},
|
||||
{"Annual Variance", "0.006"},
|
||||
{"Annual Variance", "0.007"},
|
||||
{"Information Ratio", "-1.459"},
|
||||
{"Tracking Error", "0.099"},
|
||||
{"Treynor Ratio", "0.932"},
|
||||
{"Treynor Ratio", "0.931"},
|
||||
{"Total Fees", "$2.15"},
|
||||
{"Estimated Strategy Capacity", "$150000000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "1.98%"},
|
||||
{"OrderListHash", "b337ac27f46a6298dd4e9f0f04b49427"}
|
||||
{"OrderListHash", "6365adfc234509e390295a150f25c295"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 525809;
|
||||
public virtual long DataPoints => 288140;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -124,18 +124,18 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.228"},
|
||||
{"Beta", "0.108"},
|
||||
{"Alpha", "0.227"},
|
||||
{"Beta", "0.109"},
|
||||
{"Annual Standard Deviation", "0.084"},
|
||||
{"Annual Variance", "0.007"},
|
||||
{"Information Ratio", "-1.122"},
|
||||
{"Tracking Error", "0.112"},
|
||||
{"Treynor Ratio", "2.501"},
|
||||
{"Treynor Ratio", "2.49"},
|
||||
{"Total Fees", "$2.15"},
|
||||
{"Estimated Strategy Capacity", "$1700000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Portfolio Turnover", "2.01%"},
|
||||
{"OrderListHash", "640ce720644ff0b580687e80105d0a92"}
|
||||
{"OrderListHash", "de82efe4f019a5fa1fb79d111bf15811"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -29,7 +28,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 12251;
|
||||
public override long DataPoints => 3918;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
@@ -13,13 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -107,7 +105,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 4632655;
|
||||
public virtual long DataPoints => 761073;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -131,10 +129,10 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-0.678"},
|
||||
{"Start Equity", "10000000"},
|
||||
{"End Equity", "9988860.24"},
|
||||
{"End Equity", "9988880.24"},
|
||||
{"Net Profit", "-0.111%"},
|
||||
{"Sharpe Ratio", "-10.413"},
|
||||
{"Sortino Ratio", "-0.961"},
|
||||
{"Sharpe Ratio", "-10.416"},
|
||||
{"Sortino Ratio", "-0.959"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "80%"},
|
||||
{"Win Rate", "20%"},
|
||||
@@ -145,12 +143,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.076"},
|
||||
{"Tracking Error", "0.107"},
|
||||
{"Treynor Ratio", "14.588"},
|
||||
{"Treynor Ratio", "14.634"},
|
||||
{"Total Fees", "$19.76"},
|
||||
{"Estimated Strategy Capacity", "$1300000000.00"},
|
||||
{"Estimated Strategy Capacity", "$1400000000.00"},
|
||||
{"Lowest Capacity Asset", "DC V5E8PHPRCHJ8|DC V5E8P9SH0U0X"},
|
||||
{"Portfolio Turnover", "0.00%"},
|
||||
{"OrderListHash", "7f06f736e2f1294916fb2485519021a2"}
|
||||
{"OrderListHash", "67b64c13cbc4aad88111503cf7b789bc"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 94731;
|
||||
public long DataPoints => 36213;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -150,7 +150,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "8"},
|
||||
{"Average Win", "0.69%"},
|
||||
{"Average Loss", "-2.47%"},
|
||||
{"Compounding Annual Return", "-99.966%"},
|
||||
{"Compounding Annual Return", "-99.946%"},
|
||||
{"Drawdown", "28.600%"},
|
||||
{"Expectancy", "-0.680"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
@@ -117,6 +117,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
throw new RegressionTestException("Expected to try to exercise option before and on expiry");
|
||||
}
|
||||
|
||||
var optionHoldings = Securities[_contract.Symbol].Holdings;
|
||||
if (optionHoldings.NetProfit != Portfolio.TotalNetProfit)
|
||||
{
|
||||
throw new RegressionTestException($"Unexpected holdings profit result {optionHoldings.Profit}");
|
||||
}
|
||||
if (Portfolio.Cash != (Portfolio.TotalNetProfit + 200000))
|
||||
{
|
||||
throw new RegressionTestException($"Unexpected portfolio cash {Portfolio.Cash}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -150,8 +160,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-4.10%"},
|
||||
{"Average Win", "0.68%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "24.075%"},
|
||||
{"Drawdown", "1.900%"},
|
||||
{"Expectancy", "0"},
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 872;
|
||||
public long DataPoints => 852;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 54138;
|
||||
public long DataPoints => 19043;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -114,7 +114,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-99.310%"},
|
||||
{"Compounding Annual Return", "-98.880%"},
|
||||
{"Drawdown", "4.400%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 13586;
|
||||
public virtual long DataPoints => 91;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -25,21 +25,25 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
protected override List<DateTime> AfterMarketOpen => new List<DateTime>() {
|
||||
new DateTime(2020, 02, 04, 18, 0, 0), // Tuesday
|
||||
new DateTime(2020, 02, 05, 18, 0, 0),
|
||||
new DateTime(2020, 02, 06, 18, 0, 0),
|
||||
new DateTime(2020, 02, 09, 18, 0, 0),
|
||||
new DateTime(2020, 02, 10, 18, 0, 0),
|
||||
new DateTime(2020, 02, 11, 18, 0, 0)
|
||||
new DateTime(2020, 02, 04, 0, 0, 0), // Tuesday
|
||||
new DateTime(2020, 02, 05, 0, 0, 0),
|
||||
new DateTime(2020, 02, 06, 0, 0, 0),
|
||||
new DateTime(2020, 02, 07, 0, 0, 0),
|
||||
new DateTime(2020, 02, 09, 18, 0, 0), // sunday
|
||||
new DateTime(2020, 02, 10, 0, 0, 0),
|
||||
new DateTime(2020, 02, 11, 0, 0, 0),
|
||||
new DateTime(2020, 02, 12, 0, 0, 0)
|
||||
};
|
||||
protected override List<DateTime> BeforeMarketClose => new List<DateTime>()
|
||||
{
|
||||
new DateTime(2020, 02, 04, 17, 0, 0),
|
||||
new DateTime(2020, 02, 05, 17, 0, 0),
|
||||
new DateTime(2020, 02, 06, 17, 0, 0),
|
||||
new DateTime(2020, 02, 07, 17, 0, 0),
|
||||
new DateTime(2020, 02, 10, 17, 0, 0),
|
||||
new DateTime(2020, 02, 11, 17, 0, 0)
|
||||
new DateTime(2020, 02, 04, 0, 0, 0),
|
||||
new DateTime(2020, 02, 05, 0, 0, 0),
|
||||
new DateTime(2020, 02, 06, 0, 0, 0),
|
||||
new DateTime(2020, 02, 07, 0, 0, 0),
|
||||
new DateTime(2020, 02, 07, 17, 0, 0), // friday
|
||||
new DateTime(2020, 02, 10, 0, 0, 0),
|
||||
new DateTime(2020, 02, 11, 0, 0, 0),
|
||||
new DateTime(2020, 02, 12, 0, 0, 0)
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -50,7 +54,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 41467;
|
||||
public override long DataPoints => 92;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetStartDate(2013, 10, 06);
|
||||
SetEndDate(2013, 10, 14);
|
||||
|
||||
Settings.DailyConsolidationUseExtendedMarketHours = true;
|
||||
var es = AddSecurity(SecurityType.Future, "ES", extendedMarketHours: ExtendedMarketHours);
|
||||
|
||||
_expectedOpensQueue = new Queue<DateTime>(ExpectedOpens);
|
||||
@@ -93,7 +94,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 32073;
|
||||
public virtual long DataPoints => 16313;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -29,19 +29,24 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
protected override List<DateTime> ExpectedOpens => new List<DateTime>(){
|
||||
new DateTime(2013, 10, 06, 18, 0, 0), // Sunday
|
||||
new DateTime(2013, 10, 07, 18, 0, 0),
|
||||
new DateTime(2013, 10, 08, 18, 0, 0),
|
||||
new DateTime(2013, 10, 09, 18, 0, 0),
|
||||
new DateTime(2013, 10, 10, 18, 0, 0),
|
||||
// market is open for the whole day, so goes from midnight to midnight
|
||||
new DateTime(2013, 10, 07, 0, 0, 0),
|
||||
new DateTime(2013, 10, 08, 0, 0, 0),
|
||||
new DateTime(2013, 10, 09, 0, 0, 0),
|
||||
new DateTime(2013, 10, 10, 0, 0, 0),
|
||||
new DateTime(2013, 10, 11, 0, 0, 0),
|
||||
new DateTime(2013, 10, 13, 18, 0, 0),
|
||||
new DateTime(2013, 10, 14, 0, 0, 0),
|
||||
};
|
||||
protected override List<DateTime> ExpectedCloses => new List<DateTime>(){
|
||||
new DateTime(2013, 10, 07, 17, 0, 0),
|
||||
new DateTime(2013, 10, 08, 17, 0, 0),
|
||||
new DateTime(2013, 10, 09, 17, 0, 0),
|
||||
new DateTime(2013, 10, 10, 17, 0, 0),
|
||||
new DateTime(2013, 10, 11, 17, 0, 0),
|
||||
new DateTime(2013, 10, 14, 17, 0, 0),
|
||||
new DateTime(2013, 10, 07, 0, 0, 0),
|
||||
new DateTime(2013, 10, 08, 0, 0, 0),
|
||||
new DateTime(2013, 10, 09, 0, 0, 0),
|
||||
new DateTime(2013, 10, 10, 0, 0, 0),
|
||||
new DateTime(2013, 10, 11, 0, 0, 0),
|
||||
new DateTime(2013, 10, 11, 17, 0, 0), // friday
|
||||
new DateTime(2013, 10, 14, 0, 0, 0),
|
||||
new DateTime(2013, 10, 15, 0, 0, 0),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +57,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 103818;
|
||||
public override long DataPoints => 51933;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 18492;
|
||||
public long DataPoints => 11768;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -170,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
127
Algorithm.CSharp/FutureOptionChainFullDataRegressionAlgorithm.cs
Normal file
127
Algorithm.CSharp/FutureOptionChainFullDataRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChain(Symbol)"/> method
|
||||
/// to get a future option chain.
|
||||
/// </summary>
|
||||
public class FutureOptionChainFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _optionContract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 6);
|
||||
SetEndDate(2020, 1, 6);
|
||||
|
||||
var futureContract = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
|
||||
Resolution.Minute).Symbol;
|
||||
|
||||
_optionContract = OptionChain(futureContract)
|
||||
// Get contracts expiring within 4 months
|
||||
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(120))
|
||||
// Get the contract with the latest expiration date, highest strike and lowest price
|
||||
.OrderByDescending(x => x.Expiry)
|
||||
.ThenByDescending(x => x.Strike)
|
||||
.ThenBy(x => x.LastPrice)
|
||||
.First();
|
||||
|
||||
AddFutureOptionContract(_optionContract);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// Do some trading with the selected contract for sample purposes
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_optionContract, 0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1817;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "450"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "65398.86"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "$34601.14"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES XCZJLCGM383O|ES XCZJLC9NOB29"},
|
||||
{"Portfolio Turnover", "112.25%"},
|
||||
{"OrderListHash", "f18259d04c2d899e7162b88e10239eb8"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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.Data.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.OptionChains(IEnumerable{Symbol})"/> method
|
||||
/// to get multiple future option chains.
|
||||
/// </summary>
|
||||
public class FutureOptionChainsMultipleFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _esOptionContract;
|
||||
private Symbol _gcOptionContract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 6);
|
||||
SetEndDate(2020, 1, 6);
|
||||
SetCash(100000);
|
||||
|
||||
var esFutureContract = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
|
||||
Resolution.Minute).Symbol;
|
||||
|
||||
var gcFutureContract = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(Futures.Metals.Gold, Market.COMEX, new DateTime(2020, 4, 28)),
|
||||
Resolution.Minute).Symbol;
|
||||
|
||||
var chains = OptionChains([esFutureContract, gcFutureContract]);
|
||||
|
||||
_esOptionContract = GetContract(chains, esFutureContract);
|
||||
_gcOptionContract = GetContract(chains, gcFutureContract);
|
||||
|
||||
AddFutureOptionContract(_esOptionContract);
|
||||
AddFutureOptionContract(_gcOptionContract);
|
||||
}
|
||||
|
||||
private Symbol GetContract(OptionChains chains, Symbol underlying)
|
||||
{
|
||||
return chains
|
||||
.Where(kvp => kvp.Key.Underlying == underlying)
|
||||
.Select(kvp => kvp.Value)
|
||||
.Single()
|
||||
// Get contracts expiring within 5 months
|
||||
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(120))
|
||||
// Get the contract with the latest expiration date, highest strike and lowest price
|
||||
.OrderByDescending(x => x.Expiry)
|
||||
.ThenByDescending(x => x.Strike)
|
||||
.ThenBy(x => x.LastPrice)
|
||||
.First();
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// Do some trading with the selected contract for sample purposes
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_esOptionContract, 0.25);
|
||||
SetHoldings(_gcOptionContract, 0.25);
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1819;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "450"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "80983.36"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "$19016.64"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES XCZJLCGM383O|ES XCZJLC9NOB29"},
|
||||
{"Portfolio Turnover", "49.52%"},
|
||||
{"OrderListHash", "9b39296a82d51d51fa1df02aad39d804"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 0;
|
||||
public virtual int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 0;
|
||||
public override int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
public class FutureOptionIndicatorsRegressionAlgorithm : OptionIndicatorsRegressionAlgorithm
|
||||
{
|
||||
protected override string ExpectedGreeks { get; set; } = "Implied Volatility: 0.14008,Delta: 0.63466,Gamma: 0.00209,Vega: 5.61442,Theta: -0.48254,Rho: 0.03098";
|
||||
protected override string ExpectedGreeks { get; set; } = "Implied Volatility: 0.13941,Delta: 0.63509,Gamma: 0.00209,Vega: 5.64129,Theta: -0.47731,Rho: 0.03145";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -51,6 +51,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public override long DataPoints => 1817;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 24379;
|
||||
public long DataPoints => 13942;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -179,7 +179,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -173,7 +173,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 51429;
|
||||
public long DataPoints => 23079;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -26,8 +26,8 @@ using QuantConnect.Securities.Future;
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Continuous Futures Regression algorithm.
|
||||
/// Asserting the behavior of stop market order <see cref="StopMarketOrder"/> in extended market hours
|
||||
/// Continuous Futures Regression algorithm.
|
||||
/// Asserting the behavior of stop market order <see cref="StopMarketOrder"/> in extended market hours
|
||||
/// <seealso cref="Data.UniverseSelection.UniverseSettings.ExtendedMarketHours"/>
|
||||
/// </summary>
|
||||
public class FutureStopMarketOrderOnExtendedHoursRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
@@ -43,6 +43,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
Schedule.On(DateRules.EveryDay(), TimeRules.At(19, 0), () =>
|
||||
{
|
||||
// Don't place orders at the end of the last date, the market-on-stop order won't have time to fill
|
||||
if (Time.Date == EndDate.Date.AddDays(-1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MarketOrder(_SP500EMini.Mapped, 1);
|
||||
_ticket = StopMarketOrder(_SP500EMini.Mapped, -1, _SP500EMini.Price * 1.1m);
|
||||
});
|
||||
@@ -113,7 +119,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all time slices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 75961;
|
||||
public long DataPoints => 41486;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
@@ -133,7 +139,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Orders", "10"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-6.736%"},
|
||||
{"Compounding Annual Return", "-6.419%"},
|
||||
{"Drawdown", "0.100%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Start Equity", "100000"},
|
||||
|
||||
131
Algorithm.CSharp/FutureUniverseHistoryRegressionAlgorithm.cs
Normal file
131
Algorithm.CSharp/FutureUniverseHistoryRegressionAlgorithm.cs
Normal file
@@ -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.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm testing history requests for <see cref="FutureUniverse"/> type work as expected
|
||||
/// and return the same data as the futures chain provider.
|
||||
/// </summary>
|
||||
public class FutureUniverseHistoryRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 11);
|
||||
SetEndDate(2013, 10, 11);
|
||||
|
||||
var future = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute).Symbol;
|
||||
|
||||
var historicalFuturesData = History<FutureUniverse>(future, 3, Resolution.Daily).ToList();
|
||||
|
||||
if (historicalFuturesData.Count != 3)
|
||||
{
|
||||
throw new RegressionTestException($"Expected 3 futures chains from history request, " +
|
||||
$"but got {historicalFuturesData.Count}");
|
||||
}
|
||||
|
||||
foreach (var historyFutureUniverse in historicalFuturesData)
|
||||
{
|
||||
var date = historyFutureUniverse.EndTime;
|
||||
var chain = FutureChainProvider.GetFutureContractList(future, date).ToList();
|
||||
|
||||
if (chain.Count == 0)
|
||||
{
|
||||
throw new RegressionTestException($"No futures in chain on {date}");
|
||||
}
|
||||
|
||||
if (chain.Count != historyFutureUniverse.Data.Count)
|
||||
{
|
||||
throw new RegressionTestException($"Expected {chain.Count} futures in chain on {date}, " +
|
||||
$"but got {historyFutureUniverse.Data.Count}");
|
||||
}
|
||||
|
||||
for (var i = 0; i < chain.Count; i++)
|
||||
{
|
||||
if (historyFutureUniverse.Data[i].Symbol != chain[i])
|
||||
{
|
||||
throw new RegressionTestException($"Missing future contract {chain[i]} on {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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 2735;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 6;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "100000"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Portfolio Turnover", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
133
Algorithm.CSharp/FuturesChainFullDataRegressionAlgorithm.cs
Normal file
133
Algorithm.CSharp/FuturesChainFullDataRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.FuturesChain(Symbol, bool)"/>
|
||||
/// method to get a future chain.
|
||||
/// </summary>
|
||||
public class FuturesChainFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _futureContract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 7);
|
||||
SetEndDate(2013, 10, 7);
|
||||
|
||||
var future = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute).Symbol;
|
||||
|
||||
var chain = FuturesChain(future);
|
||||
foreach (var contract in chain)
|
||||
{
|
||||
if (contract.BidPrice == 0 && contract.AskPrice == 0 && contract.Volume == 0)
|
||||
{
|
||||
throw new RegressionTestException("FuturesChain() returned contract with no data.");
|
||||
}
|
||||
}
|
||||
|
||||
_futureContract = chain
|
||||
// Get contracts expiring within 6 months
|
||||
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(180))
|
||||
// Get the contract with the latest expiration date, and lowest price
|
||||
.OrderByDescending(x => x.Expiry)
|
||||
.ThenBy(x => x.LastPrice)
|
||||
.First();
|
||||
|
||||
AddFutureContract(_futureContract);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// Do some trading with the selected contract for sample purposes
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_futureContract, 0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 4083;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "450"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "50272.1"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "$8290.40"},
|
||||
{"Estimated Strategy Capacity", "$13000.00"},
|
||||
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
|
||||
{"Portfolio Turnover", "639698.49%"},
|
||||
{"OrderListHash", "312461917700d86df1b5c43e1e7ec0eb"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.Market;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm illustrating the usage of the <see cref="QCAlgorithm.FuturesChains(IEnumerable{Symbol}, bool)"/>
|
||||
/// method to get multiple futures chains.
|
||||
/// </summary>
|
||||
public class FuturesChainsMultipleFullDataRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _esFutureContract;
|
||||
private Symbol _gcFutureContract;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 7);
|
||||
SetEndDate(2013, 10, 7);
|
||||
|
||||
var esFuture= AddFuture(Futures.Indices.SP500EMini).Symbol;
|
||||
var gcFuture = AddFuture(Futures.Metals.Gold).Symbol;
|
||||
|
||||
var chains = FuturesChains([esFuture, gcFuture]);
|
||||
|
||||
_esFutureContract = GetContract(chains, esFuture);
|
||||
_gcFutureContract = GetContract(chains, gcFuture);
|
||||
|
||||
AddFutureContract(_esFutureContract);
|
||||
AddFutureContract(_gcFutureContract);
|
||||
}
|
||||
|
||||
private Symbol GetContract(FuturesChains chains, Symbol canonical)
|
||||
{
|
||||
return chains
|
||||
.Where(kvp => kvp.Key == canonical)
|
||||
.Select(kvp => kvp.Value)
|
||||
.Single()
|
||||
// Get contracts expiring within 6 months
|
||||
.Where(contractData => contractData.Expiry - Time <= TimeSpan.FromDays(180))
|
||||
// Get the contract with the latest expiration date, and lowest price
|
||||
.OrderByDescending(x => x.Expiry)
|
||||
.ThenBy(x => x.LastPrice)
|
||||
.First();
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
// Do some trading with the selected contract for sample purposes
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings(_esFutureContract, 0.25);
|
||||
SetHoldings(_gcFutureContract, 0.25);
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 virtual List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 8184;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
/// </summary>
|
||||
public AlgorithmStatus AlgorithmStatus => AlgorithmStatus.Completed;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Orders", "900"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Start Equity", "100000"},
|
||||
{"End Equity", "57108.26"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Sortino 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", "$5701.74"},
|
||||
{"Estimated Strategy Capacity", "$19000.00"},
|
||||
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
|
||||
{"Portfolio Turnover", "432921.78%"},
|
||||
{"OrderListHash", "c75de8eb115be82a0ec2afaec8d034ff"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
var future = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
|
||||
_contractSymbol = FutureChainProvider.GetFutureContractList(future, Time).OrderBy(x => x.ID.Date).FirstOrDefault();
|
||||
_contractSymbol = FuturesChain(future).OrderBy(x => x.ID.Date).First();
|
||||
_future = AddFutureContract(_contractSymbol);
|
||||
|
||||
_future.Holdings.SetHoldings(1600, 1 * OrderSide);
|
||||
@@ -180,7 +180,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 0;
|
||||
public int AlgorithmHistoryDataPoints => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Final status of the algorithm
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 268275;
|
||||
public long DataPoints => 24508;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3631;
|
||||
public long DataPoints => 2197;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user