Compare commits
387 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19483702f8 | ||
|
|
146be2d0ba | ||
|
|
b54281b262 | ||
|
|
f12e8fc08e | ||
|
|
6b6ca5b460 | ||
|
|
ab4c3bf55e | ||
|
|
9c69ee5536 | ||
|
|
89493b1546 | ||
|
|
ee683933a3 | ||
|
|
e87c98def8 | ||
|
|
239406ef5c | ||
|
|
e13066273c | ||
|
|
7677b99bf6 | ||
|
|
c21dd716ed | ||
|
|
f87eb88f27 | ||
|
|
1d363e2c35 | ||
|
|
98273097e5 | ||
|
|
cbdf25d713 | ||
|
|
dcfdbd8c82 | ||
|
|
b5b317f490 | ||
|
|
0eecf5d139 | ||
|
|
bc513ce0e7 | ||
|
|
019ce5aa76 | ||
|
|
c4329c4132 | ||
|
|
9618c376bf | ||
|
|
3aabb11315 | ||
|
|
4d2723f851 | ||
|
|
86b74e0a09 | ||
|
|
41a730bc68 | ||
|
|
6b2dfb6b8c | ||
|
|
7a4ca7898e | ||
|
|
60028ad48a | ||
|
|
e9d690b35a | ||
|
|
db2cb57a3f | ||
|
|
3c784e5b04 | ||
|
|
31f8561330 | ||
|
|
38b87d941a | ||
|
|
83d59b5f9a | ||
|
|
f19d8cb700 | ||
|
|
fcee43b56e | ||
|
|
7898e74148 | ||
|
|
b34cea4458 | ||
|
|
e9edb8ac29 | ||
|
|
33c57bbde4 | ||
|
|
94b9b13530 | ||
|
|
682b9aa760 | ||
|
|
98c6023748 | ||
|
|
dacc679d42 | ||
|
|
3e76716b07 | ||
|
|
55b09a1ea6 | ||
|
|
5539e27905 | ||
|
|
42ed7cf2a7 | ||
|
|
62d1321d74 | ||
|
|
0fa2ea19bc | ||
|
|
e155f620e1 | ||
|
|
897e16c484 | ||
|
|
6477b40661 | ||
|
|
5bfe2491c3 | ||
|
|
03f1bacd3f | ||
|
|
9849a11933 | ||
|
|
8e6dd5a338 | ||
|
|
2738c0f006 | ||
|
|
a0c4d7b741 | ||
|
|
7095dc1559 | ||
|
|
2d7afa798a | ||
|
|
b8bcc4796f | ||
|
|
0fc9555121 | ||
|
|
45e13bb35b | ||
|
|
5773d29419 | ||
|
|
8f3bdcfe6c | ||
|
|
736e5d1fe0 | ||
|
|
c5e5de3416 | ||
|
|
39735941ec | ||
|
|
fc6835cace | ||
|
|
dba0fd0824 | ||
|
|
a0fd2b193f | ||
|
|
0fa471f4e5 | ||
|
|
b899aa4767 | ||
|
|
fed1b6e780 | ||
|
|
f528c39700 | ||
|
|
6a0fdd63a8 | ||
|
|
ca4187290b | ||
|
|
a0491a9b74 | ||
|
|
abeb841a0c | ||
|
|
783805ccf9 | ||
|
|
848d812bf2 | ||
|
|
96b07e6916 | ||
|
|
7796868da7 | ||
|
|
108bfa6c0a | ||
|
|
7f44c3d605 | ||
|
|
59eae963be | ||
|
|
c48979e986 | ||
|
|
e54fe3ae95 | ||
|
|
ee685ea045 | ||
|
|
11f13be75b | ||
|
|
188506b5da | ||
|
|
ca83e8443f | ||
|
|
ac0cdb20f5 | ||
|
|
a131a4849a | ||
|
|
31b603593d | ||
|
|
f62f110b1b | ||
|
|
ede2991823 | ||
|
|
3b65f4b9a1 | ||
|
|
f755b91158 | ||
|
|
7d1cd79618 | ||
|
|
a0ba23a7f0 | ||
|
|
4415468d96 | ||
|
|
dff92ac85e | ||
|
|
dc4a903727 | ||
|
|
5e7651f699 | ||
|
|
fcd48ecdbb | ||
|
|
8e8aa74fb0 | ||
|
|
548a6998e3 | ||
|
|
9a062e4b5d | ||
|
|
82f2aa7a63 | ||
|
|
46aa62bd0c | ||
|
|
250230e79f | ||
|
|
0be339d75f | ||
|
|
3eb2b94070 | ||
|
|
b655bd776e | ||
|
|
2bc41e0e32 | ||
|
|
d6d3514ae2 | ||
|
|
575f17c6ec | ||
|
|
3c6ae2f1e7 | ||
|
|
19f3d8b305 | ||
|
|
475f295ce0 | ||
|
|
7fdedbe98f | ||
|
|
24605c6788 | ||
|
|
c8a80e361c | ||
|
|
dc7b2faa6b | ||
|
|
9cd38a388b | ||
|
|
04723df362 | ||
|
|
3f42101f6d | ||
|
|
eddd28243b | ||
|
|
8e35155c40 | ||
|
|
98fa4464ce | ||
|
|
539011274c | ||
|
|
6f3208eded | ||
|
|
62493f8986 | ||
|
|
35afe3da84 | ||
|
|
b07680688f | ||
|
|
e4647ea146 | ||
|
|
052e20cbf4 | ||
|
|
771cc11b3a | ||
|
|
0d882b8201 | ||
|
|
95c1f752ac | ||
|
|
37dca9d458 | ||
|
|
2dd3a0cb94 | ||
|
|
aa8a3a241b | ||
|
|
cfa4a4c1c1 | ||
|
|
3064c1ed4b | ||
|
|
9e7690754a | ||
|
|
460ef10ff4 | ||
|
|
6f70606f3e | ||
|
|
9eb71e1543 | ||
|
|
3f7d339463 | ||
|
|
3f2bcc1784 | ||
|
|
30d137e9cc | ||
|
|
ab9ad75c93 | ||
|
|
1440842d87 | ||
|
|
2df01c4d2e | ||
|
|
82aab246a8 | ||
|
|
f665d693b7 | ||
|
|
ef531e09bd | ||
|
|
3db470de52 | ||
|
|
a43bdaf1c7 | ||
|
|
e0f483c46b | ||
|
|
8093df31cc | ||
|
|
9df9d76081 | ||
|
|
ad844e9411 | ||
|
|
e7e9153fbf | ||
|
|
24627f5efa | ||
|
|
440282c138 | ||
|
|
3d3f04abbc | ||
|
|
0a64462e50 | ||
|
|
c43f472503 | ||
|
|
6c93af96a1 | ||
|
|
b3cb24a16f | ||
|
|
38f7e72dbe | ||
|
|
a9073396bd | ||
|
|
b7df632294 | ||
|
|
38772a5a89 | ||
|
|
7540af454c | ||
|
|
cd06e87493 | ||
|
|
5200a9e593 | ||
|
|
07aa5625e1 | ||
|
|
31fc7ac236 | ||
|
|
e6f8a7535e | ||
|
|
778d436b94 | ||
|
|
36ddf1c618 | ||
|
|
632833caaa | ||
|
|
6200988ad5 | ||
|
|
826f2cbbf9 | ||
|
|
e54cc3e948 | ||
|
|
413a084254 | ||
|
|
8c0b60cd2f | ||
|
|
64f0a9e0a2 | ||
|
|
3f407cd80f | ||
|
|
5758b65099 | ||
|
|
c1db23250e | ||
|
|
b426483e1d | ||
|
|
30e47f3e8b | ||
|
|
506e3a1c2c | ||
|
|
ab228e8eca | ||
|
|
dc043f8c09 | ||
|
|
05bfad729c | ||
|
|
5c6a779f4d | ||
|
|
630503bf9c | ||
|
|
18eec48a3d | ||
|
|
e9409bf207 | ||
|
|
867682c923 | ||
|
|
59ac2f57ed | ||
|
|
4c3afa6ff1 | ||
|
|
9128ce1260 | ||
|
|
505ef17565 | ||
|
|
a12a43c1ef | ||
|
|
e3313c7c45 | ||
|
|
f0b59a72fd | ||
|
|
a42a53671f | ||
|
|
bb0c27fefd | ||
|
|
299cb79832 | ||
|
|
8fb188d567 | ||
|
|
740b40ff11 | ||
|
|
e736b28568 | ||
|
|
b007d9f962 | ||
|
|
4d7d7def63 | ||
|
|
09c4a53f95 | ||
|
|
714042bb69 | ||
|
|
a8e7a8b27e | ||
|
|
182ee51389 | ||
|
|
4a41c2ea90 | ||
|
|
c1dc981403 | ||
|
|
15e399c96b | ||
|
|
3fb267f4ad | ||
|
|
a3f4dff299 | ||
|
|
cbfdd85cef | ||
|
|
223066d6d9 | ||
|
|
25871497e9 | ||
|
|
3ad4695354 | ||
|
|
1c644297df | ||
|
|
60c9162b11 | ||
|
|
6e32f46068 | ||
|
|
564d8507c7 | ||
|
|
c11e24c5b2 | ||
|
|
f8c65d886c | ||
|
|
c162e75bbc | ||
|
|
ca64dd74d5 | ||
|
|
5fa9dbad3d | ||
|
|
3a00b6963c | ||
|
|
cde9be8d16 | ||
|
|
aa1883a140 | ||
|
|
0c0ee829a2 | ||
|
|
9af7d4a1dc | ||
|
|
cabbcf6d81 | ||
|
|
df308cc2a7 | ||
|
|
8f3ced7639 | ||
|
|
e0b9a2735f | ||
|
|
895dfedf81 | ||
|
|
69dd4fc638 | ||
|
|
fd20b5377d | ||
|
|
e78c3e1eb7 | ||
|
|
0fbbc0e612 | ||
|
|
fb90f118c9 | ||
|
|
d7558406c8 | ||
|
|
00dd3dbd2c | ||
|
|
cb2062debd | ||
|
|
4b86c78df0 | ||
|
|
17d57cb578 | ||
|
|
284b26a9bd | ||
|
|
0bc087954e | ||
|
|
f5dd997ca0 | ||
|
|
33616a44b0 | ||
|
|
9bd6b46160 | ||
|
|
eb995b86ea | ||
|
|
59a3912f68 | ||
|
|
1be6cccbd4 | ||
|
|
a658beb31e | ||
|
|
8cf6e073af | ||
|
|
2f39ac7d83 | ||
|
|
ea25e76faa | ||
|
|
b7a21ce4be | ||
|
|
b9d3d99917 | ||
|
|
64125668db | ||
|
|
06228a8de8 | ||
|
|
813412afb2 | ||
|
|
e0d29e1da7 | ||
|
|
41b7ff58cf | ||
|
|
6d181cc452 | ||
|
|
b8c8460c7a | ||
|
|
9fe018390e | ||
|
|
427f2a70fe | ||
|
|
32f49f1f92 | ||
|
|
b3c2303111 | ||
|
|
fc008fe906 | ||
|
|
bbcf5d71a2 | ||
|
|
482d86a44a | ||
|
|
6eab53f619 | ||
|
|
f617d25af9 | ||
|
|
a8e104f696 | ||
|
|
d1ff914e5a | ||
|
|
574d685647 | ||
|
|
fbd12c7eb1 | ||
|
|
49562c712f | ||
|
|
73fa0461ed | ||
|
|
6cf537b26f | ||
|
|
a374ce9b6e | ||
|
|
ad34429014 | ||
|
|
cc1c305432 | ||
|
|
caaa506c56 | ||
|
|
29e426c2b6 | ||
|
|
368cfe0f5d | ||
|
|
06c05c4274 | ||
|
|
cde4743ca7 | ||
|
|
58e89872c1 | ||
|
|
85eb1fca9a | ||
|
|
cc18e47cd6 | ||
|
|
15066ae5e1 | ||
|
|
1dc118304f | ||
|
|
de57cedc5a | ||
|
|
6273671eb7 | ||
|
|
cece811cce | ||
|
|
0c9c8c45e5 | ||
|
|
7e64bd0265 | ||
|
|
48a7ba77ef | ||
|
|
b6de0e7222 | ||
|
|
7732a27c1b | ||
|
|
adb6afc4f1 | ||
|
|
29588095ed | ||
|
|
e7043bfc7e | ||
|
|
a44d7b2f92 | ||
|
|
18b99338fc | ||
|
|
f129ab1a09 | ||
|
|
f86926bf7a | ||
|
|
68c046fc7b | ||
|
|
3e52816f6e | ||
|
|
c598a8d260 | ||
|
|
e63bfc9127 | ||
|
|
e316f12394 | ||
|
|
306298a16f | ||
|
|
e8160f33d5 | ||
|
|
ce3cb8e1a3 | ||
|
|
2d644d7879 | ||
|
|
b80e274d4f | ||
|
|
9a355c9be5 | ||
|
|
303b95ab50 | ||
|
|
d826d267f4 | ||
|
|
eb55311052 | ||
|
|
27d18fa2e8 | ||
|
|
bb0c671e7c | ||
|
|
c8dc343c13 | ||
|
|
b6815d22de | ||
|
|
459f60603b | ||
|
|
1aaaa20c61 | ||
|
|
07b6572bf9 | ||
|
|
a675aca7e5 | ||
|
|
87db3fe379 | ||
|
|
74321d1727 | ||
|
|
9fd50a302e | ||
|
|
fc0b2f3fa4 | ||
|
|
c4a2d6eef4 | ||
|
|
c2b60e4e48 | ||
|
|
ca9e55fda6 | ||
|
|
b698641c90 | ||
|
|
e5c709ee29 | ||
|
|
ca787d0a25 | ||
|
|
b1a1277eca | ||
|
|
30d7fb042b | ||
|
|
d1bb70fbb7 | ||
|
|
0946bfc2fb | ||
|
|
f34be8e3ff | ||
|
|
e1d1e28bb8 | ||
|
|
5ea9f04b10 | ||
|
|
2529ba124d | ||
|
|
472f78cc53 | ||
|
|
0c26d42561 | ||
|
|
4b94f50754 | ||
|
|
5bdc60b137 | ||
|
|
3837c32b36 | ||
|
|
0e298edcb2 | ||
|
|
7a753bfa3f | ||
|
|
8e2554b110 | ||
|
|
bfa58b4692 | ||
|
|
e3375bc45e | ||
|
|
ac8b500ba2 | ||
|
|
2557a36feb | ||
|
|
55cb3bdaff | ||
|
|
10bb627fc2 |
8
.devcontainer/Dockerfile
Normal file
8
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
# Use QuantConnect Research as the base
|
||||
FROM quantconnect/research:latest
|
||||
|
||||
# Install dos2unix utility for converting pesky windows formatting when needed
|
||||
RUN apt-get update && apt-get install -y dos2unix
|
||||
|
||||
# Install QuantConnect Stubs for Python Autocomplete
|
||||
RUN pip install --no-cache-dir quantconnect-stubs
|
||||
34
.devcontainer/devcontainer.json
Normal file
34
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "Lean Development Container",
|
||||
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/Lean,type=bind",
|
||||
"workspaceFolder": "/Lean",
|
||||
|
||||
// Use devcontainer Dockerfile that is based on Lean foundation image
|
||||
"build": { "dockerfile": "Dockerfile" },
|
||||
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"terminal.integrated.profiles.linux": {
|
||||
"bash": {
|
||||
"path": "bash",
|
||||
"icon": "terminal-bash"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": ["ms-dotnettools.csharp", "ms-python.python", "ms-python.vscode-pylance", "formulahendry.dotnet-test-explorer", "eamodio.gitlens", "yzhang.markdown-all-in-one"],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Uncomment the next line to run commands after the container is created - for example installing curl.
|
||||
"postCreateCommand": "dotnet nuget add source /Lean/LocalPackages; dos2unix /Lean/.vscode/launch_research.sh",
|
||||
|
||||
// Add mounts to docker container
|
||||
"mounts": [
|
||||
// Example data mount from local machine, must use target directory in Config.json
|
||||
// "source=C:/Users/XXXXXXXXXXXX/Lean/Data,target=/Data,type=bind,consistency=cached"
|
||||
]
|
||||
}
|
||||
39
.github/workflows/benchmarks.yml
vendored
Normal file
39
.github/workflows/benchmarks.yml
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
name: Benchmarks
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['*']
|
||||
tags: ['*']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: self-hosted
|
||||
container:
|
||||
image: quantconnect/lean:foundation
|
||||
volumes:
|
||||
- /nas:/Data
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Checkout Lean Master
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: QuantConnect/Lean
|
||||
path: LeanMaster
|
||||
ref: 'master'
|
||||
- name: Build Lean Master
|
||||
run: dotnet build --verbosity q /p:Configuration=Release /p:WarningLevel=1 LeanMaster/QuantConnect.Lean.sln
|
||||
|
||||
- name: Run Benchmarks Master
|
||||
run: cp run_benchmarks.py LeanMaster/run_benchmarks.py && cd LeanMaster && python run_benchmarks.py /Data && cd ../
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --verbosity q /p:Configuration=Release /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
|
||||
- name: Run Benchmarks
|
||||
run: python run_benchmarks.py /Data
|
||||
|
||||
- name: Compare Benchmarks
|
||||
run: python compare_benchmarks.py LeanMaster/benchmark_results.json benchmark_results.json
|
||||
4
.github/workflows/gh-actions.yml
vendored
4
.github/workflows/gh-actions.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
run: dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
|
||||
- name: Run Tests
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter TestCategory!=TravisExclude -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --blame-hang-timeout 300seconds --blame-crash --filter "TestCategory!=TravisExclude&TestCategory!=ResearchRegressionTests" -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\)
|
||||
|
||||
- name: Generate & Publish python stubs
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
@@ -28,3 +28,5 @@ jobs:
|
||||
./ci_build_stubs.sh -t -g -p
|
||||
env:
|
||||
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
||||
ADDITIONAL_STUBS_REPOS: ${{ secrets.ADDITIONAL_STUBS_REPOS }}
|
||||
QC_GIT_TOKEN: ${{ secrets.QC_GIT_TOKEN }}
|
||||
|
||||
21
.github/workflows/rebase-org-branches.yml
vendored
Normal file
21
.github/workflows/rebase-org-branches.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Rebase Organization Branches
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Rebase Organization Branches
|
||||
run: |
|
||||
chmod +x rebase_organization_branches.sh
|
||||
./rebase_organization_branches.sh
|
||||
env:
|
||||
QC_GIT_TOKEN: ${{ secrets.QC_GIT_TOKEN }}
|
||||
35
.github/workflows/research-regression-tests.yml
vendored
Normal file
35
.github/workflows/research-regression-tests.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Research Regression Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['*']
|
||||
tags: ['*']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
container:
|
||||
image: quantconnect/lean:foundation
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: install dependencies
|
||||
run: |
|
||||
pip3 install papermill==2.4.0 clr-loader==0.1.6
|
||||
|
||||
- name: install kernel
|
||||
run: dotnet tool install --global Microsoft.dotnet-interactive --version 1.0.340501
|
||||
|
||||
- name: Add dotnet tools to Path
|
||||
run: echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
|
||||
|
||||
- name: activate kernel for jupyter
|
||||
run: dotnet interactive jupyter install
|
||||
|
||||
- name: Build
|
||||
run: dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
|
||||
- name: Run Tests
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter TestCategory=ResearchRegressionTests -- TestRunParameters.Parameter\(name=\"log-handler\", value=\"ConsoleErrorLogHandler\"\) TestRunParameters.Parameter\(name=\"reduced-disk-size\", value=\"true\"\)
|
||||
61
.github/workflows/virtual-environments.yml
vendored
Normal file
61
.github/workflows/virtual-environments.yml
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
name: Python Virtual Environments
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['*']
|
||||
tags: ['*']
|
||||
pull_request:
|
||||
branches: [master]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-20.04
|
||||
container:
|
||||
image: quantconnect/lean:foundation
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Build
|
||||
run: dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 QuantConnect.Lean.sln
|
||||
|
||||
- name: Python Virtual Environment System Packages
|
||||
run: python -m venv /lean-testenv --system-site-packages && . /lean-testenv/bin/activate && pip install --no-cache-dir lean==1.0.99 && deactivate
|
||||
|
||||
- name: Run Virtual Environment Test System Packages
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonVirtualEnvironmentTests.AssertVirtualEnvironment"
|
||||
|
||||
- name: Python Virtual Environment
|
||||
run: rm -rf /lean-testenv && python -m venv /lean-testenv && . /lean-testenv/bin/activate && pip install --no-cache-dir lean==1.0.99 && deactivate
|
||||
|
||||
- name: Run Virtual Environment Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonVirtualEnvironmentTests.AssertVirtualEnvironment"
|
||||
|
||||
- name: Run Python Package Tests
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests"
|
||||
|
||||
- name: Run Pomegranate Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.PomegranateTest"
|
||||
|
||||
- name: Run Tensorforce Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorforceTests"
|
||||
|
||||
- name: Run StableBaselines Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.StableBaselinesTest"
|
||||
|
||||
- name: Run AxPlatform Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.AxPlatformTest"
|
||||
|
||||
- name: Run NeuralTangents Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.NeuralTangentsTest"
|
||||
|
||||
- name: Run NBeats Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.NBeatsTest"
|
||||
|
||||
- name: Run Tensorly Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.TensorlyTest"
|
||||
|
||||
- name: Run Ignite Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.IgniteTest"
|
||||
|
||||
- name: Run Hvplot Python Package Test
|
||||
run: dotnet test ./Tests/bin/Release/QuantConnect.Tests.dll --filter "FullyQualifiedName=QuantConnect.Tests.Python.PythonPackagesTests.HvplotTest"
|
||||
@@ -18,7 +18,7 @@ To use Lean CLI follow the instructions for installation and tutorial for usage
|
||||
|
||||
<h2>Option 2: Install Locally</h2>
|
||||
|
||||
1. Install [.Net 5](https://dotnet.microsoft.com/download) for the project
|
||||
1. Install [.Net 6](https://dotnet.microsoft.com/download) for the project
|
||||
|
||||
2. (Optional) Get [Python 3.6.8](https://www.python.org/downloads/release/python-368/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-36) for your platform
|
||||
|
||||
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@@ -3,13 +3,13 @@
|
||||
VS Code Launch configurations for the LEAN engine
|
||||
|
||||
Launch:
|
||||
Builds the project with dotnet 5 and then launches the program using coreclr; supports debugging.
|
||||
In order to use this you need dotnet 5 on your system path, As well as the C# extension from the
|
||||
Builds the project with dotnet 6 and then launches the program using coreclr; supports debugging.
|
||||
In order to use this you need dotnet 6 on your system path, As well as the C# extension from the
|
||||
marketplace.
|
||||
|
||||
Attach to Python:
|
||||
Will attempt to attach to LEAN running locally using PTVSD. Requires that the process is
|
||||
actively running and config is set: "debugging": true, "debugging-method": "PTVSD",
|
||||
Will attempt to attach to LEAN running locally using DebugPy. Requires that the process is
|
||||
actively running and config is set: "debugging": true, "debugging-method": "DebugPy",
|
||||
Requires Python extension from the marketplace. Currently only works with algorithms in
|
||||
Algorithm.Python directory. This is because we map that directory to our build directory
|
||||
that contains the py file at runtime. If using another location change "localRoot" value
|
||||
@@ -26,7 +26,7 @@
|
||||
"program": "${workspaceFolder}/Launcher/bin/Debug/QuantConnect.Lean.Launcher.dll",
|
||||
"args": [
|
||||
"--config",
|
||||
"${workspaceFolder}/Launcher/config.json"
|
||||
"${workspaceFolder}/Launcher/bin/Debug/config.json"
|
||||
],
|
||||
"cwd": "${workspaceFolder}/Launcher/bin/Debug/",
|
||||
"stopAtEntry": false,
|
||||
|
||||
15
.vscode/launch_research.sh
vendored
Normal file
15
.vscode/launch_research.sh
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Realpath polyfill, notably absent macOS and some debian distros
|
||||
absolute_path() {
|
||||
echo "$(cd "$(dirname "${1}")" && pwd)/$(basename "${1}")"
|
||||
}
|
||||
|
||||
# Get build directory from args position 1, or use default
|
||||
DEFAULT_BUILD_DIR=../Launcher/bin/Debug/
|
||||
BUILD_DIR=${1:-$DEFAULT_BUILD_DIR}
|
||||
BUILD_DIR=$(absolute_path "${BUILD_DIR}")
|
||||
|
||||
#Add our build directory to python path for python kernel
|
||||
export PYTHONPATH="${PYTHONPATH}:${BUILD_DIR}"
|
||||
|
||||
# Launch jupyter-lab
|
||||
jupyter-lab --allow-root --no-browser --notebook-dir=$BUILD_DIR --LabApp.token=''
|
||||
53
.vscode/readme.md
vendored
53
.vscode/readme.md
vendored
@@ -4,6 +4,8 @@ This document contains information regarding ways to use Visual Studio Code to w
|
||||
|
||||
- Using Lean CLI -> A great tool for working with your algorithms locally, while still being able to deploy to the cloud and have access to Lean data. It is also able to run algorithms locally through our official docker images **Recommended for algorithm development.
|
||||
|
||||
- Using a Lean Dev container -> A docker environment with all dependencies pre-installed to allow seamless Lean development across platforms. Great for open source contributors.
|
||||
|
||||
- Locally installing all dependencies to run Lean with Visual Studio Code on your OS.
|
||||
|
||||
<br />
|
||||
@@ -12,32 +14,63 @@ This document contains information regarding ways to use Visual Studio Code to 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 Dependencies Locally</h2>
|
||||
<h2>Option 2: Lean Development Container</h2>
|
||||
|
||||
1. Install [.Net 5](https://dotnet.microsoft.com/download) for the project
|
||||
Before anything we need to ensure a few things have been done for either option:
|
||||
|
||||
2. (Optional) Get [Python 3.6.8](https://www.python.org/downloads/release/python-368/) for running Python algorithms
|
||||
- Follow Python instructions [here](https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#installing-python-36) for your platform
|
||||
1. Get [Visual Studio Code](https://code.visualstudio.com/download)
|
||||
- Get [Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) Extension
|
||||
|
||||
2. Get [Docker](https://docs.docker.com/get-docker/):
|
||||
- Follow the instructions for your Operating System
|
||||
- New to Docker? Try [docker getting-started](https://docs.docker.com/get-started/)
|
||||
|
||||
3. Pull Lean’s latest research image from a terminal
|
||||
- `docker pull quantconnect/research:latest`
|
||||
|
||||
4. Get Lean into VS Code
|
||||
- Download the repo or clone it using: `git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)`
|
||||
- Open the folder using VS Code
|
||||
|
||||
5. Open Development Container
|
||||
- In VS Code, either:
|
||||
- Select "Reopen in Container" from pop up box.
|
||||
|
||||
OR
|
||||
|
||||
- Ctrl+Shift+P (Command Palette) and select "Remote-Containers: Rebuild and Reopen in Container"
|
||||
|
||||
You should now be in the development container, give VS Code a moment to prepare and you will be ready to go!
|
||||
If you would like to mount any additional local files to your container, checkout [devcontainer.json "mounts" section](https://containers.dev/implementors/json_reference/) for an example! Upon any mount changes you must rebuild the container using Command Palette as in step 5.
|
||||
|
||||
<br />
|
||||
|
||||
<h2>Option 3: Install Dependencies Locally</h2>
|
||||
|
||||
1. Install [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.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
|
||||
|
||||
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
|
||||
- Get the Extension [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for Python Debugging
|
||||
|
||||
4. Get Lean into VS Code
|
||||
- Download the repo or clone it using: _git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)_
|
||||
- Download the repo or clone it using: `git clone [https://github.com/QuantConnect/Lean](https://github.com/QuantConnect/Lean)`
|
||||
- Open the folder using VS Code
|
||||
|
||||
Your environment is prepared and ready to run lean
|
||||
Your environment is prepared and ready to run Lean.
|
||||
|
||||
<br />
|
||||
|
||||
<h1>How to use Lean</h1>
|
||||
|
||||
This section will cover configuring, building, 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, building, 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 />
|
||||
|
||||
@@ -73,7 +106,6 @@ In VS Code run build task (Ctrl+Shift+B or "Terminal" dropdown); there are a few
|
||||
|
||||
- __Build__ - basic build task, just builds Lean once
|
||||
- __Rebuild__ - rebuild task, completely rebuilds the project. Use if having issues with debugging symbols being loaded for your algorithms.
|
||||
- __Autobuilder__ - Starts a script that builds then waits for files to change and rebuilds appropriately
|
||||
- __Clean__ - deletes out all project build files
|
||||
|
||||
<br />
|
||||
@@ -95,7 +127,7 @@ Python algorithms require a little extra work in order to be able to debug them.
|
||||
First in order to debug a Python algorithm in VS Code we must make the following change to our configuration (Launcher\config.json) under the comment debugging configuration:
|
||||
|
||||
"debugging": true,
|
||||
"debugging-method": "PTVSD",
|
||||
"debugging-method": "DebugPy",
|
||||
|
||||
In setting this we are telling Lean to expect a debugger connection using ‘Python Tools for Visual Studio Debugger’. Once this is set Lean will stop upon initialization and await a connection to the debugger via port 5678.
|
||||
|
||||
@@ -123,5 +155,6 @@ _Figure 2: Python Debugger Messages_
|
||||
<h1>Common Issues</h1>
|
||||
Here we will cover some common issues with setting this up. This section will expand as we get user feedback!
|
||||
|
||||
- The "project file cannot be loaded" and "nuget packages not found" errors occurs when the project files are open by another process in the host. Closing all applications and/or restarting the computer solve the issue.
|
||||
- Autocomplete and reference finding with omnisharp can sometimes bug, if this occurs use the command palette to restart omnisharp. (Ctrl+Shift+P "OmniSharp: Restart OmniSharp")
|
||||
- Any error messages about building in VSCode that point to comments in JSON. Either select **ignore** or follow steps described [here](https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json) to remove the errors entirely.
|
||||
|
||||
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files.eol": "\n",
|
||||
"python.analysis.extraPaths": [
|
||||
"/Lean/Algorithm.Python",
|
||||
"/opt/miniconda3/lib/python3.8/site-packages"
|
||||
]
|
||||
}
|
||||
12
.vscode/tasks.json
vendored
12
.vscode/tasks.json
vendored
@@ -50,6 +50,18 @@
|
||||
"reveal": "silent"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "start research",
|
||||
"type": "shell",
|
||||
"dependsOn": ["build"],
|
||||
"group": "build",
|
||||
"isBackground": true,
|
||||
"command" : "${workspaceFolder}/.vscode/launch_research.sh",
|
||||
"args" : [
|
||||
"${workspaceFolder}/Launcher/bin/Debug"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -69,6 +69,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3943;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -105,6 +105,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 58;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -82,6 +82,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 24;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -79,6 +79,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 24;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -99,6 +99,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp};
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 10977;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 11;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -113,6 +113,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 63;
|
||||
|
||||
/// <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>
|
||||
@@ -121,31 +131,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "3"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.03%"},
|
||||
{"Compounding Annual Return", "-2.503%"},
|
||||
{"Compounding Annual Return", "-2.594%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.032%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "-0.034%"},
|
||||
{"Sharpe Ratio", "-7.854"},
|
||||
{"Probabilistic Sharpe Ratio", "1.216%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Alpha", "-0.022"},
|
||||
{"Beta", "0.004"},
|
||||
{"Annual Standard Deviation", "0.003"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-0.678"},
|
||||
{"Tracking Error", "0.243"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Estimated Strategy Capacity", "$2100000.00"},
|
||||
{"Information Ratio", "-0.768"},
|
||||
{"Tracking Error", "0.241"},
|
||||
{"Treynor Ratio", "-4.689"},
|
||||
{"Total Fees", "$8.60"},
|
||||
{"Estimated Strategy Capacity", "$5500000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Fitness Score", "0.419"},
|
||||
{"Fitness Score", "0.417"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-81.557"},
|
||||
{"Portfolio Turnover", "0.837"},
|
||||
{"Return Over Maximum Drawdown", "-81.518"},
|
||||
{"Portfolio Turnover", "0.834"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -159,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "68775c18eb40c1bde212653faec4016e"}
|
||||
{"OrderListHash", "802a335b5c355e83b8cd2174f053c1b9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 4);
|
||||
SetEndDate(2020, 1, 6);
|
||||
SetEndDate(2020, 1, 8);
|
||||
|
||||
_es20h20 = AddFutureContract(
|
||||
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 3, 20)),
|
||||
@@ -51,8 +51,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
QuantConnect.Symbol.CreateFuture(Futures.Indices.SP500EMini, Market.CME, new DateTime(2020, 6, 19)),
|
||||
Resolution.Minute).Symbol;
|
||||
|
||||
// Get option contract lists for 2020/01/05 (Time.AddDays(1)) because Lean has local data for that date
|
||||
var optionChains = OptionChainProvider.GetOptionContractList(_es20h20, Time.AddDays(1))
|
||||
.Concat(OptionChainProvider.GetOptionContractList(_es19m20, Time));
|
||||
.Concat(OptionChainProvider.GetOptionContractList(_es19m20, Time.AddDays(1)));
|
||||
|
||||
foreach (var optionContract in optionChains)
|
||||
{
|
||||
@@ -160,6 +161,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 311879;
|
||||
|
||||
/// <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>
|
||||
@@ -168,31 +179,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "116.059%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Compounding Annual Return", "5512.811%"},
|
||||
{"Drawdown", "1.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.635%"},
|
||||
{"Sharpe Ratio", "17.16"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "5.333%"},
|
||||
{"Sharpe Ratio", "64.137"},
|
||||
{"Probabilistic Sharpe Ratio", "95.977%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "2.25"},
|
||||
{"Beta", "-1.665"},
|
||||
{"Annual Standard Deviation", "0.071"},
|
||||
{"Annual Variance", "0.005"},
|
||||
{"Information Ratio", "5.319"},
|
||||
{"Tracking Error", "0.114"},
|
||||
{"Treynor Ratio", "-0.735"},
|
||||
{"Total Fees", "$7.40"},
|
||||
{"Estimated Strategy Capacity", "$24000000.00"},
|
||||
{"Alpha", "25.72"},
|
||||
{"Beta", "2.914"},
|
||||
{"Annual Standard Deviation", "0.423"},
|
||||
{"Annual Variance", "0.179"},
|
||||
{"Information Ratio", "66.11"},
|
||||
{"Tracking Error", "0.403"},
|
||||
{"Treynor Ratio", "9.315"},
|
||||
{"Total Fees", "$8.60"},
|
||||
{"Estimated Strategy Capacity", "$22000000.00"},
|
||||
{"Lowest Capacity Asset", "ES XFH59UK0MYO1"},
|
||||
{"Fitness Score", "1"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "2.133"},
|
||||
{"Portfolio Turnover", "2.035"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -206,7 +217,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "35738733ff791eeeaf508faec804cab0"}
|
||||
{"OrderListHash", "e7021bd385f366771ae00abd3a46a22e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This regression algorithm tests we can add future option contracts from contracts in the future chain
|
||||
/// </summary>
|
||||
public class AddFutureOptionContractFromFutureChainRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private bool _addedOptions;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 4);
|
||||
SetEndDate(2020, 1, 6);
|
||||
|
||||
var es = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME);
|
||||
es.SetFilter((futureFilter) =>
|
||||
{
|
||||
return futureFilter.Expiration(0, 365).ExpirationCycle(new[] { 3, 6 });
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!_addedOptions)
|
||||
{
|
||||
_addedOptions = true;
|
||||
foreach (var futuresContracts in data.FutureChains.Values)
|
||||
{
|
||||
foreach (var contract in futuresContracts)
|
||||
{
|
||||
var option_contract_symbols = OptionChainProvider.GetOptionContractList(contract.Symbol, Time).ToList();
|
||||
if(option_contract_symbols.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var option_contract_symbol in option_contract_symbols.OrderBy(x => x.ID.Date)
|
||||
.ThenBy(x => x.ID.StrikePrice)
|
||||
.ThenBy(x => x.ID.OptionRight).Take(5))
|
||||
{
|
||||
AddOptionContract(option_contract_symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Portfolio.Invested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var chain in data.OptionChains.Values)
|
||||
{
|
||||
foreach (var option in chain.Contracts.Keys)
|
||||
{
|
||||
MarketOrder(option, 1);
|
||||
MarketOrder(option.Underlying, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 12164;
|
||||
|
||||
/// <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 Trades", "20"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "386219349.202%"},
|
||||
{"Drawdown", "5.200%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "11.912%"},
|
||||
{"Sharpe Ratio", "1604181.92"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "2144881.34"},
|
||||
{"Beta", "31.223"},
|
||||
{"Annual Standard Deviation", "1.337"},
|
||||
{"Annual Variance", "1.788"},
|
||||
{"Information Ratio", "1657259.526"},
|
||||
{"Tracking Error", "1.294"},
|
||||
{"Treynor Ratio", "68696.045"},
|
||||
{"Total Fees", "$35.70"},
|
||||
{"Estimated Strategy Capacity", "$2600000.00"},
|
||||
{"Lowest Capacity Asset", "ES 31C3JQS9D84PW|ES XCZJLC9NOB29"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "64221a660525c4259d5bd852eef1299c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2020, 1, 4);
|
||||
SetEndDate(2020, 1, 6);
|
||||
SetEndDate(2020, 1, 8);
|
||||
|
||||
_es = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME);
|
||||
_es.SetFilter((futureFilter) =>
|
||||
@@ -164,8 +164,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
base.OnEndOfAlgorithm();
|
||||
|
||||
if (!_optionFilterRan)
|
||||
{
|
||||
throw new InvalidOperationException("Option chain filter was never ran");
|
||||
@@ -219,6 +217,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 608437;
|
||||
|
||||
/// <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>
|
||||
@@ -227,31 +235,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-10.708%"},
|
||||
{"Drawdown", "0.200%"},
|
||||
{"Compounding Annual Return", "347.065%"},
|
||||
{"Drawdown", "0.900%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-0.093%"},
|
||||
{"Sharpe Ratio", "-10.594"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Net Profit", "1.951%"},
|
||||
{"Sharpe Ratio", "15.548"},
|
||||
{"Probabilistic Sharpe Ratio", "95.977%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.261"},
|
||||
{"Beta", "0.244"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-22.456"},
|
||||
{"Tracking Error", "0.032"},
|
||||
{"Treynor Ratio", "-0.454"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Estimated Strategy Capacity", "$41000.00"},
|
||||
{"Lowest Capacity Asset", "ES 31C3JQTOYO9T0|ES XCZJLC9NOB29"},
|
||||
{"Fitness Score", "0.273"},
|
||||
{"Alpha", "1.885"},
|
||||
{"Beta", "1.066"},
|
||||
{"Annual Standard Deviation", "0.155"},
|
||||
{"Annual Variance", "0.024"},
|
||||
{"Information Ratio", "13.528"},
|
||||
{"Tracking Error", "0.142"},
|
||||
{"Treynor Ratio", "2.258"},
|
||||
{"Total Fees", "$3.57"},
|
||||
{"Estimated Strategy Capacity", "$760000.00"},
|
||||
{"Lowest Capacity Asset", "ES XCZJLDQX2SRO|ES XCZJLC9NOB29"},
|
||||
{"Fitness Score", "0.403"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-123.159"},
|
||||
{"Portfolio Turnover", "0.547"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.403"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -265,7 +273,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "9347e3b610cfa21f7cbd968a0135c8af"}
|
||||
{"OrderListHash", "738240babf741f1bf79f85ea5026ec4c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 37597;
|
||||
|
||||
/// <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>
|
||||
@@ -160,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4f50b8360ea317ef974801649088bd06"}
|
||||
{"OrderListHash", "568fe7c2a11960436660db1231f2cfd2"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +166,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 5797;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -113,6 +113,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 4677;
|
||||
|
||||
/// <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>
|
||||
@@ -159,7 +169,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "7fbcd12db40304d50b3a34d7878eb3cf"}
|
||||
{"OrderListHash", "546b6182e1df2d222178454d8f311566"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm asserting that using OnlyApplyFilterAtMarketOpen along with other dynamic filters will make the filters be applied only on market
|
||||
/// open, regardless of the order of configuration of the filters
|
||||
/// </summary>
|
||||
public class AddOptionWithOnMarketOpenOnlyFilterRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 6, 5);
|
||||
SetEndDate(2014, 6, 10);
|
||||
|
||||
// OnlyApplyFilterAtMarketOpen as first filter
|
||||
AddOption("AAPL", Resolution.Minute).SetFilter(u =>
|
||||
u.OnlyApplyFilterAtMarketOpen()
|
||||
.Strikes(-5, 5)
|
||||
.Expiration(0, 100)
|
||||
.IncludeWeeklys());
|
||||
|
||||
// OnlyApplyFilterAtMarketOpen as last filter
|
||||
AddOption("TWX", Resolution.Minute).SetFilter(u =>
|
||||
u.Strikes(-5, 5)
|
||||
.Expiration(0, 100)
|
||||
.IncludeWeeklys()
|
||||
.OnlyApplyFilterAtMarketOpen());
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
// This will be the first call, the underlying securities are added.
|
||||
if (changes.AddedSecurities.All(s => s.Type != SecurityType.Option))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var changeOptions = changes.AddedSecurities.Concat(changes.RemovedSecurities)
|
||||
.Where(s => s.Type == SecurityType.Option);
|
||||
|
||||
// Susbtract one minute to get the actual market open. If market open is at 9:30am, this will be invoked at 9:31am
|
||||
var expectedTime = Time.TimeOfDay - TimeSpan.FromMinutes(1);
|
||||
var allOptionsWereChangedOnMarketOpen = changeOptions.All(s =>
|
||||
{
|
||||
var firstMarketSegment = s.Exchange.Hours.MarketHours[Time.DayOfWeek].Segments
|
||||
.First(segment => segment.State == MarketHoursState.Market);
|
||||
|
||||
return firstMarketSegment.Start == expectedTime;
|
||||
});
|
||||
|
||||
if (!allOptionsWereChangedOnMarketOpen)
|
||||
{
|
||||
throw new Exception("Expected options filter to be run only on market open");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all time slices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3338420;
|
||||
|
||||
/// <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 Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-10.144"},
|
||||
{"Tracking Error", "0.033"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -40,8 +40,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
private int _expectedContractIndex;
|
||||
private readonly List<Symbol> _expectedContracts = new List<Symbol>
|
||||
{
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00747500"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00750000"),
|
||||
SymbolRepresentation.ParseOptionTickerOSI("GOOG 151224P00752500")
|
||||
};
|
||||
|
||||
@@ -109,6 +109,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var googOptionChain = AddOption(UnderlyingTicker);
|
||||
googOptionChain.SetFilter(u =>
|
||||
{
|
||||
// we added the universe at 10, the universe selection data should not be from before
|
||||
if (u.Underlying.EndTime.Hour < 10)
|
||||
{
|
||||
throw new Exception($"Unexpected underlying data point {u.Underlying.EndTime} {u.Underlying}");
|
||||
}
|
||||
// find first put above market price
|
||||
return u.IncludeWeeklys()
|
||||
.Strikes(+1, +1)
|
||||
@@ -205,6 +210,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 200618;
|
||||
|
||||
/// <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>
|
||||
@@ -231,7 +246,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$6.00"},
|
||||
{"Estimated Strategy Capacity", "$2000.00"},
|
||||
{"Lowest Capacity Asset", "GOOCV 305RBQ2BZBZT2|GOOCV VP83T1ZUHROL"},
|
||||
{"Lowest Capacity Asset", "GOOCV 305RBR0BSWIX2|GOOCV VP83T1ZUHROL"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
@@ -251,7 +266,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "1e7b3e90918777b9dbf46353a96f3329"}
|
||||
{"OrderListHash", "550a99c482106defd8ba15f48183768e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
142
Algorithm.CSharp/AddRemoveSecurityCacheRegressionAlgorithm.cs
Normal file
142
Algorithm.CSharp/AddRemoveSecurityCacheRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm making sure the securities cache is reset correctly once it's removed from the algorithm
|
||||
/// </summary>
|
||||
public class AddRemoveSecurityCacheRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 07); //Set Start Date
|
||||
SetEndDate(2013, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
AddEquity("SPY", Resolution.Minute, extendedMarketHours: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
SetHoldings("SPY", 1);
|
||||
}
|
||||
|
||||
if (Time.Day == 11)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!ActiveSecurities.ContainsKey("AIG"))
|
||||
{
|
||||
var aig = AddEquity("AIG", Resolution.Minute);
|
||||
|
||||
var ticket = MarketOrder("AIG", 1);
|
||||
|
||||
if (ticket.Status != OrderStatus.Invalid)
|
||||
{
|
||||
throw new Exception("Expected order to always be invalid because there is no data yet!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveSecurity("AIG");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 11202;
|
||||
|
||||
/// <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 Trades", "19"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "271.720%"},
|
||||
{"Drawdown", "2.500%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.754%"},
|
||||
{"Sharpe Ratio", "11.994"},
|
||||
{"Probabilistic Sharpe Ratio", "74.160%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.618"},
|
||||
{"Beta", "0.81"},
|
||||
{"Annual Standard Deviation", "0.185"},
|
||||
{"Annual Variance", "0.034"},
|
||||
{"Information Ratio", "3.961"},
|
||||
{"Tracking Error", "0.061"},
|
||||
{"Treynor Ratio", "2.746"},
|
||||
{"Total Fees", "$21.45"},
|
||||
{"Estimated Strategy Capacity", "$830000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.204"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "43.135"},
|
||||
{"Return Over Maximum Drawdown", "261.238"},
|
||||
{"Portfolio Turnover", "0.204"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6ee62edf1ac883882b0fcef8cb3e9bae"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 7063;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -59,6 +59,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3943;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Regression algorithm reproducing issue where underlying option contract would be removed with the first call
|
||||
/// too RemoveOptionContract
|
||||
/// </summary>
|
||||
public class AddTwoAndRemoveOneOptionContractRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contract1;
|
||||
private Symbol _contract2;
|
||||
private bool _hasRemoved;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2014, 06, 06);
|
||||
SetEndDate(2014, 06, 06);
|
||||
|
||||
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
|
||||
UniverseSettings.MinimumTimeInUniverse = TimeSpan.Zero;
|
||||
|
||||
var aapl = QuantConnect.Symbol.Create("AAPL", SecurityType.Equity, Market.USA);
|
||||
|
||||
var contracts = OptionChainProvider.GetOptionContractList(aapl, Time)
|
||||
.OrderBy(symbol => symbol.ID.Symbol)
|
||||
.Where(optionContract => optionContract.ID.OptionRight == OptionRight.Call
|
||||
&& optionContract.ID.OptionStyle == OptionStyle.American)
|
||||
.Take(2)
|
||||
.ToList();
|
||||
|
||||
_contract1 = contracts[0];
|
||||
_contract2 = contracts[1];
|
||||
AddOptionContract(_contract1);
|
||||
AddOptionContract(_contract2);
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (slice.HasData)
|
||||
{
|
||||
if (!_hasRemoved)
|
||||
{
|
||||
RemoveOptionContract(_contract1);
|
||||
_hasRemoved = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var subscriptions =
|
||||
SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs("AAPL");
|
||||
if (subscriptions.Count == 0)
|
||||
{
|
||||
throw new Exception("No configuration for underlying was found!");
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
Buy(_contract2, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (!_hasRemoved)
|
||||
{
|
||||
throw new Exception("Expect a single call to OnData where we removed the option and underlying");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1578;
|
||||
|
||||
/// <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 Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"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", "$2.00"},
|
||||
{"Estimated Strategy Capacity", "$230000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL VXBK4QQIRLZA|AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "0"},
|
||||
{"Return Over Maximum Drawdown", "0"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "228194dcc6fd8689a67f383577ee2d85"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 53;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -89,6 +89,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 234018;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -153,6 +153,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 795;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -186,6 +186,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 35410;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -65,6 +65,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 890;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 12;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -41,6 +41,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 6214;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 61;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -65,8 +75,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "-0.859"},
|
||||
{"Tracking Error", "0.004"},
|
||||
{"Treynor Ratio", "-0.832"},
|
||||
{"Total Fees", "$2.89"},
|
||||
{"Estimated Strategy Capacity", "$8900000000.00"},
|
||||
{"Total Fees", "€2.89"},
|
||||
{"Estimated Strategy Capacity", "€8900000000.00"},
|
||||
{"Lowest Capacity Asset", "AAPL R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.506"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
|
||||
@@ -78,6 +78,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 893;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 2;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -92,6 +92,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 2313;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Orders.Fees;
|
||||
using QuantConnect.Data.Custom;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Risk;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
{
|
||||
///<summary>
|
||||
/// This Alpha Model uses Wells Fargo 30-year Fixed Rate Mortgage data from Quandl to
|
||||
/// generate Insights about the movement of Real Estate ETFs. Mortgage rates can provide information
|
||||
/// regarding the general price trend of real estate, and ETFs provide good continuous-time instruments
|
||||
/// to measure the impact against. Volatility in mortgage rates tends to put downward pressure on real
|
||||
/// estate prices, whereas stable mortgage rates, regardless of true rate, lead to stable or higher real
|
||||
/// estate prices. This Alpha model seeks to take advantage of this correlation by emitting insights
|
||||
/// based on volatility and rate deviation from its historic mean.
|
||||
///
|
||||
/// This alpha is part of the Benchmark Alpha Series created by QuantConnect which are open
|
||||
/// sourced so the community and client funds can see an example of an alpha.
|
||||
///</summary>
|
||||
public class MortgageRateVolatilityAlgorithm : QCAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2017, 1, 1); //Set Start Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
SetSecurityInitializer(security => security.FeeModel = new ConstantFeeModel(0));
|
||||
|
||||
// Basket of 6 liquid real estate ETFs
|
||||
Func<string, Symbol> toSymbol = x => QuantConnect.Symbol.Create(x, SecurityType.Equity, Market.USA);
|
||||
var realEstateETFs = new[] { "VNQ", "REET", "TAO", "FREL", "SRET", "HIPS" }.Select(toSymbol).ToArray();
|
||||
SetUniverseSelection(new ManualUniverseSelectionModel(realEstateETFs));
|
||||
|
||||
SetAlpha(new MortgageRateVolatilityAlphaModel(this));
|
||||
|
||||
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
|
||||
|
||||
SetExecution(new ImmediateExecutionModel());
|
||||
|
||||
SetRiskManagement(new NullRiskManagementModel());
|
||||
|
||||
}
|
||||
|
||||
private class MortgageRateVolatilityAlphaModel : AlphaModel
|
||||
{
|
||||
private readonly int _indicatorPeriod;
|
||||
private readonly Resolution _resolution;
|
||||
private readonly TimeSpan _insightDuration;
|
||||
private readonly int _deviations;
|
||||
private readonly double _insightMagnitude;
|
||||
private readonly Symbol _mortgageRate;
|
||||
private readonly SimpleMovingAverage _mortgageRateSma;
|
||||
private readonly StandardDeviation _mortgageRateStd;
|
||||
|
||||
public MortgageRateVolatilityAlphaModel(
|
||||
QCAlgorithm algorithm,
|
||||
int indicatorPeriod = 15,
|
||||
double insightMagnitude = 0.0005,
|
||||
int deviations = 2,
|
||||
Resolution resolution = Resolution.Daily
|
||||
)
|
||||
{
|
||||
// Add Quandl data for a Well's Fargo 30-year Fixed Rate mortgage
|
||||
_mortgageRate = algorithm.AddData<QuandlMortgagePriceColumns>("WFC/PR_GOV_30YFIXEDVA_APR").Symbol;
|
||||
_indicatorPeriod = indicatorPeriod;
|
||||
_resolution = resolution;
|
||||
_insightDuration = resolution.ToTimeSpan().Multiply(indicatorPeriod);
|
||||
_insightMagnitude = insightMagnitude;
|
||||
_deviations = deviations;
|
||||
|
||||
// Add indicators for the mortgage rate -- Standard Deviation and Simple Moving Average
|
||||
_mortgageRateStd = algorithm.STD(_mortgageRate, _indicatorPeriod, resolution);
|
||||
_mortgageRateSma = algorithm.SMA(_mortgageRate, _indicatorPeriod, resolution);
|
||||
|
||||
// Use a history call to warm-up the indicators
|
||||
WarmUpIndicators(algorithm);
|
||||
}
|
||||
|
||||
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data)
|
||||
{
|
||||
var insights = new List<Insight>();
|
||||
|
||||
// Return empty list if data slice doesn't contain monrtgage rate data
|
||||
if (!data.Keys.Contains(_mortgageRate))
|
||||
{
|
||||
return insights;
|
||||
}
|
||||
// Extract current mortgage rate, the current STD indicator value, and current SMA value
|
||||
var rate = data[_mortgageRate].Value;
|
||||
var deviation = _deviations * _mortgageRateStd;
|
||||
var sma = _mortgageRateSma;
|
||||
|
||||
// Loop through all Active Securities to emit insights
|
||||
foreach (var security in algorithm.ActiveSecurities.Keys)
|
||||
{
|
||||
// Mortgage rate Symbol will be in the collection, so skip it
|
||||
if (security == _mortgageRate)
|
||||
{
|
||||
return insights;
|
||||
}
|
||||
|
||||
// If volatility in mortgage rates is high, then we emit an Insight to sell
|
||||
if ((rate < sma - deviation) || (rate > sma + deviation))
|
||||
{
|
||||
insights.Add(Insight.Price(security, _insightDuration, InsightDirection.Down, _insightMagnitude));
|
||||
}
|
||||
|
||||
// If volatility in mortgage rates is low, then we emit an Insight to buy
|
||||
if ((rate < sma - (decimal)deviation/2) || (rate > sma + (decimal)deviation/2))
|
||||
{
|
||||
insights.Add(Insight.Price(security, _insightDuration, InsightDirection.Up, _insightMagnitude));
|
||||
}
|
||||
}
|
||||
|
||||
return insights;
|
||||
}
|
||||
|
||||
private void WarmUpIndicators(QCAlgorithm algorithm)
|
||||
{
|
||||
// Make a history call and update the indicators
|
||||
algorithm.History(new[] { _mortgageRate }, _indicatorPeriod, _resolution).PushThrough(bar =>
|
||||
{
|
||||
_mortgageRateSma.Update(bar.EndTime, bar.Value);
|
||||
_mortgageRateStd.Update(bar.EndTime, bar.Value);
|
||||
});
|
||||
}
|
||||
}
|
||||
public class QuandlMortgagePriceColumns : Quandl
|
||||
{
|
||||
public QuandlMortgagePriceColumns()
|
||||
|
||||
// Rename the Quandl object column to the data we want, which is the 'Value' column
|
||||
// of the CSV that our API call returns
|
||||
: base(valueColumnName: "Value")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,16 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 0;
|
||||
|
||||
/// </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>
|
||||
@@ -195,4 +205,4 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
UltraShort = ultraShort;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
/// A number of companies publicly trade two different classes of shares
|
||||
/// in US equity markets. If both assets trade with reasonable volume, then
|
||||
/// the underlying driving forces of each should be similar or the same. Given
|
||||
/// this, we can create a relatively dollar-netural long/short portfolio using
|
||||
/// this, we can create a relatively dollar-neutral long/short portfolio using
|
||||
/// the dual share classes. Theoretically, any deviation of this portfolio from
|
||||
/// its mean-value should be corrected, and so the motivating idea is based on
|
||||
/// mean-reversion. Using a Simple Moving Average indicator, we can
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
int barsToConsolidate = 1
|
||||
)
|
||||
{
|
||||
// coefficient that used to determinte upper and lower borders of a breakout channel
|
||||
// coefficient that used to determine upper and lower borders of a breakout channel
|
||||
_k1 = k1;
|
||||
_k2 = k2;
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace QuantConnect.Algorithm.CSharp.Alphas
|
||||
SymbolData symbolData;
|
||||
if (_symbolDataBySymbol.TryGetValue(removed.Symbol, out symbolData))
|
||||
{
|
||||
// unsibscribe consolidator from data updates
|
||||
// unsubscribe consolidator from data updates
|
||||
algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, symbolData.GetConsolidator());
|
||||
|
||||
// remove item from dictionary collection
|
||||
|
||||
@@ -73,6 +73,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1893;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 100;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw;
|
||||
EnableAutomaticIndicatorWarmUp = true;
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 09);
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 10);
|
||||
|
||||
var SP500 = QuantConnect.Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME);
|
||||
_symbol = FutureChainProvider.GetFutureContractList(SP500, StartDate).First();
|
||||
@@ -67,7 +67,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
// Test case: custom IndicatorBase<QuoteBar> indicator using Future subscribed symbol
|
||||
var indicator = new CustomIndicator();
|
||||
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(1), typeof(QuoteBar));
|
||||
var consolidator = CreateConsolidator(TimeSpan.FromMinutes(2), typeof(QuoteBar));
|
||||
RegisterIndicator(_symbol, indicator, consolidator);
|
||||
|
||||
AssertIndicatorState(indicator, isReady: false);
|
||||
@@ -143,6 +143,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 6426;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 84;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -151,31 +161,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "19.800%"},
|
||||
{"Compounding Annual Return", "733913.744%"},
|
||||
{"Drawdown", "15.900%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-10.353%"},
|
||||
{"Sharpe Ratio", "-1.379"},
|
||||
{"Net Profit", "6.828%"},
|
||||
{"Sharpe Ratio", "203744786353.302"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "3.004"},
|
||||
{"Beta", "5.322"},
|
||||
{"Annual Standard Deviation", "0.725"},
|
||||
{"Annual Variance", "0.525"},
|
||||
{"Information Ratio", "-0.42"},
|
||||
{"Tracking Error", "0.589"},
|
||||
{"Treynor Ratio", "-0.188"},
|
||||
{"Total Fees", "$20.35"},
|
||||
{"Estimated Strategy Capacity", "$13000000.00"},
|
||||
{"Alpha", "456382350698.561"},
|
||||
{"Beta", "9.229"},
|
||||
{"Annual Standard Deviation", "2.24"},
|
||||
{"Annual Variance", "5.017"},
|
||||
{"Information Ratio", "228504036840.953"},
|
||||
{"Tracking Error", "1.997"},
|
||||
{"Treynor Ratio", "49450701625.718"},
|
||||
{"Total Fees", "$23.65"},
|
||||
{"Estimated Strategy Capacity", "$200000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Fitness Score", "0.125"},
|
||||
{"Fitness Score", "0.518"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-2.162"},
|
||||
{"Return Over Maximum Drawdown", "-8.144"},
|
||||
{"Portfolio Turnover", "3.184"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-7.708"},
|
||||
{"Portfolio Turnover", "5.277"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -189,7 +199,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "7ff48adafe9676f341e64ac9388d3c2c"}
|
||||
{"OrderListHash", "dd38e7b94027d20942a5aa9ac31a9a7f"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3943;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 40;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -293,6 +293,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1748811;
|
||||
|
||||
/// <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>
|
||||
@@ -339,7 +349,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f67306bc706a2cf66288f1cadf6148ed"}
|
||||
{"OrderListHash", "85cbf92f01c2c91b5f710b7eeefecbe1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Brokerages;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
|
||||
@@ -33,6 +34,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
SetStartDate(2018, 04, 04); //Set Start Date
|
||||
SetEndDate(2018, 04, 04); //Set End Date
|
||||
SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
|
||||
//Before setting any cash or adding a Security call SetAccountCurrency
|
||||
SetAccountCurrency("EUR");
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
@@ -63,6 +65,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 4324;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 120;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -87,14 +99,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$85000.00"},
|
||||
{"Total Fees", "€298.35"},
|
||||
{"Estimated Strategy Capacity", "€85000.00"},
|
||||
{"Lowest Capacity Asset", "BTCEUR XJ"},
|
||||
{"Fitness Score", "0.506"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-14.148"},
|
||||
{"Return Over Maximum Drawdown", "-13.614"},
|
||||
{"Portfolio Turnover", "1.073"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -109,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "18dc611407abec4ea47092e71f33f983"}
|
||||
{"OrderListHash", "2ba443899dcccc79dc0f04441f797bf9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3943;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -43,9 +43,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
DefaultOrderProperties = new AtreyuOrderProperties
|
||||
{
|
||||
// Can specify the default exchange to execute an order on.
|
||||
// If not specified will default to the primary exchange
|
||||
Exchange = Exchange.BATS,
|
||||
// Currently only support order for the day
|
||||
TimeInForce = TimeInForce.Day
|
||||
};
|
||||
@@ -59,10 +56,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
// will set 25% of our buying power with a market order that will be routed to exchange set in the default order properties (BATS)
|
||||
// will set 25% of our buying power with a market order
|
||||
SetHoldings("SPY", 0.25m);
|
||||
// will increase our SPY holdings to 50% of our buying power with a market order that will be routed to ARCA
|
||||
SetHoldings("SPY", 0.50m, orderProperties: new AtreyuOrderProperties { Exchange = Exchange.ARCA });
|
||||
|
||||
Debug("Purchased SPY!");
|
||||
}
|
||||
@@ -78,39 +73,49 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3901;
|
||||
|
||||
/// <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 Trades", "2"},
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "93.340%"},
|
||||
{"Drawdown", "1.100%"},
|
||||
{"Compounding Annual Return", "39.143%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.846%"},
|
||||
{"Sharpe Ratio", "6.515"},
|
||||
{"Probabilistic Sharpe Ratio", "67.535%"},
|
||||
{"Net Profit", "0.423%"},
|
||||
{"Sharpe Ratio", "5.634"},
|
||||
{"Probabilistic Sharpe Ratio", "67.498%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0.11"},
|
||||
{"Annual Variance", "0.012"},
|
||||
{"Information Ratio", "6.515"},
|
||||
{"Tracking Error", "0.11"},
|
||||
{"Annual Standard Deviation", "0.055"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "5.634"},
|
||||
{"Tracking Error", "0.055"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$1.20"},
|
||||
{"Estimated Strategy Capacity", "$8600000.00"},
|
||||
{"Total Fees", "$0.60"},
|
||||
{"Estimated Strategy Capacity", "$150000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.124"},
|
||||
{"Fitness Score", "0.062"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "78.222"},
|
||||
{"Portfolio Turnover", "0.124"},
|
||||
{"Return Over Maximum Drawdown", "71.634"},
|
||||
{"Portfolio Turnover", "0.062"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -124,7 +129,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "01a751a837beafd90015b2fd82edf994"}
|
||||
{"OrderListHash", "d549c64ee7f5e3866712b3c7dbd64caa"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
72
Algorithm.CSharp/BasicTemplateCfdAlgorithm.cs
Normal file
72
Algorithm.CSharp/BasicTemplateCfdAlgorithm.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm demonstrating CFD asset types and requesting history.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="history" />
|
||||
/// <meta name="tag" content="cfd" />
|
||||
public class BasicTemplateCfdAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _symbol;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetAccountCurrency("EUR");
|
||||
|
||||
SetStartDate(2019, 2, 20);
|
||||
SetEndDate(2019, 2, 21);
|
||||
SetCash("EUR", 100000);
|
||||
|
||||
_symbol = AddCfd("DE30EUR").Symbol;
|
||||
|
||||
// Historical Data
|
||||
var history = History(_symbol, 60, Resolution.Daily);
|
||||
Log($"Received {history.Count()} bars from CFD historical data call.");
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
// Access Data
|
||||
if (slice.QuoteBars.ContainsKey(_symbol))
|
||||
{
|
||||
var quoteBar = slice.QuoteBars[_symbol];
|
||||
Log($"{quoteBar.EndTime} :: {quoteBar.Close}");
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
SetHoldings(_symbol, 1);
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug($"{Time} {orderEvent.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
@@ -62,7 +63,11 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
foreach (var changedEvent in data.SymbolChangedEvents.Values)
|
||||
{
|
||||
Log($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
Debug($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
if (Time.TimeOfDay != TimeSpan.Zero)
|
||||
{
|
||||
throw new Exception($"{Time} unexpected symbol changed event {changedEvent}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
@@ -78,7 +83,8 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
Liquidate();
|
||||
}
|
||||
|
||||
if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped)
|
||||
// We check exchange hours because the contract mapping can call OnData outside of regular hours.
|
||||
if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped && _continuousContract.Exchange.ExchangeOpen)
|
||||
{
|
||||
Log($"{Time} - rolling position from {_currentContract.Symbol} to {_continuousContract.Mapped}");
|
||||
|
||||
@@ -109,6 +115,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 284403;
|
||||
|
||||
/// <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>
|
||||
@@ -116,31 +132,31 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-0.007%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-0.033%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.004%"},
|
||||
{"Sharpe Ratio", "-0.369"},
|
||||
{"Probabilistic Sharpe Ratio", "10.640%"},
|
||||
{"Net Profit", "-0.017%"},
|
||||
{"Sharpe Ratio", "-1.173"},
|
||||
{"Probabilistic Sharpe Ratio", "0.011%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0"},
|
||||
{"Beta", "0"},
|
||||
{"Beta", "-0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.751"},
|
||||
{"Information Ratio", "-2.752"},
|
||||
{"Tracking Error", "0.082"},
|
||||
{"Treynor Ratio", "-0.616"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Treynor Ratio", "1.883"},
|
||||
{"Total Fees", "$4.30"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Fitness Score", "0.007"},
|
||||
{"Fitness Score", "0.006"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-0.738"},
|
||||
{"Return Over Maximum Drawdown", "-1.993"},
|
||||
{"Portfolio Turnover", "0.01"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
@@ -155,7 +171,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "bd7fbe57802dfedb36c85609b7234016"}
|
||||
{"OrderListHash", "1fd4b49e9450800981c6dead2bbca995"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
using Futures = QuantConnect.Securities.Futures;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic Continuous Futures Template Algorithm with extended market hours
|
||||
/// </summary>
|
||||
public class BasicTemplateContinuousFutureWithExtendedMarketAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Future _continuousContract;
|
||||
private Security _currentContract;
|
||||
private SimpleMovingAverage _fast;
|
||||
private SimpleMovingAverage _slow;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 7, 1);
|
||||
SetEndDate(2014, 1, 1);
|
||||
|
||||
_continuousContract = AddFuture(Futures.Indices.SP500EMini,
|
||||
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
|
||||
dataMappingMode: DataMappingMode.LastTradingDay,
|
||||
contractDepthOffset: 0,
|
||||
extendedMarketHours: true
|
||||
);
|
||||
|
||||
_fast = SMA(_continuousContract.Symbol, 3, Resolution.Daily);
|
||||
_slow = SMA(_continuousContract.Symbol, 10, Resolution.Daily);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
foreach (var changedEvent in data.SymbolChangedEvents.Values)
|
||||
{
|
||||
Debug($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
if (Time.TimeOfDay != TimeSpan.Zero)
|
||||
{
|
||||
throw new Exception($"{Time} unexpected symbol changed event {changedEvent}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsMarketOpen(_continuousContract.Symbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
if(_fast > _slow)
|
||||
{
|
||||
_currentContract = Securities[_continuousContract.Mapped];
|
||||
Buy(_currentContract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
else if(_fast < _slow)
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
|
||||
if (_currentContract != null && _currentContract.Symbol != _continuousContract.Mapped)
|
||||
{
|
||||
Log($"{Time} - rolling position from {_currentContract.Symbol} to {_continuousContract.Mapped}");
|
||||
|
||||
var currentPositionSize = _currentContract.Holdings.Quantity;
|
||||
Liquidate(_currentContract.Symbol);
|
||||
Buy(_continuousContract.Mapped, currentPositionSize);
|
||||
_currentContract = Securities[_continuousContract.Mapped];
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug($"{orderEvent}");
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
Debug($"{Time}-{changes}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 884815;
|
||||
|
||||
/// <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 Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-0.033%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.017%"},
|
||||
{"Sharpe Ratio", "-1.173"},
|
||||
{"Probabilistic Sharpe Ratio", "0.011%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0"},
|
||||
{"Beta", "-0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-2.752"},
|
||||
{"Tracking Error", "0.082"},
|
||||
{"Treynor Ratio", "1.883"},
|
||||
{"Total Fees", "$4.30"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Fitness Score", "0.006"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-1.985"},
|
||||
{"Portfolio Turnover", "0.01"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "adb237703e65b93da5961c0085109732"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -198,6 +198,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 12970;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 240;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
292
Algorithm.CSharp/BasicTemplateCryptoFutureAlgorithm.cs
Normal file
292
Algorithm.CSharp/BasicTemplateCryptoFutureAlgorithm.cs
Normal file
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Brokerages;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Data.Market;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Securities.CryptoFuture;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Minute resolution regression algorithm trading Coin and USDT binance futures long and short asserting the behavior
|
||||
/// </summary>
|
||||
public class BasicTemplateCryptoFutureAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Dictionary<Symbol, int> _interestPerSymbol = new();
|
||||
private CryptoFuture _btcUsd;
|
||||
private CryptoFuture _adaUsdt;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2022, 12, 13); // Set Start Date
|
||||
SetEndDate(2022, 12, 13); // Set End Date
|
||||
|
||||
SetTimeZone(NodaTime.DateTimeZone.Utc);
|
||||
|
||||
try
|
||||
{
|
||||
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Cash);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// expected, we don't allow cash account type
|
||||
}
|
||||
SetBrokerageModel(BrokerageName.BinanceFutures, AccountType.Margin);
|
||||
|
||||
_btcUsd = AddCryptoFuture("BTCUSD");
|
||||
_adaUsdt = AddCryptoFuture("ADAUSDT");
|
||||
|
||||
_fast = EMA(_btcUsd.Symbol, 30, Resolution.Minute);
|
||||
_slow = EMA(_btcUsd.Symbol, 60, Resolution.Minute);
|
||||
|
||||
_interestPerSymbol[_btcUsd.Symbol] = 0;
|
||||
_interestPerSymbol[_adaUsdt.Symbol] = 0;
|
||||
|
||||
// Default USD cash, set 1M but it wont be used
|
||||
SetCash(1000000);
|
||||
|
||||
// the amount of BTC we need to hold to trade 'BTCUSD'
|
||||
_btcUsd.BaseCurrency.SetAmount(0.005m);
|
||||
// the amount of USDT we need to hold to trade 'ADAUSDT'
|
||||
_adaUsdt.QuoteCurrency.SetAmount(200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var interestRates = data.Get<MarginInterestRate>();
|
||||
foreach (var interestRate in interestRates)
|
||||
{
|
||||
_interestPerSymbol[interestRate.Key]++;
|
||||
|
||||
var cachedInterestRate = Securities[interestRate.Key].Cache.GetData<MarginInterestRate>();
|
||||
if (cachedInterestRate != interestRate.Value)
|
||||
{
|
||||
throw new Exception($"Unexpected cached margin interest rate for {interestRate.Key}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (_fast > _slow)
|
||||
{
|
||||
if (!Portfolio.Invested && Transactions.OrdersCount == 0)
|
||||
{
|
||||
var ticket = Buy(_btcUsd.Symbol, 50);
|
||||
if (ticket.Status != OrderStatus.Invalid)
|
||||
{
|
||||
throw new Exception($"Unexpected valid order {ticket}, should fail due to margin not sufficient");
|
||||
}
|
||||
|
||||
Buy(_btcUsd.Symbol, 1);
|
||||
|
||||
var marginUsed = Portfolio.TotalMarginUsed;
|
||||
var btcUsdHoldings = _btcUsd.Holdings;
|
||||
|
||||
// Coin futures value is 100 USD
|
||||
var holdingsValueBtcUsd = 100;
|
||||
|
||||
if (Math.Abs(btcUsdHoldings.TotalSaleVolume - holdingsValueBtcUsd) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalSaleVolume {btcUsdHoldings.TotalSaleVolume}");
|
||||
}
|
||||
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - holdingsValueBtcUsd) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {btcUsdHoldings.HoldingsCost}");
|
||||
}
|
||||
// margin used is based on the maintenance rate
|
||||
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|
||||
|| _btcUsd.BuyingPowerModel.GetMaintenanceMargin(_btcUsd) != marginUsed)
|
||||
{
|
||||
throw new Exception($"Unexpected margin used {marginUsed}");
|
||||
}
|
||||
|
||||
Buy(_adaUsdt.Symbol, 1000);
|
||||
|
||||
marginUsed = Portfolio.TotalMarginUsed - marginUsed;
|
||||
var adaUsdtHoldings = _adaUsdt.Holdings;
|
||||
|
||||
// USDT/BUSD futures value is based on it's price
|
||||
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 1000;
|
||||
|
||||
if (Math.Abs(adaUsdtHoldings.TotalSaleVolume - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalSaleVolume {adaUsdtHoldings.TotalSaleVolume}");
|
||||
}
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
|
||||
}
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|
||||
|| _adaUsdt.BuyingPowerModel.GetMaintenanceMargin(_adaUsdt) != marginUsed)
|
||||
{
|
||||
throw new Exception($"Unexpected margin used {marginUsed}");
|
||||
}
|
||||
|
||||
// position just opened should be just spread here
|
||||
var profit = Portfolio.TotalUnrealizedProfit;
|
||||
if ((5 - Math.Abs(profit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
|
||||
}
|
||||
|
||||
if (Portfolio.TotalProfit != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// let's revert our position and double
|
||||
if (Time.Hour > 10 && Transactions.OrdersCount == 3)
|
||||
{
|
||||
Sell(_btcUsd.Symbol, 3);
|
||||
|
||||
var btcUsdHoldings = _btcUsd.Holdings;
|
||||
|
||||
if (Math.Abs(btcUsdHoldings.AbsoluteHoldingsCost - 100 * 2) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {btcUsdHoldings.HoldingsCost}");
|
||||
}
|
||||
|
||||
Sell(_adaUsdt.Symbol, 3000);
|
||||
|
||||
var adaUsdtHoldings = _adaUsdt.Holdings;
|
||||
|
||||
// USDT/BUSD futures value is based on it's price
|
||||
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 2000;
|
||||
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
|
||||
}
|
||||
|
||||
// position just opened should be just spread here
|
||||
var profit = Portfolio.TotalUnrealizedProfit;
|
||||
if ((5 - Math.Abs(profit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
|
||||
}
|
||||
// we barely did any difference on the previous trade
|
||||
if ((5 - Math.Abs(Portfolio.TotalProfit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_interestPerSymbol[_adaUsdt.Symbol] != 1)
|
||||
{
|
||||
throw new Exception($"Unexpected interest rate count {_interestPerSymbol[_adaUsdt.Symbol]}");
|
||||
}
|
||||
|
||||
if (_interestPerSymbol[_btcUsd.Symbol] != 3)
|
||||
{
|
||||
throw new Exception($"Unexpected interest rate count {_interestPerSymbol[_btcUsd.Symbol]}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug(Time + " " + orderEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 7205;
|
||||
|
||||
/// <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 Trades", "4"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$1.63"},
|
||||
{"Estimated Strategy Capacity", "$630000000.00"},
|
||||
{"Lowest Capacity Asset", "ADAUSDT 18R"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0.001"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "d4520985f69c915060f6bee3b7926cf5"}
|
||||
};
|
||||
}
|
||||
}
|
||||
255
Algorithm.CSharp/BasicTemplateCryptoFutureHourlyAlgorithm.cs
Normal file
255
Algorithm.CSharp/BasicTemplateCryptoFutureHourlyAlgorithm.cs
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Brokerages;
|
||||
using QuantConnect.Data.Market;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Securities.CryptoFuture;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Hourly regression algorithm trading ADAUSDT binance futures long and short asserting the behavior
|
||||
/// </summary>
|
||||
public class BasicTemplateCryptoFutureHourlyAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Dictionary<Symbol, int> _interestPerSymbol = new();
|
||||
private CryptoFuture _adaUsdt;
|
||||
private ExponentialMovingAverage _fast;
|
||||
private ExponentialMovingAverage _slow;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2022, 12, 13);
|
||||
SetEndDate(2022, 12, 13);
|
||||
|
||||
SetTimeZone(NodaTime.DateTimeZone.Utc);
|
||||
|
||||
try
|
||||
{
|
||||
SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Cash);
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// expected, we don't allow cash account type
|
||||
}
|
||||
SetBrokerageModel(BrokerageName.BinanceCoinFutures, AccountType.Margin);
|
||||
|
||||
_adaUsdt = AddCryptoFuture("ADAUSDT", Resolution.Hour);
|
||||
|
||||
_fast = EMA(_adaUsdt.Symbol, 3, Resolution.Hour);
|
||||
_slow = EMA(_adaUsdt.Symbol, 6, Resolution.Hour);
|
||||
|
||||
_interestPerSymbol[_adaUsdt.Symbol] = 0;
|
||||
|
||||
// Default USD cash, set 1M but it wont be used
|
||||
SetCash(1000000);
|
||||
|
||||
// the amount of USDT we need to hold to trade 'ADAUSDT'
|
||||
_adaUsdt.QuoteCurrency.SetAmount(200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice data)
|
||||
{
|
||||
var interestRates = data.Get<MarginInterestRate>();
|
||||
foreach (var interestRate in interestRates)
|
||||
{
|
||||
_interestPerSymbol[interestRate.Key]++;
|
||||
|
||||
var cachedInterestRate = Securities[interestRate.Key].Cache.GetData<MarginInterestRate>();
|
||||
if (cachedInterestRate != interestRate.Value)
|
||||
{
|
||||
throw new Exception($"Unexpected cached margin interest rate for {interestRate.Key}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (_fast > _slow)
|
||||
{
|
||||
if (!Portfolio.Invested && Transactions.OrdersCount == 0)
|
||||
{
|
||||
var ticket = Buy(_adaUsdt.Symbol, 100000);
|
||||
if(ticket.Status != OrderStatus.Invalid)
|
||||
{
|
||||
throw new Exception($"Unexpected valid order {ticket}, should fail due to margin not sufficient");
|
||||
}
|
||||
|
||||
Buy(_adaUsdt.Symbol, 1000);
|
||||
|
||||
var marginUsed = Portfolio.TotalMarginUsed;
|
||||
var adaUsdtHoldings = _adaUsdt.Holdings;
|
||||
|
||||
// USDT/BUSD futures value is based on it's price
|
||||
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 1000;
|
||||
|
||||
if (Math.Abs(adaUsdtHoldings.TotalSaleVolume - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalSaleVolume {adaUsdtHoldings.TotalSaleVolume}");
|
||||
}
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
|
||||
}
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost * 0.05m - marginUsed) > 1
|
||||
|| _adaUsdt.BuyingPowerModel.GetMaintenanceMargin(_adaUsdt) != marginUsed)
|
||||
{
|
||||
throw new Exception($"Unexpected margin used {marginUsed}");
|
||||
}
|
||||
|
||||
// position just opened should be just spread here
|
||||
var profit = Portfolio.TotalUnrealizedProfit;
|
||||
if ((5 - Math.Abs(profit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
|
||||
}
|
||||
|
||||
if (Portfolio.TotalProfit != 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// let's revert our position and double
|
||||
if (Time.Hour > 10 && Transactions.OrdersCount == 2)
|
||||
{
|
||||
Sell(_adaUsdt.Symbol, 3000);
|
||||
|
||||
var adaUsdtHoldings = _adaUsdt.Holdings;
|
||||
|
||||
// USDT/BUSD futures value is based on it's price
|
||||
var holdingsValueUsdt = _adaUsdt.Price * _adaUsdt.SymbolProperties.ContractMultiplier * 2000;
|
||||
|
||||
if (Math.Abs(adaUsdtHoldings.AbsoluteHoldingsCost - holdingsValueUsdt) > 1)
|
||||
{
|
||||
throw new Exception($"Unexpected holdings cost {adaUsdtHoldings.HoldingsCost}");
|
||||
}
|
||||
|
||||
// position just opened should be just spread here
|
||||
var profit = Portfolio.TotalUnrealizedProfit;
|
||||
if ((5 - Math.Abs(profit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalUnrealizedProfit {Portfolio.TotalUnrealizedProfit}");
|
||||
}
|
||||
// we barely did any difference on the previous trade
|
||||
if ((5 - Math.Abs(Portfolio.TotalProfit)) < 0)
|
||||
{
|
||||
throw new Exception($"Unexpected TotalProfit {Portfolio.TotalProfit}");
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.Hour >= 22 && Transactions.OrdersCount == 3)
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_interestPerSymbol[_adaUsdt.Symbol] != 1)
|
||||
{
|
||||
throw new Exception($"Unexpected interest rate count {_interestPerSymbol[_adaUsdt.Symbol]}");
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug(Time + " " + orderEvent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 50;
|
||||
|
||||
/// <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 Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"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", "$1.23"},
|
||||
{"Estimated Strategy Capacity", "$520000000.00"},
|
||||
{"Lowest Capacity Asset", "ADAUSDT 18R"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "-364.162"},
|
||||
{"Portfolio Turnover", "0.001"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "17f99ecc3f35f94fff1ea5694c40d32c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 73;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -84,6 +84,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 3943;
|
||||
|
||||
/// <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>
|
||||
|
||||
95
Algorithm.CSharp/BasicTemplateFutureOptionAlgorithm.cs
Normal file
95
Algorithm.CSharp/BasicTemplateFutureOptionAlgorithm.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm demonstrating FutureOption asset types and requesting history.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="history" />
|
||||
/// <meta name="tag" content="future option" />
|
||||
public class BasicTemplateFutureOptionAlgorithm : QCAlgorithm
|
||||
{
|
||||
private Symbol _symbol;
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2022, 1, 1);
|
||||
SetEndDate(2022, 2, 1);
|
||||
SetCash(100000);
|
||||
|
||||
var gold_futures = AddFuture(Futures.Metals.Gold, Resolution.Minute);
|
||||
gold_futures.SetFilter(0, 180);
|
||||
_symbol = gold_futures.Symbol;
|
||||
AddFutureOption(_symbol, universe => universe.Strikes(-5, +5)
|
||||
.CallsOnly()
|
||||
.BackMonth()
|
||||
.OnlyApplyFilterAtMarketOpen());
|
||||
|
||||
// Historical Data
|
||||
var history = History(_symbol, 60, Resolution.Daily);
|
||||
Log($"Received {history.Count()} bars from {_symbol} FutureOption historical data call.");
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
// Access Data
|
||||
foreach(var kvp in slice.OptionChains)
|
||||
{
|
||||
var underlyingFutureContract = kvp.Key.Underlying;
|
||||
var chain = kvp.Value;
|
||||
|
||||
if (chain.Count() == 0) continue;
|
||||
|
||||
foreach(var contract in chain)
|
||||
{
|
||||
Log($@"Canonical Symbol: {kvp.Key};
|
||||
Contract: {contract};
|
||||
Right: {contract.Right};
|
||||
Expiry: {contract.Expiry};
|
||||
Bid price: {contract.BidPrice};
|
||||
Ask price: {contract.AskPrice};
|
||||
Implied Volatility: {contract.ImpliedVolatility}");
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var atmStrike = chain.OrderBy(x => Math.Abs(chain.Underlying.Price - x.Strike)).First().Strike;
|
||||
var selectedContract = chain.Where(x => x.Strike == atmStrike).OrderByDescending(x => x.Expiry).First();
|
||||
MarketOrder(selectedContract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Debug($"{Time} {orderEvent.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
235
Algorithm.CSharp/BasicTemplateFutureRolloverAlgorithm.cs
Normal file
235
Algorithm.CSharp/BasicTemplateFutureRolloverAlgorithm.cs
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Example algorithm for trading continuous future
|
||||
/// </summary>
|
||||
public class BasicTemplateFutureRolloverAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Dictionary<Symbol, SymbolData> _symbolDataBySymbol = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 8);
|
||||
SetEndDate(2013, 12, 10);
|
||||
SetCash(1000000);
|
||||
|
||||
var futures = new List<string> {
|
||||
Futures.Indices.SP500EMini
|
||||
};
|
||||
|
||||
foreach (var future in futures)
|
||||
{
|
||||
// Requesting data
|
||||
var continuousContract = AddFuture(future,
|
||||
resolution: Resolution.Daily,
|
||||
extendedMarketHours: true,
|
||||
dataNormalizationMode: DataNormalizationMode.BackwardsRatio,
|
||||
dataMappingMode: DataMappingMode.OpenInterest,
|
||||
contractDepthOffset: 0
|
||||
);
|
||||
|
||||
var symbolData = new SymbolData(this, continuousContract);
|
||||
_symbolDataBySymbol.Add(continuousContract.Symbol, symbolData);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
|
||||
/// </summary>
|
||||
/// <param name="slice">Slice object keyed by symbol containing the stock data</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
foreach (var kvp in _symbolDataBySymbol)
|
||||
{
|
||||
var symbol = kvp.Key;
|
||||
var symbolData = kvp.Value;
|
||||
|
||||
// Call SymbolData.Update() method to handle new data slice received
|
||||
symbolData.Update(slice);
|
||||
|
||||
// Check if information in SymbolData class and new slice data are ready for trading
|
||||
if (!symbolData.IsReady || !slice.Bars.ContainsKey(symbol))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var emaCurrentValue = symbolData.EMA.Current.Value;
|
||||
if (emaCurrentValue < symbolData.Price && !symbolData.IsLong)
|
||||
{
|
||||
MarketOrder(symbolData.Mapped, 1);
|
||||
}
|
||||
else if (emaCurrentValue > symbolData.Price && !symbolData.IsShort)
|
||||
{
|
||||
MarketOrder(symbolData.Mapped, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstracted class object to hold information (state, indicators, methods, etc.) from a Symbol/Security in a multi-security algorithm
|
||||
/// </summary>
|
||||
public class SymbolData
|
||||
{
|
||||
private QCAlgorithm _algorithm;
|
||||
private Future _future;
|
||||
public ExponentialMovingAverage EMA;
|
||||
public decimal Price;
|
||||
public bool IsLong;
|
||||
public bool IsShort;
|
||||
public Symbol Symbol => _future.Symbol;
|
||||
public Symbol Mapped => _future.Mapped;
|
||||
|
||||
/// <summary>
|
||||
/// Check if symbolData class object are ready for trading
|
||||
/// </summary>
|
||||
public bool IsReady => Mapped != null && EMA.IsReady;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to instantiate the information needed to be hold
|
||||
/// </summary>
|
||||
public SymbolData(QCAlgorithm algorithm, Future future)
|
||||
{
|
||||
_algorithm = algorithm;
|
||||
_future = future;
|
||||
EMA = algorithm.EMA(future.Symbol, 20, Resolution.Daily);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler of new slice of data received
|
||||
/// </summary>
|
||||
public void Update(Slice slice)
|
||||
{
|
||||
if (slice.SymbolChangedEvents.TryGetValue(Symbol, out var changedEvent))
|
||||
{
|
||||
var oldSymbol = changedEvent.OldSymbol;
|
||||
var newSymbol = changedEvent.NewSymbol;
|
||||
var tag = $"Rollover - Symbol changed at {_algorithm.Time}: {oldSymbol} -> {newSymbol}";
|
||||
var quantity = _algorithm.Portfolio[oldSymbol].Quantity;
|
||||
|
||||
// Rolling over: to liquidate any position of the old mapped contract and switch to the newly mapped contract
|
||||
_algorithm.Liquidate(oldSymbol, tag: tag);
|
||||
_algorithm.MarketOrder(newSymbol, quantity, tag: tag);
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
Price = slice.Bars.ContainsKey(Symbol) ? slice.Bars[Symbol].Price : Price;
|
||||
IsLong = _algorithm.Portfolio[Mapped].IsLong;
|
||||
IsShort = _algorithm.Portfolio[Mapped].IsShort;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset RollingWindow/indicator to adapt to newly mapped contract, then warm up the RollingWindow/indicator
|
||||
/// </summary>
|
||||
private void Reset()
|
||||
{
|
||||
EMA.Reset();
|
||||
_algorithm.WarmUpIndicator(Symbol, EMA, Resolution.Daily);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposal method to remove consolidator/update method handler, and reset RollingWindow/indicator to free up memory and speed
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
EMA.Reset();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 995;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 4;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0.53%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "3.011%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0.528%"},
|
||||
{"Sharpe Ratio", "1.999"},
|
||||
{"Probabilistic Sharpe Ratio", "83.704%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "100%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0.023"},
|
||||
{"Beta", "-0.004"},
|
||||
{"Annual Standard Deviation", "0.011"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-4.774"},
|
||||
{"Tracking Error", "0.084"},
|
||||
{"Treynor Ratio", "-4.853"},
|
||||
{"Total Fees", "$4.30"},
|
||||
{"Estimated Strategy Capacity", "$5900000000.00"},
|
||||
{"Lowest Capacity Asset", "ES VMKLFZIH2MTD"},
|
||||
{"Fitness Score", "0.002"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "1792.236"},
|
||||
{"Portfolio Turnover", "0.002"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "40e4b91ec89383f6501d9ba324e50eb9"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
@@ -58,12 +59,15 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
// set our expiry filter for this futures chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
futureGold.SetFilter(0, 182);
|
||||
|
||||
var benchmark = AddEquity("SPY");
|
||||
SetBenchmark(benchmark.Symbol);
|
||||
|
||||
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
|
||||
SetSecurityInitializer(security => seeder.SeedSecurity(security));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,6 +76,15 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <param name="slice">The current slice of data keyed by symbol string</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
|
||||
{
|
||||
Debug($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
if (Time.TimeOfDay != TimeSpan.Zero)
|
||||
{
|
||||
throw new Exception($"{Time} unexpected symbol changed event {changedEvent}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
foreach(var chain in slice.FutureChains)
|
||||
@@ -112,6 +125,19 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var addedSecurity in changes.AddedSecurities)
|
||||
{
|
||||
if (addedSecurity.Symbol.SecurityType == SecurityType.Future
|
||||
&& !addedSecurity.Symbol.IsCanonical()
|
||||
&& !addedSecurity.HasData)
|
||||
{
|
||||
throw new Exception($"Future contracts did not work up as expected: {addedSecurity.Symbol}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
@@ -122,39 +148,49 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 68645;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 340;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "8220"},
|
||||
{"Total Trades", "2700"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "13.500%"},
|
||||
{"Expectancy", "-0.818"},
|
||||
{"Net Profit", "-13.517%"},
|
||||
{"Sharpe Ratio", "-98.781"},
|
||||
{"Compounding Annual Return", "-99.777%"},
|
||||
{"Drawdown", "4.400%"},
|
||||
{"Expectancy", "-0.724"},
|
||||
{"Net Profit", "-4.430%"},
|
||||
{"Sharpe Ratio", "-31.389"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "89%"},
|
||||
{"Win Rate", "11%"},
|
||||
{"Profit-Loss Ratio", "0.69"},
|
||||
{"Alpha", "-1.676"},
|
||||
{"Beta", "0.042"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-73.981"},
|
||||
{"Tracking Error", "0.233"},
|
||||
{"Treynor Ratio", "-23.975"},
|
||||
{"Total Fees", "$15207.00"},
|
||||
{"Estimated Strategy Capacity", "$8000.00"},
|
||||
{"Loss Rate", "83%"},
|
||||
{"Win Rate", "17%"},
|
||||
{"Profit-Loss Ratio", "0.65"},
|
||||
{"Alpha", "-3.059"},
|
||||
{"Beta", "0.128"},
|
||||
{"Annual Standard Deviation", "0.031"},
|
||||
{"Annual Variance", "0.001"},
|
||||
{"Information Ratio", "-81.232"},
|
||||
{"Tracking Error", "0.212"},
|
||||
{"Treynor Ratio", "-7.618"},
|
||||
{"Total Fees", "$6237.00"},
|
||||
{"Estimated Strategy Capacity", "$14000.00"},
|
||||
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
|
||||
{"Fitness Score", "0.033"},
|
||||
{"Fitness Score", "0.001"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-8.62"},
|
||||
{"Return Over Maximum Drawdown", "-7.81"},
|
||||
{"Portfolio Turnover", "302.321"},
|
||||
{"Sortino Ratio", "-58.725"},
|
||||
{"Return Over Maximum Drawdown", "-32.073"},
|
||||
{"Portfolio Turnover", "98.477"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -168,7 +204,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "35b3f4b7a225468d42ca085386a2383e"}
|
||||
{"OrderListHash", "8f92e1528c6477a156449fd1e86527e7"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ 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
|
||||
{
|
||||
@@ -31,14 +33,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesDailyAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contractSymbol;
|
||||
protected virtual Resolution Resolution => Resolution.Daily;
|
||||
protected virtual bool ExtendedMarketHours => false;
|
||||
|
||||
// S&P 500 EMini futures
|
||||
private const string RootSP500 = Futures.Indices.SP500EMini;
|
||||
|
||||
// Gold futures
|
||||
private const string RootGold = Futures.Metals.Gold;
|
||||
private Future _futureSP500;
|
||||
private Future _futureGold;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
@@ -46,17 +50,17 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 10);
|
||||
SetEndDate(2014, 10, 10);
|
||||
SetCash(1000000);
|
||||
|
||||
var futureSP500 = AddFuture(RootSP500, Resolution);
|
||||
var futureGold = AddFuture(RootGold, Resolution);
|
||||
_futureSP500 = AddFuture(RootSP500, Resolution, extendedMarketHours: ExtendedMarketHours);
|
||||
_futureGold = AddFuture(RootGold, Resolution, extendedMarketHours: ExtendedMarketHours);
|
||||
|
||||
// set our expiry filter for this futures chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
futureGold.SetFilter(0, 182);
|
||||
// The following statements yield the same filtering criteria
|
||||
_futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
_futureGold.SetFilter(0, 182);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,18 +80,28 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
select futuresContract
|
||||
).FirstOrDefault();
|
||||
|
||||
// if found, trade it
|
||||
if (contract != null)
|
||||
// if found, trade it.
|
||||
// Also check if exchange is open for regular or extended hours. Since daily data comes at 8PM, this allows us prevent the
|
||||
// algorithm from trading on friday when there is not after-market.
|
||||
if (contract != null && Securities[contract.Symbol].Exchange.Hours.IsOpen(Time, true))
|
||||
{
|
||||
_contractSymbol = contract.Symbol;
|
||||
MarketOrder(_contractSymbol, 1);
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
// Same as above, check for cases like trading on a friday night.
|
||||
else if (Securities.Values.Where(x => x.Invested).All(x => x.Exchange.Hours.IsOpen(Time, true)))
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
|
||||
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
|
||||
{
|
||||
if (Time.TimeOfDay != TimeSpan.Zero)
|
||||
{
|
||||
throw new Exception($"{Time} unexpected symbol changed event {changedEvent}!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,39 +114,49 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 11709;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual 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 virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-0.10%"},
|
||||
{"Compounding Annual Return", "-23.119%"},
|
||||
{"Drawdown", "0.300%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.276%"},
|
||||
{"Sharpe Ratio", "-13.736"},
|
||||
{"Total Trades", "118"},
|
||||
{"Average Win", "0.09%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-0.479%"},
|
||||
{"Drawdown", "0.500%"},
|
||||
{"Expectancy", "-0.835"},
|
||||
{"Net Profit", "-0.483%"},
|
||||
{"Sharpe Ratio", "-1.938"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.526"},
|
||||
{"Beta", "0.057"},
|
||||
{"Annual Standard Deviation", "0.015"},
|
||||
{"Loss Rate", "98%"},
|
||||
{"Win Rate", "2%"},
|
||||
{"Profit-Loss Ratio", "8.76"},
|
||||
{"Alpha", "-0.003"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.002"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-31.088"},
|
||||
{"Tracking Error", "0.189"},
|
||||
{"Treynor Ratio", "-3.51"},
|
||||
{"Total Fees", "$11.10"},
|
||||
{"Estimated Strategy Capacity", "$200000000.00"},
|
||||
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Information Ratio", "-1.397"},
|
||||
{"Tracking Error", "0.089"},
|
||||
{"Treynor Ratio", "5.665"},
|
||||
{"Total Fees", "$263.30"},
|
||||
{"Estimated Strategy Capacity", "$1000.00"},
|
||||
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
|
||||
{"Fitness Score", "0.01"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-17.118"},
|
||||
{"Return Over Maximum Drawdown", "-83.844"},
|
||||
{"Portfolio Turnover", "0.16"},
|
||||
{"Sortino Ratio", "-1.059"},
|
||||
{"Return Over Maximum Drawdown", "-0.992"},
|
||||
{"Portfolio Turnover", "0.031"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -146,7 +170,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "512f55519e5221c7e82e1d9f5ddd1b9f"}
|
||||
{"OrderListHash", "b75b224669c374dcbacc33f946a1cc7c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,12 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public class BasicTemplateFuturesFrameworkAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
protected virtual bool ExtendedMarketHours => false;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
UniverseSettings.ExtendedMarketHours = ExtendedMarketHours;
|
||||
|
||||
SetStartDate(2013, 10, 07);
|
||||
SetEndDate(2013, 10, 11);
|
||||
@@ -123,60 +126,70 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <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;
|
||||
public virtual bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 43786;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual 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>
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-92.656%"},
|
||||
{"Drawdown", "5.000%"},
|
||||
{"Compounding Annual Return", "-81.734%"},
|
||||
{"Drawdown", "4.100%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-3.312%"},
|
||||
{"Sharpe Ratio", "-6.305"},
|
||||
{"Probabilistic Sharpe Ratio", "9.342%"},
|
||||
{"Net Profit", "-2.169%"},
|
||||
{"Sharpe Ratio", "-10.195"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-1.465"},
|
||||
{"Beta", "0.312"},
|
||||
{"Annual Standard Deviation", "0.134"},
|
||||
{"Annual Variance", "0.018"},
|
||||
{"Information Ratio", "-14.77"},
|
||||
{"Tracking Error", "0.192"},
|
||||
{"Treynor Ratio", "-2.718"},
|
||||
{"Total Fees", "$3.70"},
|
||||
{"Estimated Strategy Capacity", "$52000000.00"},
|
||||
{"Alpha", "-1.206"},
|
||||
{"Beta", "0.238"},
|
||||
{"Annual Standard Deviation", "0.072"},
|
||||
{"Annual Variance", "0.005"},
|
||||
{"Information Ratio", "-15.404"},
|
||||
{"Tracking Error", "0.176"},
|
||||
{"Treynor Ratio", "-3.077"},
|
||||
{"Total Fees", "$4.62"},
|
||||
{"Estimated Strategy Capacity", "$17000000.00"},
|
||||
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
|
||||
{"Fitness Score", "0.009"},
|
||||
{"Kelly Criterion Estimate", "-112.972"},
|
||||
{"Kelly Criterion Probability Value", "0.671"},
|
||||
{"Sortino Ratio", "-8.425"},
|
||||
{"Return Over Maximum Drawdown", "-35.219"},
|
||||
{"Portfolio Turnover", "0.548"},
|
||||
{"Total Insights Generated", "6"},
|
||||
{"Total Insights Closed", "5"},
|
||||
{"Total Insights Analysis Completed", "5"},
|
||||
{"Long Insight Count", "6"},
|
||||
{"Fitness Score", "0.006"},
|
||||
{"Kelly Criterion Estimate", "-50.022"},
|
||||
{"Kelly Criterion Probability Value", "0.711"},
|
||||
{"Sortino Ratio", "-9.907"},
|
||||
{"Return Over Maximum Drawdown", "-50.79"},
|
||||
{"Portfolio Turnover", "0.54"},
|
||||
{"Total Insights Generated", "5"},
|
||||
{"Total Insights Closed", "4"},
|
||||
{"Total Insights Analysis Completed", "4"},
|
||||
{"Long Insight Count", "5"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$-96.12923"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-15.621"},
|
||||
{"Mean Population Estimated Insight Value", "$-3.1242"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Estimated Monthly Alpha Value", "$-4434.791"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-720.6535"},
|
||||
{"Mean Population Estimated Insight Value", "$-180.1634"},
|
||||
{"Mean Population Direction", "25%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Direction", "25%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "18ffd3a774c68da83d867e3b09e3e05d"}
|
||||
{"OrderListHash", "323b899ae80aa839e320806411665ce7"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
using QuantConnect.Algorithm.Framework.Execution;
|
||||
using QuantConnect.Algorithm.Framework.Portfolio;
|
||||
using QuantConnect.Algorithm.Framework.Risk;
|
||||
using QuantConnect.Algorithm.Framework.Selection;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template futures framework algorithm uses framework components to define an algorithm
|
||||
/// that trades futures.
|
||||
/// </summary>
|
||||
public class BasicTemplateFuturesFrameworkWithExtendedMarketAlgorithm : BasicTemplateFuturesFrameworkAlgorithm
|
||||
{
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 123753;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "2"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-92.667%"},
|
||||
{"Drawdown", "5.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-3.314%"},
|
||||
{"Sharpe Ratio", "-6.303"},
|
||||
{"Probabilistic Sharpe Ratio", "9.333%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-1.465"},
|
||||
{"Beta", "0.312"},
|
||||
{"Annual Standard Deviation", "0.134"},
|
||||
{"Annual Variance", "0.018"},
|
||||
{"Information Ratio", "-14.77"},
|
||||
{"Tracking Error", "0.192"},
|
||||
{"Treynor Ratio", "-2.718"},
|
||||
{"Total Fees", "$4.62"},
|
||||
{"Estimated Strategy Capacity", "$52000000.00"},
|
||||
{"Lowest Capacity Asset", "GC VL5E74HP3EE5"},
|
||||
{"Fitness Score", "0.009"},
|
||||
{"Kelly Criterion Estimate", "-112.972"},
|
||||
{"Kelly Criterion Probability Value", "0.671"},
|
||||
{"Sortino Ratio", "-8.421"},
|
||||
{"Return Over Maximum Drawdown", "-35.2"},
|
||||
{"Portfolio Turnover", "0.548"},
|
||||
{"Total Insights Generated", "6"},
|
||||
{"Total Insights Closed", "5"},
|
||||
{"Total Insights Analysis Completed", "5"},
|
||||
{"Long Insight Count", "6"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$-96.12923"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$-15.621"},
|
||||
{"Mean Population Estimated Insight Value", "$-3.1242"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "18ffd3a774c68da83d867e3b09e3e05d"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,9 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesHistoryAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
protected virtual bool ExtendedMarketHours => false;
|
||||
protected virtual int ExpectedHistoryCallCount => 42;
|
||||
|
||||
// S&P 500 EMini futures
|
||||
private string [] roots = new []
|
||||
{
|
||||
@@ -44,7 +47,6 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
};
|
||||
|
||||
private int _successCount = 0;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 8);
|
||||
@@ -54,7 +56,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
foreach (var root in roots)
|
||||
{
|
||||
// set our expiry filter for this futures chain
|
||||
AddFuture(root, Resolution.Minute).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
AddFuture(root, Resolution.Minute, extendedMarketHours: ExtendedMarketHours).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
}
|
||||
|
||||
SetBenchmark(d => 1000000);
|
||||
@@ -74,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (_successCount < 49)
|
||||
if (_successCount < ExpectedHistoryCallCount)
|
||||
{
|
||||
throw new Exception($"Scheduled Event did not assert history call as many times as expected: {_successCount}/49");
|
||||
}
|
||||
@@ -118,7 +120,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
@@ -128,17 +130,27 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <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;
|
||||
public virtual bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 44184;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 4818;
|
||||
|
||||
/// <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>
|
||||
public virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Data.UniverseSelection;
|
||||
using QuantConnect.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to get access to futures history for a given root symbol with extended market hours.
|
||||
/// It also shows how you can prefilter contracts easily based on expirations, and inspect the futures
|
||||
/// chain to pick a specific contract to trade.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="history and warm up" />
|
||||
/// <meta name="tag" content="history" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesHistoryWithExtendedMarketHoursAlgorithm : BasicTemplateFuturesHistoryAlgorithm
|
||||
{
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
protected override int ExpectedHistoryCallCount => 49;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 134096;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 5539;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "0"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$0.00"},
|
||||
{"Estimated Strategy Capacity", "$0"},
|
||||
{"Lowest Capacity Asset", ""},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "79228162514264337593543950335"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "d41d8cd98f00b204e9800998ecf8427e"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -31,52 +31,51 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesHourlyAlgorithm : BasicTemplateFuturesDailyAlgorithm
|
||||
{
|
||||
private Symbol _contractSymbol;
|
||||
protected override Resolution Resolution => Resolution.Hour;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public override bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 73252;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "140"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.02%"},
|
||||
{"Compounding Annual Return", "-38.171%"},
|
||||
{"Drawdown", "0.400%"},
|
||||
{"Expectancy", "-0.369"},
|
||||
{"Net Profit", "-0.394%"},
|
||||
{"Sharpe Ratio", "-24.82"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "66%"},
|
||||
{"Win Rate", "34%"},
|
||||
{"Profit-Loss Ratio", "0.84"},
|
||||
{"Alpha", "0.42"},
|
||||
{"Beta", "-0.041"},
|
||||
{"Annual Standard Deviation", "0.01"},
|
||||
{"Total Trades", "638"},
|
||||
{"Average Win", "0.02%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-1.610%"},
|
||||
{"Drawdown", "1.600%"},
|
||||
{"Expectancy", "-0.841"},
|
||||
{"Net Profit", "-1.622%"},
|
||||
{"Sharpe Ratio", "-5.105"},
|
||||
{"Probabilistic Sharpe Ratio", "0.000%"},
|
||||
{"Loss Rate", "96%"},
|
||||
{"Win Rate", "4%"},
|
||||
{"Profit-Loss Ratio", "3.21"},
|
||||
{"Alpha", "-0.01"},
|
||||
{"Beta", "-0.003"},
|
||||
{"Annual Standard Deviation", "0.002"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-65.112"},
|
||||
{"Tracking Error", "0.253"},
|
||||
{"Treynor Ratio", "6.024"},
|
||||
{"Total Fees", "$259.00"},
|
||||
{"Estimated Strategy Capacity", "$130000.00"},
|
||||
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Information Ratio", "-1.473"},
|
||||
{"Tracking Error", "0.089"},
|
||||
{"Treynor Ratio", "3.179"},
|
||||
{"Total Fees", "$1456.18"},
|
||||
{"Estimated Strategy Capacity", "$6000.00"},
|
||||
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
|
||||
{"Fitness Score", "0.045"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-43.422"},
|
||||
{"Return Over Maximum Drawdown", "-100.459"},
|
||||
{"Portfolio Turnover", "4.716"},
|
||||
{"Sortino Ratio", "-4.326"},
|
||||
{"Return Over Maximum Drawdown", "-0.994"},
|
||||
{"Portfolio Turnover", "0.205"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
@@ -90,7 +89,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "320067074c8dd771f69602ab07001f1e"}
|
||||
{"OrderListHash", "8842e0b890f721371ebf3c25328dee5b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to add futures for a given underlying asset.
|
||||
/// It also shows how you can prefilter contracts easily based on expirations, and how you
|
||||
/// can inspect the futures chain to pick a specific contract to trade.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesWithExtendedMarketAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
private Symbol _contractSymbol;
|
||||
|
||||
// S&P 500 EMini futures
|
||||
private const string RootSP500 = Futures.Indices.SP500EMini;
|
||||
public Symbol SP500 = QuantConnect.Symbol.Create(RootSP500, SecurityType.Future, Market.CME);
|
||||
|
||||
// Gold futures
|
||||
private const string RootGold = Futures.Metals.Gold;
|
||||
public Symbol Gold = QuantConnect.Symbol.Create(RootGold, SecurityType.Future, Market.COMEX);
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2013, 10, 08);
|
||||
SetEndDate(2013, 10, 10);
|
||||
SetCash(1000000);
|
||||
|
||||
var futureSP500 = AddFuture(RootSP500, extendedMarketHours: true);
|
||||
var futureGold = AddFuture(RootGold, extendedMarketHours: true);
|
||||
|
||||
// set our expiry filter for this futures chain
|
||||
// SetFilter method accepts TimeSpan objects or integer for days.
|
||||
// The following statements yield the same filtering criteria
|
||||
futureSP500.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
|
||||
futureGold.SetFilter(0, 182);
|
||||
|
||||
var benchmark = AddEquity("SPY");
|
||||
SetBenchmark(benchmark.Symbol);
|
||||
|
||||
var seeder = new FuncSecuritySeeder(GetLastKnownPrices);
|
||||
SetSecurityInitializer(security => seeder.SeedSecurity(security));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event
|
||||
/// </summary>
|
||||
/// <param name="slice">The current slice of data keyed by symbol string</param>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
foreach (var changedEvent in slice.SymbolChangedEvents.Values)
|
||||
{
|
||||
Debug($"{Time} - SymbolChanged event: {changedEvent}");
|
||||
if (Time.TimeOfDay != TimeSpan.Zero)
|
||||
{
|
||||
throw new Exception($"{Time} unexpected symbol changed event {changedEvent}!");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
foreach(var chain in slice.FutureChains)
|
||||
{
|
||||
// find the front contract expiring no earlier than in 90 days
|
||||
var contract = (
|
||||
from futuresContract in chain.Value.OrderBy(x => x.Expiry)
|
||||
where futuresContract.Expiry > Time.Date.AddDays(90)
|
||||
select futuresContract
|
||||
).FirstOrDefault();
|
||||
|
||||
// if found, trade it
|
||||
if (contract != null)
|
||||
{
|
||||
_contractSymbol = contract.Symbol;
|
||||
MarketOrder(_contractSymbol, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
// Get the margin requirements
|
||||
var buyingPowerModel = Securities[_contractSymbol].BuyingPowerModel;
|
||||
var futureMarginModel = buyingPowerModel as FutureMarginModel;
|
||||
if (buyingPowerModel == null)
|
||||
{
|
||||
throw new Exception($"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}");
|
||||
}
|
||||
var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;
|
||||
var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;
|
||||
var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;
|
||||
var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;
|
||||
}
|
||||
|
||||
public override void OnSecuritiesChanged(SecurityChanges changes)
|
||||
{
|
||||
foreach (var addedSecurity in changes.AddedSecurities)
|
||||
{
|
||||
if (addedSecurity.Symbol.SecurityType == SecurityType.Future
|
||||
&& !addedSecurity.Symbol.IsCanonical()
|
||||
&& !addedSecurity.HasData)
|
||||
{
|
||||
throw new Exception($"Future contracts did not work up as expected: {addedSecurity.Symbol}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 204087;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public int AlgorithmHistoryDataPoints => 340;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "8282"},
|
||||
{"Average Win", "0.00%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-100.000%"},
|
||||
{"Drawdown", "13.900%"},
|
||||
{"Expectancy", "-0.824"},
|
||||
{"Net Profit", "-13.874%"},
|
||||
{"Sharpe Ratio", "-19.202"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "89%"},
|
||||
{"Win Rate", "11%"},
|
||||
{"Profit-Loss Ratio", "0.64"},
|
||||
{"Alpha", "2.477"},
|
||||
{"Beta", "-0.215"},
|
||||
{"Annual Standard Deviation", "0.052"},
|
||||
{"Annual Variance", "0.003"},
|
||||
{"Information Ratio", "-58.37"},
|
||||
{"Tracking Error", "0.295"},
|
||||
{"Treynor Ratio", "4.66"},
|
||||
{"Total Fees", "$19131.42"},
|
||||
{"Estimated Strategy Capacity", "$130000.00"},
|
||||
{"Lowest Capacity Asset", "GC VOFJUCDY9XNH"},
|
||||
{"Fitness Score", "0.032"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-9.217"},
|
||||
{"Return Over Maximum Drawdown", "-7.692"},
|
||||
{"Portfolio Turnover", "304.869"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "85cdd035d7c7a3da178d1c2dff31f1bd"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
using QuantConnect.Securities;
|
||||
using QuantConnect.Securities.Future;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to add futures with daily resolution and extended market hours.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesWithExtendedMarketDailyAlgorithm : BasicTemplateFuturesDailyAlgorithm
|
||||
{
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 13559;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "152"},
|
||||
{"Average Win", "0.09%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-0.644%"},
|
||||
{"Drawdown", "0.600%"},
|
||||
{"Expectancy", "-0.872"},
|
||||
{"Net Profit", "-0.649%"},
|
||||
{"Sharpe Ratio", "-2.343"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "99%"},
|
||||
{"Win Rate", "1%"},
|
||||
{"Profit-Loss Ratio", "8.76"},
|
||||
{"Alpha", "-0.004"},
|
||||
{"Beta", "-0.001"},
|
||||
{"Annual Standard Deviation", "0.002"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.409"},
|
||||
{"Tracking Error", "0.089"},
|
||||
{"Treynor Ratio", "3.618"},
|
||||
{"Total Fees", "$338.96"},
|
||||
{"Estimated Strategy Capacity", "$1000.00"},
|
||||
{"Lowest Capacity Asset", "ES VRJST036ZY0X"},
|
||||
{"Fitness Score", "0.013"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-1.464"},
|
||||
{"Return Over Maximum Drawdown", "-0.992"},
|
||||
{"Portfolio Turnover", "0.04"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "48bfc4d255420cb589e00cf582554e0a"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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>
|
||||
/// This regressions tests the BasicTemplateFuturesDailyAlgorithm with hour data and extended market hours
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
/// <meta name="tag" content="futures" />
|
||||
public class BasicTemplateFuturesWithExtendedMarketHourlyAlgorithm : BasicTemplateFuturesHourlyAlgorithm
|
||||
{
|
||||
protected override bool ExtendedMarketHours => true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 205645;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
public override Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "1982"},
|
||||
{"Average Win", "0.01%"},
|
||||
{"Average Loss", "-0.01%"},
|
||||
{"Compounding Annual Return", "-4.666%"},
|
||||
{"Drawdown", "4.700%"},
|
||||
{"Expectancy", "-0.911"},
|
||||
{"Net Profit", "-4.700%"},
|
||||
{"Sharpe Ratio", "-5.792"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "97%"},
|
||||
{"Win Rate", "3%"},
|
||||
{"Profit-Loss Ratio", "2.04"},
|
||||
{"Alpha", "-0.031"},
|
||||
{"Beta", "-0.008"},
|
||||
{"Annual Standard Deviation", "0.005"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.701"},
|
||||
{"Tracking Error", "0.09"},
|
||||
{"Treynor Ratio", "4.096"},
|
||||
{"Total Fees", "$4521.78"},
|
||||
{"Estimated Strategy Capacity", "$2000.00"},
|
||||
{"Lowest Capacity Asset", "ES VP274HSU1AF5"},
|
||||
{"Fitness Score", "0.131"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-6.211"},
|
||||
{"Return Over Maximum Drawdown", "-0.995"},
|
||||
{"Portfolio Turnover", "0.649"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$0"},
|
||||
{"Mean Population Estimated Insight Value", "$0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "2402a307b20aee195b77b8478d7ca64d"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 78;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
protected Symbol SpxOption;
|
||||
private ExponentialMovingAverage _emaSlow;
|
||||
private ExponentialMovingAverage _emaFast;
|
||||
|
||||
|
||||
protected virtual Resolution Resolution => Resolution.Minute;
|
||||
protected virtual int StartDay => 4;
|
||||
|
||||
@@ -109,6 +109,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 16690;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -155,7 +165,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "0668385036aba3e95127607dfc2f1a59"}
|
||||
{"OrderListHash", "3b71b146c15d234b4dc9e201838b551c"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
// two complete weeks starting from the 5th plus the 18th bar
|
||||
protected virtual int ExpectedBarCount => 2 * 5 + 1;
|
||||
protected int BarCounter = 0;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Purchase a contract when we are not invested, liquidate otherwise
|
||||
/// </summary>
|
||||
@@ -30,7 +30,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
|
||||
|
||||
// Count how many slices we receive with SPX data in it to assert later
|
||||
if (slice.ContainsKey(Spx))
|
||||
{
|
||||
@@ -56,6 +56,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 122;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -102,7 +112,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "474e8e0e28ee84c869f8c69ec3efe371"}
|
||||
{"OrderListHash", "0ee6860210d55051c38e494bd24bb6de"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 408;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -66,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "3eb56c551f20e2ffa1c56c47c5ee6667"}
|
||||
{"OrderListHash", "0c74daf716d7782a7e89c7a0ea57856f"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public virtual Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public virtual long DataPoints => 0;
|
||||
|
||||
/// </summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public virtual int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
|
||||
@@ -65,6 +65,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 381;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -111,7 +121,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "5f5df233d68d9115a0d81785de54e71d"}
|
||||
{"OrderListHash", "607d309c5fb52a8b88310720b4a867e1"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public override Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 2212;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 0;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate what the expected statistics are from running the algorithm
|
||||
/// </summary>
|
||||
@@ -81,7 +91,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "f21910eb98ceaa39e02020de95354d86"}
|
||||
{"OrderListHash", "cc19277c90eb3b1f1e09ee15dfa7029b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
*/
|
||||
|
||||
using QuantConnect.Data;
|
||||
using QuantConnect.Orders;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
@@ -26,28 +27,29 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="using quantconnect" />
|
||||
/// <meta name="tag" content="trading and orders" />
|
||||
public class BasicTemplateIndiaAlgorithm : QCAlgorithm
|
||||
public class BasicTemplateIndiaAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2003, 10, 07); //Set Start Date
|
||||
SetEndDate(2003, 10, 11); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
SetAccountCurrency("INR"); //Set Account Currency
|
||||
SetStartDate(2019, 1, 23); //Set Start Date
|
||||
SetEndDate(2019, 10, 31); //Set End Date
|
||||
SetCash(100000); //Set Strategy Cash
|
||||
|
||||
// Find more symbols here: http://quantconnect.com/data
|
||||
// Equities Resolutions: Tick, Second, Minute, Hour, Daily.
|
||||
AddEquity("UNIONBANK", Resolution.Second, Market.India);
|
||||
AddEquity("YESBANK", Resolution.Minute, Market.India);
|
||||
|
||||
//Set Order Prperties as per the requirements for order placement
|
||||
//Set Order Properties as per the requirements for order placement
|
||||
DefaultOrderProperties = new IndiaOrderProperties(exchange: Exchange.NSE);
|
||||
//override default productType value set in config.json if needed - order specific productType value
|
||||
//DefaultOrderProperties = new IndiaOrderProperties(exchange: Exchange.NSE, IndiaOrderProperties.IndiaProductType.CNC);
|
||||
|
||||
// General Debug statement for acknowledgement
|
||||
Debug("Intialization Done");
|
||||
Debug("Initialization Done");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,7 +60,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var marketTicket = MarketOrder("UNIONBANK", 1);
|
||||
var marketTicket = MarketOrder("YESBANK", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,60 +75,70 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public bool CanRunLocally { get; } = false;
|
||||
public bool CanRunLocally { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate which languages this algorithm is written in.
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 29524;
|
||||
|
||||
/// <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 Trades", "3"},
|
||||
{"Total Trades", "1"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "-1.01%"},
|
||||
{"Compounding Annual Return", "261.134%"},
|
||||
{"Drawdown", "2.200%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "1.655%"},
|
||||
{"Sharpe Ratio", "8.505"},
|
||||
{"Probabilistic Sharpe Ratio", "66.840%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "-0.010%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "-0.008%"},
|
||||
{"Sharpe Ratio", "-1.183"},
|
||||
{"Probabilistic Sharpe Ratio", "0.001%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "-0.091"},
|
||||
{"Beta", "1.006"},
|
||||
{"Annual Standard Deviation", "0.224"},
|
||||
{"Annual Variance", "0.05"},
|
||||
{"Information Ratio", "-33.445"},
|
||||
{"Tracking Error", "0.002"},
|
||||
{"Treynor Ratio", "1.893"},
|
||||
{"Total Fees", "$10.32"},
|
||||
{"Estimated Strategy Capacity", "$27000000.00"},
|
||||
{"Lowest Capacity Asset", "SPY R735QTJ8XC9X"},
|
||||
{"Fitness Score", "0.747"},
|
||||
{"Kelly Criterion Estimate", "38.796"},
|
||||
{"Kelly Criterion Probability Value", "0.228"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "85.095"},
|
||||
{"Portfolio Turnover", "0.747"},
|
||||
{"Total Insights Generated", "100"},
|
||||
{"Total Insights Closed", "99"},
|
||||
{"Total Insights Analysis Completed", "99"},
|
||||
{"Long Insight Count", "100"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-1.183"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "₹6.00"},
|
||||
{"Estimated Strategy Capacity", "₹61000000000.00"},
|
||||
{"Lowest Capacity Asset", "YESBANK UL"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-0.247"},
|
||||
{"Return Over Maximum Drawdown", "-1.104"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "$135639.1761"},
|
||||
{"Total Accumulated Estimated Alpha Value", "$21852.9784"},
|
||||
{"Mean Population Estimated Insight Value", "$220.7372"},
|
||||
{"Mean Population Direction", "53.5354%"},
|
||||
{"Mean Population Magnitude", "53.5354%"},
|
||||
{"Rolling Averaged Population Direction", "58.2788%"},
|
||||
{"Rolling Averaged Population Magnitude", "58.2788%"},
|
||||
{"OrderListHash", "ad2216297c759d8e5aef48ff065f8919"}
|
||||
{"Estimated Monthly Alpha Value", "₹0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "₹0"},
|
||||
{"Mean Population Estimated Insight Value", "₹0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6cc69218edd7bd461678b9ee0c575db5"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
168
Algorithm.CSharp/BasicTemplateIndiaIndexAlgorithm.cs
Normal file
168
Algorithm.CSharp/BasicTemplateIndiaIndexAlgorithm.cs
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Indicators;
|
||||
using QuantConnect.Interfaces;
|
||||
using QuantConnect.Orders;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// This example demonstrates how to add index asset types.
|
||||
/// </summary>
|
||||
/// <meta name="tag" content="using data" />
|
||||
/// <meta name="tag" content="benchmarks" />
|
||||
/// <meta name="tag" content="indexes" />
|
||||
public class BasicTemplateIndiaIndexAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition
|
||||
{
|
||||
protected Symbol Nifty;
|
||||
protected Symbol NiftyETF;
|
||||
private ExponentialMovingAverage _emaSlow;
|
||||
private ExponentialMovingAverage _emaFast;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize your algorithm and add desired assets.
|
||||
/// </summary>
|
||||
public override void Initialize()
|
||||
{
|
||||
SetAccountCurrency("INR"); //Set Account Currency
|
||||
SetStartDate(2019, 1, 1); //Set End Date
|
||||
SetEndDate(2019, 1, 5); //Set End Date
|
||||
SetCash(1000000); //Set Strategy Cash
|
||||
|
||||
// Use indicator for signal; but it cannot be traded
|
||||
Nifty = AddIndex("NIFTY50", Resolution.Minute, Market.India).Symbol;
|
||||
|
||||
//Trade Index based ETF
|
||||
NiftyETF = AddEquity("JUNIORBEES", Resolution.Minute, Market.India).Symbol;
|
||||
|
||||
//Set Order Properties as per the requirements for order placement
|
||||
DefaultOrderProperties = new IndiaOrderProperties(exchange: Exchange.NSE);
|
||||
|
||||
_emaSlow = EMA(Nifty, 80);
|
||||
_emaFast = EMA(Nifty, 200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Index EMA Cross trading underlying.
|
||||
/// </summary>
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (!slice.Bars.ContainsKey(Nifty) || !slice.Bars.ContainsKey(NiftyETF))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Warm up indicators
|
||||
if (!_emaSlow.IsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_emaFast > _emaSlow)
|
||||
{
|
||||
if (!Portfolio.Invested)
|
||||
{
|
||||
var marketTicket = MarketOrder(NiftyETF, 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Liquidate();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEndOfAlgorithm()
|
||||
{
|
||||
if (Portfolio[Nifty].TotalSaleVolume > 0)
|
||||
{
|
||||
throw new Exception("Index is not tradable.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.
|
||||
/// </summary>
|
||||
public virtual 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 Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 2882;
|
||||
|
||||
/// <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 virtual Dictionary<string, string> ExpectedStatistics => new Dictionary<string, string>
|
||||
{
|
||||
{"Total Trades", "6"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0.00%"},
|
||||
{"Compounding Annual Return", "-0.395%"},
|
||||
{"Drawdown", "0.000%"},
|
||||
{"Expectancy", "-1"},
|
||||
{"Net Profit", "-0.004%"},
|
||||
{"Sharpe Ratio", "-23.595"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "100%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "-23.595"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "₹36.00"},
|
||||
{"Estimated Strategy Capacity", "₹74000.00"},
|
||||
{"Lowest Capacity Asset", "JUNIORBEES UL"},
|
||||
{"Fitness Score", "0"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "-29.6"},
|
||||
{"Return Over Maximum Drawdown", "-123.624"},
|
||||
{"Portfolio Turnover", "0"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "₹0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "₹0"},
|
||||
{"Mean Population Estimated Insight Value", "₹0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "4637f26543287548b28a3c296db055d3"}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <meta name="tag" content="trading and orders" />
|
||||
public class BasicTemplateIntrinioEconomicData : QCAlgorithm
|
||||
{
|
||||
// Set your Intrinino user and password.
|
||||
// Set your Intrinio user and password.
|
||||
public string _user = "";
|
||||
public string _password = "";
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
SetEndDate(year: 2013, month: 12, day: 31); //Set End Date
|
||||
SetCash(startingCash: 100000); //Set Strategy Cash
|
||||
|
||||
// Set your Intrinino user and password.
|
||||
// Set your Intrinio user and password.
|
||||
IntrinioConfig.SetUserAndPassword(_user, _password);
|
||||
|
||||
// Set Intrinio config to make 1 call each minute, default is 1 call each 5 seconds.
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
@@ -99,6 +99,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 884208;
|
||||
|
||||
/// <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>
|
||||
@@ -123,7 +133,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "$10.00"},
|
||||
{"Total Fees", "$7.50"},
|
||||
{"Estimated Strategy Capacity", "$84000.00"},
|
||||
{"Lowest Capacity Asset", "GOOCV W78ZERHAOVVQ|GOOCV VP83T1ZUHROL"},
|
||||
{"Fitness Score", "0"},
|
||||
@@ -145,7 +155,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "82c29cc9db9a300074d6ff136253f4ac"}
|
||||
{"OrderListHash", "92610619a10e30863020cc84aa30be3b"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
@@ -109,6 +109,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 884616;
|
||||
|
||||
/// <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>
|
||||
@@ -155,7 +165,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "6a88f302b7f29a2c59e4b1e978161da1"}
|
||||
{"OrderListHash", "c9e110f2122451dabefcfe24287cadcf"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
@@ -106,6 +106,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 884197;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
var contractsByExpiration = chain.Where(x => x.Expiry != Time.Date).OrderBy(x => x.Expiry);
|
||||
var contract = contractsByExpiration.FirstOrDefault();
|
||||
|
||||
if (contract != null)
|
||||
if (contract != null && IsMarketOpen(contract.Symbol))
|
||||
{
|
||||
// if found, trade it
|
||||
MarketOrder(contract.Symbol, 1);
|
||||
@@ -81,14 +81,14 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
Log(orderEvent.ToString());
|
||||
|
||||
// Check for our expected OTM option expiry
|
||||
if (orderEvent.Message == "OTM")
|
||||
if (orderEvent.Message.Contains("OTM", StringComparison.InvariantCulture))
|
||||
{
|
||||
// Assert it is at midnight (5AM UTC)
|
||||
if (orderEvent.UtcTime != new DateTime(2016, 1, 16, 5, 0, 0))
|
||||
@@ -119,6 +119,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 39654;
|
||||
|
||||
/// <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>
|
||||
@@ -165,7 +175,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "c6d089f1fb86379c74a7413a9c2f8553"}
|
||||
{"OrderListHash", "0b52bbe98ade8e3aab943e64fcf4abfe"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 1722373;
|
||||
|
||||
/// <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>
|
||||
@@ -143,7 +153,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "452e7a36e0a95e33d3457a908add3ead"}
|
||||
{"OrderListHash", "0f8537495f5744c02191656d6b3f9205"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 990979;
|
||||
|
||||
/// <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>
|
||||
@@ -182,7 +192,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "50.0482%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "87603bd45898dd9c456745fa51f989a5"}
|
||||
{"OrderListHash", "83c9fb13ee32284702779eff8d11c608"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
.ThenByDescending(x => x.Right)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (atmContract != null)
|
||||
if (atmContract != null && IsMarketOpen(atmContract.Symbol))
|
||||
{
|
||||
// if found, trade it
|
||||
MarketOrder(atmContract.Symbol, 1);
|
||||
@@ -89,7 +89,7 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// <summary>
|
||||
/// Order fill event handler. On an order fill update the resulting information is passed to this method.
|
||||
/// </summary>
|
||||
/// <param name="orderEvent">Order event details containing details of the evemts</param>
|
||||
/// <param name="orderEvent">Order event details containing details of the events</param>
|
||||
/// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
|
||||
public override void OnOrderEvent(OrderEvent orderEvent)
|
||||
{
|
||||
@@ -106,6 +106,16 @@ namespace QuantConnect.Algorithm.CSharp
|
||||
/// </summary>
|
||||
public Language[] Languages { get; } = { Language.CSharp, Language.Python };
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public long DataPoints => 32492;
|
||||
|
||||
/// <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>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -28,7 +28,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2000, 01, 01);
|
||||
SetEndDate(2017, 01, 01);
|
||||
SetEndDate(2022, 01, 01);
|
||||
SetBenchmark(dt => 1m);
|
||||
AddEquity("SPY");
|
||||
}
|
||||
@@ -42,4 +42,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -34,7 +34,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
UniverseSettings.Resolution = Resolution.Minute;
|
||||
|
||||
SetStartDate(2017, 11, 01);
|
||||
SetEndDate(2018, 01, 01);
|
||||
SetEndDate(2018, 3, 01);
|
||||
SetCash(50000);
|
||||
|
||||
AddUniverse(CoarseSelectionFunction, FineSelectionFunction);
|
||||
@@ -98,4 +98,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
_changes = changes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using QuantConnect.Data;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
/// <summary>
|
||||
/// Benchmark Algorithm: Loading and synchronization of 500 equity minute symbols and their options.
|
||||
/// </summary>
|
||||
public class EmptyEquityAndOptions400Benchmark : QCAlgorithm
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2022, 5, 11);
|
||||
SetEndDate(2022, 5, 12);
|
||||
|
||||
var equity_symbols = new[] {
|
||||
|
||||
"MARK", "TSN", "DT", "RDW", "CVE", "NXPI", "FIVN", "CLX", "SPXL", "BKSY", "NUGT", "CF", "NEGG",
|
||||
"RH", "SIRI", "ITUB", "CSX", "AUR", "LIDR", "CMPS", "DHI", "GLW", "NTES", "CIFR", "S", "HSBC",
|
||||
"HIPO", "WTRH", "AMRN", "BIIB", "RIO", "EDIT", "TEAM", "CNK", "BUD", "MILE", "AEHR", "DOCN",
|
||||
"CLSK", "BROS", "MLCO", "SBLK", "ICLN", "OPK", "CNC", "SKX", "SESN", "VRM", "ASML", "BBAI",
|
||||
"HON", "MRIN", "BLMN", "NTNX", "POWW", "FOUR", "HOG", "GOGO", "MGNI", "GENI", "XPDI",
|
||||
"DG", "PSX", "RRC", "CORT", "MET", "UMC", "INMD", "RBAC", "ISRG", "BOX", "DVAX", "CRVS", "HLT",
|
||||
"BKNG", "BENE", "CLVS", "ESSC", "PTRA", "BE", "FPAC", "YETI", "DOCS", "DB", "EBON", "RDS.B",
|
||||
"ERIC", "BSIG", "INTU", "MNTS", "BCTX", "BLU", "FIS", "MAC", "WMB", "TTWO", "ARDX", "SWBI",
|
||||
"ELY", "INDA", "REAL", "ACI", "APRN", "BHP", "CPB", "SLQT", "ARKF", "TSP", "OKE", "NVTA", "META",
|
||||
"CSTM", "KMX", "IBB", "AGEN", "WOOF", "MJ", "HYZN", "RSI", "JCI", "EXC", "HPE", "SI", "WPM",
|
||||
"PRTY", "BBD", "FVRR", "CANO", "INDI", "MDLZ", "KOLD", "AMBA", "SOXS", "RSX", "ZEN", "PUBM",
|
||||
"VLDR", "CI", "ISEE", "GEO", "BKR", "DHR", "GRPN", "NRXP", "ACN", "MAT", "BODY", "ENDP",
|
||||
"SHPW", "AVIR", "GPN", "BILL", "BZ", "CERN", "ARVL", "DNMR", "NTR", "FSM", "BMBL", "PAAS",
|
||||
"INVZ", "ANF", "CL", "XP", "CS", "KD", "WW", "AHT", "GRTX", "XLC", "BLDP", "HTA", "APT", "BYSI",
|
||||
"ENB", "TRIT", "VTNR", "AVCT", "SLI", "CP", "CAH", "ALLY", "FIGS", "PXD", "TPX", "ZI", "BKLN", "SKIN",
|
||||
"LNG", "NU", "CX", "GSM", "NXE", "REI", "MNDT", "IP", "BLOK", "IAA", "TIP", "MCHP", "EVTL", "BIGC",
|
||||
"IGV", "LOTZ", "EWC", "DRI", "PSTG", "APLS", "KIND", "BBIO", "APPH", "FIVE", "LSPD", "SHAK",
|
||||
"COMM", "NAT", "VFC", "AMT", "VRTX", "RGS", "DD", "GBIL", "LICY", "ACHR", "FLR", "HGEN", "TECL",
|
||||
"SEAC", "NVS", "NTAP", "ML", "SBSW", "XRX", "UA", "NNOX", "SFT", "FE", "APP", "KEY", "CDEV",
|
||||
"DPZ", "BARK", "SPR", "CNQ", "XL", "AXSM", "ECH", "RNG", "AMLP", "ENG", "BTI", "REKR",
|
||||
"STZ", "BK", "HEAR", "LEV", "SKT", "HBI", "ALB", "CAG", "MNKD", "NMM", "BIRD", "CIEN", "SILJ",
|
||||
"STNG", "GUSH", "GIS", "PRPL", "SDOW", "GNRC", "ERX", "GES", "CPE", "FBRX", "WM", "ESTC",
|
||||
"GOED", "STLD", "LILM", "JNK", "BOIL", "ALZN", "IRBT", "KOPN", "AU", "TPR", "RWLK", "TROX",
|
||||
"TMO", "AVDL", "XSPA", "JKS", "PACB", "LOGI", "BLK", "REGN", "CFVI", "EGHT", "ATNF", "PRU",
|
||||
"URBN", "KMB", "SIX", "CME", "ENVX", "NVTS", "CELH", "CSIQ", "GSL", "PAA", "WU", "MOMO",
|
||||
"TOL", "WEN", "GTE", "EXAS", "GDRX", "PVH", "BFLY", "SRTY", "UDOW", "NCR", "ALTO", "CRTD",
|
||||
"GOCO", "ALK", "TTM", "DFS", "VFF", "ANTM", "FREY", "WY", "ACWI", "PNC", "SYY", "SNY", "CRK",
|
||||
"SO", "XXII", "PBF", "AER", "RKLY", "SOL", "CND", "MPLX", "JNPR", "FTCV", "CLR", "XHB", "YY",
|
||||
"POSH", "HIMS", "LIFE", "XENE", "ADM", "ROST", "MIR", "NRG", "AAP", "SSYS", "KBH", "KKR", "PLAN",
|
||||
"DUK", "WIMI", "DBRG", "WSM", "LTHM", "OVV", "CFLT", "EWT", "UNFI", "TX", "EMR", "IMGN", "K",
|
||||
"ONON", "UNIT", "LEVI", "ADTX", "UPWK", "DBA", "VOO", "FATH", "URI", "MPW", "JNUG", "RDFN",
|
||||
"OSCR", "WOLF", "SYF", "GOGL", "HES", "PHM", "CWEB", "ALDX", "BTWN", "AFL", "PPL", "CIM"
|
||||
|
||||
};
|
||||
Settings.DataSubscriptionLimit = 1000000;
|
||||
SetWarmUp(TimeSpan.FromDays(1));
|
||||
foreach(var ticker in equity_symbols)
|
||||
{
|
||||
var option = AddOption(ticker);
|
||||
option.SetFilter(1, 7, 0, 90);
|
||||
}
|
||||
|
||||
AddEquity("SPY");
|
||||
}
|
||||
|
||||
public override void OnData(Slice slice)
|
||||
{
|
||||
if (IsWarmingUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Quit("The end!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -30,8 +30,8 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2015, 10, 1);
|
||||
SetEndDate(2015, 11, 15);
|
||||
SetStartDate(2015, 9, 1);
|
||||
SetEndDate(2015, 12, 1);
|
||||
foreach (var symbol in Symbols.Equity.All.Take(400))
|
||||
{
|
||||
AddSecurity(SecurityType.Equity, symbol);
|
||||
@@ -402,4 +402,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -27,7 +27,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2008, 01, 01);
|
||||
SetEndDate(2009, 01, 01);
|
||||
SetEndDate(2008, 06, 01);
|
||||
SetBenchmark(dt => 1m);
|
||||
AddEquity("SPY", Resolution.Second);
|
||||
}
|
||||
@@ -36,4 +36,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -23,7 +23,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2010, 01, 01);
|
||||
SetEndDate(2018, 01, 01);
|
||||
SetEndDate(2022, 01, 01);
|
||||
SetCash(10000);
|
||||
_symbol = AddEquity("SPY").Symbol;
|
||||
}
|
||||
@@ -38,4 +38,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
var dailyOpen = dailyHistory.Open;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -32,7 +32,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2010, 01, 01);
|
||||
SetEndDate(2018, 01, 01);
|
||||
SetEndDate(2022, 01, 01);
|
||||
|
||||
AddSecurity(SecurityType.Equity, "SPY", Resolution.Minute);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
// define an indicator that takes the output of the sma and pipes it into our delay indicator
|
||||
var delayedSma = delay.Of(sma);
|
||||
|
||||
// register our new 'delayedSma' for automaic updates on a daily resolution
|
||||
// register our new 'delayedSma' for automatic updates on a daily resolution
|
||||
RegisterIndicator(_spy, delayedSma, Resolution.Daily, data => data.Value);
|
||||
|
||||
return delayedSma;
|
||||
@@ -68,4 +68,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
@@ -24,7 +24,7 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void Initialize()
|
||||
{
|
||||
SetStartDate(2011, 1, 1);
|
||||
SetEndDate(2018, 1, 1);
|
||||
SetEndDate(2022, 1, 1);
|
||||
SetCash(100000);
|
||||
AddEquity("SPY");
|
||||
foreach (int period in Enumerable.Range(0, 300))
|
||||
@@ -37,4 +37,4 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
public override void OnData(Slice data) { }
|
||||
private void Rebalance() { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -29,8 +29,8 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
SetStartDate(2017, 11, 01);
|
||||
SetEndDate(2018, 01, 01);
|
||||
SetStartDate(2017, 1, 01);
|
||||
SetEndDate(2019, 1, 01);
|
||||
SetCash(50000);
|
||||
|
||||
AddUniverse(CoarseSelectionFunction);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
|
||||
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
|
||||
*
|
||||
@@ -27,8 +27,8 @@ namespace QuantConnect.Algorithm.CSharp.Benchmarks
|
||||
{
|
||||
UniverseSettings.Resolution = Resolution.Daily;
|
||||
|
||||
SetStartDate(2017, 11, 01);
|
||||
SetEndDate(2018, 01, 01);
|
||||
SetStartDate(2017, 1, 01);
|
||||
SetEndDate(2019, 1, 01);
|
||||
SetCash(50000);
|
||||
|
||||
AddUniverse(CoarseSelectionFunction);
|
||||
|
||||
100
Algorithm.CSharp/BinanceCashAccountFeeRegressionAlgorithm.cs
Normal file
100
Algorithm.CSharp/BinanceCashAccountFeeRegressionAlgorithm.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.Brokerages;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Algorithm.CSharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Binance cash account regression algorithm, reproduces issue https://github.com/QuantConnect/Lean/issues/6123
|
||||
/// </summary>
|
||||
public class BinanceCashAccountFeeRegressionAlgorithm : CryptoBaseCurrencyFeeRegressionAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// The target account type
|
||||
/// </summary>
|
||||
protected override AccountType AccountType { get; } = AccountType.Cash;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
SetAccountCurrency("USDT");
|
||||
SetStartDate(2018, 05, 02);
|
||||
SetEndDate(2018, 05, 03);
|
||||
BrokerageName = BrokerageName.Binance;
|
||||
Pair = "BTCUSDT";
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of all timeslices of algorithm
|
||||
/// </summary>
|
||||
public override long DataPoints => 50;
|
||||
|
||||
/// <summary>
|
||||
/// Data Points count of the algorithm history
|
||||
/// </summary>
|
||||
public override int AlgorithmHistoryDataPoints => 28;
|
||||
|
||||
/// <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()
|
||||
{
|
||||
{"Total Trades", "49"},
|
||||
{"Average Win", "0%"},
|
||||
{"Average Loss", "0%"},
|
||||
{"Compounding Annual Return", "0%"},
|
||||
{"Drawdown", "0%"},
|
||||
{"Expectancy", "0"},
|
||||
{"Net Profit", "0%"},
|
||||
{"Sharpe Ratio", "0"},
|
||||
{"Probabilistic Sharpe Ratio", "0%"},
|
||||
{"Loss Rate", "0%"},
|
||||
{"Win Rate", "0%"},
|
||||
{"Profit-Loss Ratio", "0"},
|
||||
{"Alpha", "0"},
|
||||
{"Beta", "0"},
|
||||
{"Annual Standard Deviation", "0"},
|
||||
{"Annual Variance", "0"},
|
||||
{"Information Ratio", "0"},
|
||||
{"Tracking Error", "0"},
|
||||
{"Treynor Ratio", "0"},
|
||||
{"Total Fees", "₮45.62"},
|
||||
{"Estimated Strategy Capacity", "₮220000.00"},
|
||||
{"Lowest Capacity Asset", "BTCUSDT 18N"},
|
||||
{"Fitness Score", "0.208"},
|
||||
{"Kelly Criterion Estimate", "0"},
|
||||
{"Kelly Criterion Probability Value", "0"},
|
||||
{"Sortino Ratio", "79228162514264337593543950335"},
|
||||
{"Return Over Maximum Drawdown", "26.189"},
|
||||
{"Portfolio Turnover", "0.208"},
|
||||
{"Total Insights Generated", "0"},
|
||||
{"Total Insights Closed", "0"},
|
||||
{"Total Insights Analysis Completed", "0"},
|
||||
{"Long Insight Count", "0"},
|
||||
{"Short Insight Count", "0"},
|
||||
{"Long/Short Ratio", "100%"},
|
||||
{"Estimated Monthly Alpha Value", "₮0"},
|
||||
{"Total Accumulated Estimated Alpha Value", "₮0"},
|
||||
{"Mean Population Estimated Insight Value", "₮0"},
|
||||
{"Mean Population Direction", "0%"},
|
||||
{"Mean Population Magnitude", "0%"},
|
||||
{"Rolling Averaged Population Direction", "0%"},
|
||||
{"Rolling Averaged Population Magnitude", "0%"},
|
||||
{"OrderListHash", "7417649395922ff3791471b4f3b5c021"}
|
||||
};
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user