Skip to content

Commit

Permalink
Adds QuantBook Support/Example (#22)
Browse files Browse the repository at this point in the history
* Adds QuantBook Support/Example

* Fixes GitHub CI Space
  • Loading branch information
AlexCatarino committed Nov 28, 2023
1 parent 8c138b4 commit 37b7611
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ on:
jobs:
build:
runs-on: ubuntu-20.04
container:
image: quantconnect/lean:foundation

steps:
- uses: actions/checkout@v2

- name: Free space
run: df -h && rm -rf /opt/hostedtoolcache* && df -h

- name: Pull Foundation Image
uses: addnab/docker-run-action@v3
with:
image: quantconnect/lean:foundation

- name: Checkout Lean Same Branch
id: lean-same-branch
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions DataProcessing/DataProcessing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="QuantConnect.Lean.Engine" Version="2.5.*"/>
<PackageReference Include="QuantConnect.Research" Version="2.5.*"/>
<PackageReference Include="QuantConnect.Messaging" Version="2.5.*"/>
<PackageReference Include="QuantConnect.pythonnet" Version="2.0.*" />
<PackageReference Include="fasterflect" Version="3.0.0" />
</ItemGroup>
Expand Down
46 changes: 41 additions & 5 deletions DataProcessing/process.sample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,61 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "9b8eae46",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# CLRImports is required to handle Lean C# objects for Mapped Datasets (Single asset and Universe Selection)\n",
"# Requirements:\n",
"# python -m pip install clr-loader==0.1.7\n",
"# python -m pip install pythonnet==3.0.0a2\n",
"# This script must be executed in ./bin/Debug/net6.0 after the follwing command is executed\n",
"# dotnet build .\\DataProcessing\\\n",
"import os\n",
"from CLRImports import *\n",
"\n",
"# To use QuantBook, we need to set its internal handlers\n",
"# We download LEAN confif with the default settings \n",
"with open(\"quantbook.json\", 'w') as fp:\n",
" from requests import get\n",
" response = get(\"https://raw.githubusercontent.com/QuantConnect/Lean/master/Launcher/config.json\")\n",
" fp.write(response.text)\n",
"\n",
"Config.SetConfigurationFile(\"quantbook.json\")\n",
"Config.Set(\"composer-dll-directory\", os.path.abspath(''))\n",
"\n",
"# Set the data folder\n",
"Config.Set(\"data-folder\", '<path-to-data-folder>')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ddc2ed2-5690-422c-8c91-6e6f64dd45cb",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# To generate the Security Identifier, we need to create and initialize the Map File Provider\n",
"# and call the SecurityIdentifier.GenerateEquity method\n",
"mapFileProvider = LocalZipMapFileProvider()\n",
"mapFileProvider.Initialize(DefaultDataProvider())\n",
"sid = SecurityIdentifier.GenerateEquity(\"BAC\", Market.USA, True, mapFileProvider, datetime(2022, 3, 1))"
"sid = SecurityIdentifier.GenerateEquity(\"SPY\", Market.USA, True, mapFileProvider, datetime(2022, 3, 1))\n",
"\n",
"qb = QuantBook()\n",
"symbol = Symbol(sid, \"SPY\")\n",
"history = qb.History(symbol, 3600, Resolution.Daily)\n",
"print(history)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -34,7 +70,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.13"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down
26 changes: 25 additions & 1 deletion DataProcessing/process.sample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
# CLRImports is required to handle Lean C# objects for Mapped Datasets (Single asset and Universe Selection)
# Requirements:
# python -m pip install clr-loader==0.1.7
# python -m pip install pythonnet==3.0.0a2
# This script must be executed in ./bin/Debug/net6.0 after the follwing command is executed
# dotnet build .\DataProcessing\
import os
from CLRImports import *

# To use QuantBook, we need to set its internal handlers
# We download LEAN confif with the default settings
with open("quantbook.json", 'w') as fp:
from requests import get
response = get("https://raw.githubusercontent.com/QuantConnect/Lean/master/Launcher/config.json")
fp.write(response.text)

Config.SetConfigurationFile("quantbook.json")
Config.Set("composer-dll-directory", os.path.dirname(os.path.realpath(__file__)))

# Set the data folder
Config.Set("data-folder", '<path-to-data-folder>')

# To generate the Security Identifier, we need to create and initialize the Map File Provider
# and call the SecurityIdentifier.GenerateEquity method
mapFileProvider = LocalZipMapFileProvider()
mapFileProvider.Initialize(DefaultDataProvider())
sid = SecurityIdentifier.GenerateEquity("BAC", Market.USA, True, mapFileProvider, datetime(2022, 3, 1))
sid = SecurityIdentifier.GenerateEquity("SPY", Market.USA, True, mapFileProvider, datetime(2022, 3, 1))

qb = QuantBook()
symbol = Symbol(sid, "SPY")
history = qb.History(symbol, 3600, Resolution.Daily)
print(history)

0 comments on commit 37b7611

Please sign in to comment.