chore: import upstream snapshot with attribution
This commit is contained in:
+137
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
|
||||
namespace QuantConnect.Tests.Research.RegressionTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template framework for regression testing of research notebooks
|
||||
/// </summary>
|
||||
public class BasicTemplateCustomDataTypeHistoryResearchCSharp : IRegressionResearchDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected output from the reading the raw notebook file
|
||||
/// </summary>
|
||||
/// <remarks>Requires to be implemented last in the file <see cref="ResearchRegressionTests.UpdateResearchRegressionOutputInSourceFile"/>
|
||||
/// get should start from next line</remarks>
|
||||
public string ExpectedOutput =>
|
||||
"{ \"cells\": [ { \"cell_type\": \"markdown\", \"id\": \"c5f3ed6d\", \"metadata\": { \"papermill\": { \"duration\": 0.003499, \"end_t" +
|
||||
"ime\": \"2023-02-17T23:37:52.736173\", \"exception\": false, \"start_time\": \"2023-02-17T23:37:52.732674\", \"status\": \"completed\" " +
|
||||
"}, \"tags\": [] }, \"source\": [ \"\", \"<hr>\" ] }, { \"cell_type" +
|
||||
"\": \"markdown\", \"id\": \"2025ecbd\", \"metadata\": { \"papermill\": { \"duration\": 0.002997, \"end_time\": \"2023-02-17T23:37:52.74" +
|
||||
"1673\", \"exception\": false, \"start_time\": \"2023-02-17T23:37:52.738676\", \"status\": \"completed\" }, \"tags\": [] }, \"sou" +
|
||||
"rce\": [ \"# Custom data history\" ] }, { \"cell_type\": \"code\", \"execution_count\": 1, \"id\": \"bbc993a0\", \"metadata\": { \"e" +
|
||||
"xecution\": { \"iopub.execute_input\": \"2023-02-17T23:37:52.761679Z\", \"iopub.status.busy\": \"2023-02-17T23:37:52.753179Z\", \"iopub.st" +
|
||||
"atus.idle\": \"2023-02-17T23:38:01.186963Z\", \"shell.execute_reply\": \"2023-02-17T23:38:01.173466Z\" }, \"papermill\": { \"duration\":" +
|
||||
" 8.442283, \"end_time\": \"2023-02-17T23:38:01.187462\", \"exception\": false, \"start_time\": \"2023-02-17T23:37:52.745179\", \"statu" +
|
||||
"s\": \"completed\" }, \"tags\": [], \"vscode\": { \"languageId\": \"csharp\" } }, \"outputs\": [ { \"data\": { \"text/" +
|
||||
"html\": [ \"\", \"<div>\", \" <div id='dotnet-interactive-this-cell-122456.Microsoft.DotNet.Interactive.Http.HttpPort' style='dis" +
|
||||
"play: none'>\", \" The below script needs to be able to find the current output cell; this is an easy method to get it.\", \" </" +
|
||||
"div>\", \" <script type='text/javascript'>\", \"async function probeAddresses(probingAddresses) {\", \" function timeout(ms, p" +
|
||||
"romise) {\", \" return new Promise(function (resolve, reject) {\", \" setTimeout(function () {\", \" " +
|
||||
" reject(new Error('timeout'))\", \" }, ms)\", \" promise.then(resolve, reject)\", \" })\", \" " +
|
||||
" }\", \"\", \" if (Array.isArray(probingAddresses)) {\", \" for (let i = 0; i < probingAddresses.length; i++) {\", \"" +
|
||||
"\", \" let rootUrl = probingAddresses[i];\", \"\", \" if (!rootUrl.endsWith('/')) {\", \" " +
|
||||
" rootUrl = `${rootUrl}/`;\", \" }\", \"\", \" try {\", \" let response = await timeout(10" +
|
||||
"00, fetch(`${rootUrl}discovery`, {\", \" method: 'POST',\", \" cache: 'no-cache',\", \" " +
|
||||
" mode: 'cors',\", \" timeout: 1000,\", \" headers: {\", \" " +
|
||||
"'Content-Type': 'text/plain'\", \" },\", \" body: probingAddresses[i]\", \" }))" +
|
||||
";\", \"\", \" if (response.status == 200) {\", \" return rootUrl;\", \" }\", " +
|
||||
" \" }\", \" catch (e) { }\", \" }\", \" }\", \"}\", \"\", \"function loadDotn" +
|
||||
"etInteractiveApi() {\", \" probeAddresses([\\\"http://172.19.192.1:1000/\\\", \\\"http://192.168.56.1:1000/\\\", \\\"http://192.168.16.104:10" +
|
||||
"00/\\\", \\\"http://127.0.0.1:1000/\\\"])\", \" .then((root) => {\", \" // use probing to find host url and api resources\"," +
|
||||
" \" // load interactive helpers and language services\", \" let dotnetInteractiveRequire = require.config({\", \" " +
|
||||
" context: '122456.Microsoft.DotNet.Interactive.Http.HttpPort',\", \" paths:\", \" {\", \" " +
|
||||
" 'dotnet-interactive': `${root}resources`\", \" }\", \" }) || require;\", \"\", \" window.dot" +
|
||||
"netInteractiveRequire = dotnetInteractiveRequire;\", \"\", \" window.configureRequireFromExtension = function(extensionName, ex" +
|
||||
"tensionCacheBuster) {\", \" let paths = {};\", \" paths[extensionName] = `${root}extensions/${extensionName}" +
|
||||
"/resources/`;\", \" \", \" let internalRequire = require.config({\", \" context: ex" +
|
||||
"tensionCacheBuster,\", \" paths: paths,\", \" urlArgs: `cacheBuster=${extensionCacheBuster}`\", " +
|
||||
" \" }) || require;\", \"\", \" return internalRequire\", \" };\", \" \", " +
|
||||
" \" dotnetInteractiveRequire([\", \" 'dotnet-interactive/dotnet-interactive'\", \" ],\"," +
|
||||
" \" function (dotnet) {\", \" dotnet.init(window);\", \" },\", \" " +
|
||||
" function (error) {\", \" console.log(error);\", \" }\", \" );\", \" })" +
|
||||
"\", \" .catch(error => {console.log(error);});\", \" }\", \"\", \"// ensure `require` is available globally\", " +
|
||||
" \"if ((typeof(require) !== typeof(Function)) || (typeof(require.config) !== typeof(Function))) {\", \" let require_script = document.create" +
|
||||
"Element('script');\", \" require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\", " +
|
||||
" \" require_script.setAttribute('type', 'text/javascript');\", \" \", \" \", \" require_script.onload = function() {\"" +
|
||||
", \" loadDotnetInteractiveApi();\", \" };\", \"\", \" document.getElementsByTagName('head')[0].appendChild(requir" +
|
||||
"e_script);\", \"}\", \"else {\", \" loadDotnetInteractiveApi();\", \"}\", \"\", \" </script>\", \"</di" +
|
||||
"v>\" ] }, \"metadata\": {}, \"output_type\": \"display_data\" }, { \"name\": \"stdout\", \"output_type\": \"stream\", " +
|
||||
" \"text\": [ \"Initialize.csx: Loading assemblies from C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] } ], " +
|
||||
" \"source\": [ \"// We need to load assemblies at the start in their own cell\", \"#load \\\"./Initialize.csx\\\"\" ] }, { \"cell_type\":" +
|
||||
" \"code\", \"execution_count\": 2, \"id\": \"0f8ca7c8\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2023-02-17T23:38:01." +
|
||||
"204969Z\", \"iopub.status.busy\": \"2023-02-17T23:38:01.203966Z\", \"iopub.status.idle\": \"2023-02-17T23:38:01.720374Z\", \"shell.execute" +
|
||||
"_reply\": \"2023-02-17T23:38:01.718372Z\" }, \"papermill\": { \"duration\": 0.527908, \"end_time\": \"2023-02-17T23:38:01.720374\", " +
|
||||
"\"exception\": false, \"start_time\": \"2023-02-17T23:38:01.192466\", \"status\": \"completed\" }, \"tags\": [], \"vscode\": { \"" +
|
||||
"languageId\": \"csharp\" } }, \"outputs\": [ { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23" +
|
||||
":38:01.491 TRACE:: Config.GetValue(): debug-mode - Using default value: False\" ] }, { \"name\": \"stdout\", \"output_type\": \"stre" +
|
||||
"am\", \"text\": [ \"20230217 23:38:01.493 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default " +
|
||||
"value: \" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38:01.496 TRACE:: Config.Get(" +
|
||||
"): Configuration key not found. Key: plugin-directory - Using default value: \" ] }, { \"name\": \"stdout\", \"output_type\": \"stre" +
|
||||
"am\", \"text\": [ \"20230217 23:38:01.501 TRACE:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default valu" +
|
||||
"e: \" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38:01.502 TRACE:: Composer(): Loa" +
|
||||
"ding Assemblies from C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] }, { \"name\": \"stdout\", \"output_type\":" +
|
||||
" \"stream\", \"text\": [ \"20230217 23:38:01.587 TRAC" +
|
||||
"E:: Config.Get(): Configuration key not found. Key: version-id - Using default value: \" ] }, { \"name\": \"stdout\", \"output_type\"" +
|
||||
": \"stream\", \"text\": [ \"20230217 23:38:01.587 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default valu" +
|
||||
"e: ../../../Data/\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38:01.588 TRACE:: E" +
|
||||
"ngine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) Host: ABREU\" ] }, { \"name\": \"stdout\", \"output_type\"" +
|
||||
": \"stream\", \"text\": [ \"20230217 23:38:01.589 TRACE:: Engine.Main(): Started 7:38 PM\" ] }, { \"name\": \"stdout\", \"o" +
|
||||
"utput_type\": \"stream\", \"text\": [ \"20230217 23:38:01.597 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Usi" +
|
||||
"ng default value: LocalLeanManager\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38" +
|
||||
":01.619 TRACE:: Config.Get(): Configuration key not found. Key: data-permission-manager - Using default value: DataPermissionManager\" ] }, " +
|
||||
"{ \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38:01.623 TRACE:: Config.Get(): Configuration key not " +
|
||||
"found. Key: results-destination-folder - Using default value: C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] }, {" +
|
||||
" \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20230217 23:38:01.657 TRACE:: Config.Get(): Configuration key not f" +
|
||||
"ound. Key: object-store-root - Using default value: ./storage\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text" +
|
||||
"\": [ \"20230217 23:38:01.668 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: C:\\\\Use" +
|
||||
"rs\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] } ], \"source\": [ \"// Initialize Lean Engine.\", \"#load \\\"./Qua" +
|
||||
"ntConnect.csx\\\"\", \"\", \"using System.Globalization;\", \"using System.Linq;\", \"using QuantConnect;\", \"using QuantConnect.Data;" +
|
||||
"\", \"using QuantConnect.Algorithm;\", \"using QuantConnect.Research;\" ] }, { \"cell_type\": \"code\", \"execution_count\": 3, \"id\"" +
|
||||
": \"83870958\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2023-02-17T23:38:01.737374Z\", \"iopub.status.busy\": \"2023-" +
|
||||
"02-17T23:38:01.735874Z\", \"iopub.status.idle\": \"2023-02-17T23:38:02.793265Z\", \"shell.execute_reply\": \"2023-02-17T23:38:02.792263Z\" " +
|
||||
"}, \"papermill\": { \"duration\": 1.067389, \"end_time\": \"2023-02-17T23:38:02.793764\", \"exception\": false, \"start_time\": \"2" +
|
||||
"023-02-17T23:38:01.726375\", \"status\": \"completed\" }, \"tags\": [], \"vscode\": { \"languageId\": \"csharp\" } }, \"output" +
|
||||
"s\": [], \"source\": [ \"class CustomDataType : DynamicData\", \"{\", \" public decimal Open;\", \" public decimal High;\", \" " +
|
||||
" public decimal Low;\", \" public decimal Close;\", \"\", \" public override SubscriptionDataSource GetSource(SubscriptionDataConfig " +
|
||||
"config, DateTime date, bool isLiveMode)\", \" {\", \" var source = \\\"https://www.dl.dropboxusercontent.com/s/d83xvd7mm9fzpk0/path_to" +
|
||||
"_my_csv_data.csv?dl=0\\\";\", \" return new SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);\", \" }\", \"\"" +
|
||||
", \" public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)\", \" {\", \" i" +
|
||||
"f (string.IsNullOrWhiteSpace(line.Trim()))\", \" {\", \" return null;\", \" }\", \"\", \" try\", \" " +
|
||||
" {\", \" var csv = line.Split(\\\",\\\");\", \" var data = new CustomDataType()\", \" {\", \" " +
|
||||
" Symbol = config.Symbol,\", \" Time = DateTime.ParseExact(csv[0], DateFormat.DB, CultureInfo.InvariantCulture).AddHours(20)" +
|
||||
",\", \" Value = csv[4].ToDecimal(),\", \" Open = csv[1].ToDecimal(),\", \" High = csv[2].ToDecim" +
|
||||
"al(),\", \" Low = csv[3].ToDecimal(),\", \" Close = csv[4].ToDecimal()\", \" };\", \"\", \" " +
|
||||
" return data;\", \" }\", \" catch\", \" {\", \" return null;\", \" }\", \" }\", " +
|
||||
" \"}\" ] }, { \"cell_type\": \"code\", \"execution_count\": 4, \"id\": \"ed9ea0a3\", \"metadata\": { \"execution\": { \"iopub.execu" +
|
||||
"te_input\": \"2023-02-17T23:38:02.815268Z\", \"iopub.status.busy\": \"2023-02-17T23:38:02.814265Z\", \"iopub.status.idle\": \"2023-02-17T23:38" +
|
||||
":10.436355Z\", \"shell.execute_reply\": \"2023-02-17T23:38:10.435324Z\" }, \"papermill\": { \"duration\": 7.633591, \"end_time\": \"" +
|
||||
"2023-02-17T23:38:10.436355\", \"exception\": false, \"start_time\": \"2023-02-17T23:38:02.802764\", \"status\": \"completed\" }, \"t" +
|
||||
"ags\": [], \"vscode\": { \"languageId\": \"csharp\" } }, \"outputs\": [ { \"name\": \"stdout\", \"output_type\": \"stream\", " +
|
||||
" \"text\": [ \"PythonEngine.Initialize(): clr GetManifestResourceStream...\" ] } ], \"source\": [ \"var qb = new QuantBook();\"," +
|
||||
" \"var symbol = qb.AddData<CustomDataType>(\\\"CustomDataType\\\", Resolution.Hour).Symbol;\", \"\", \"var start = new DateTime(2017, 8, 20);" +
|
||||
"\", \"var end = start.AddHours(48);\", \"var history = qb.History<CustomDataType>(symbol, start, end, Resolution.Hour).ToList();\", \"\", " +
|
||||
"\"if (history.Count == 0)\", \"{\", \" throw new Exception(\\\"No history data returned\\\");\", \"}\" ] } ], \"metadata\": { \"kernel" +
|
||||
"spec\": { \"display_name\": \".NET (C#)\", \"language\": \"C#\", \"name\": \".net-csharp\" }, \"language_info\": { \"file_extension\": \".cs" +
|
||||
"\", \"mimetype\": \"text/x-csharp\", \"name\": \"C#\", \"pygments_lexer\": \"csharp\", \"version\": \"10.0\" }, \"papermill\": { \"default" +
|
||||
"_parameters\": {}, \"duration\": 25.341314, \"end_time\": \"2023-02-17T23:38:13.053129\", \"environment_variables\": {}, \"exception\": null, " +
|
||||
" \"input_path\": \"C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\\\\Research\\\\RegressionTemplates\\\\BasicTemplateCustomDat" +
|
||||
"aTypeHistoryResearchCSharp.ipynb\", \"output_path\": \"C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\\\\Research\\\\Regressi" +
|
||||
"onTemplates\\\\BasicTemplateCustomDataTypeHistoryResearchCSharp-output.ipynb\", \"parameters\": {}, \"start_time\": \"2023-02-17T23:37:47.711815\"" +
|
||||
", \"version\": \"2.4.0\" } }, \"nbformat\": 4, \"nbformat_minor\": 5}";
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [ "\n", "<hr>" ]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [ "# Custom data history" ]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": { "vscode": { "languageId": "csharp" } },
|
||||
"outputs": [],
|
||||
"source": [ "// We need to load assemblies at the start in their own cell\n", "#load \"./Initialize.csx\"" ]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": { "vscode": { "languageId": "csharp" } },
|
||||
"outputs": [],
|
||||
"source": [ "// Initialize Lean Engine.\n", "#load \"./QuantConnect.csx\"\n", "\n", "using System.Globalization;\n", "using System.Linq;\n", "using QuantConnect;\n", "using QuantConnect.Data;\n", "using QuantConnect.Algorithm;\n", "using QuantConnect.Research;" ]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": { "vscode": { "languageId": "csharp" } },
|
||||
"outputs": [],
|
||||
"source": [ "class CustomDataType : DynamicData\n", "{\n", " public decimal Open;\n", " public decimal High;\n", " public decimal Low;\n", " public decimal Close;\n", "\n", " public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)\n", " {\n", " var source = \"https://www.dl.dropboxusercontent.com/s/d83xvd7mm9fzpk0/path_to_my_csv_data.csv?dl=0\";\n", " return new SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);\n", " }\n", "\n", " public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)\n", " {\n", " if (string.IsNullOrWhiteSpace(line.Trim()))\n", " {\n", " return null;\n", " }\n", "\n", " try\n", " {\n", " var csv = line.Split(\",\");\n", " var data = new CustomDataType()\n", " {\n", " Symbol = config.Symbol,\n", " Time = DateTime.ParseExact(csv[0], DateFormat.DB, CultureInfo.InvariantCulture).AddHours(20),\n", " Value = csv[4].ToDecimal(),\n", " Open = csv[1].ToDecimal(),\n", " High = csv[2].ToDecimal(),\n", " Low = csv[3].ToDecimal(),\n", " Close = csv[4].ToDecimal()\n", " };\n", "\n", " return data;\n", " }\n", " catch\n", " {\n", " return null;\n", " }\n", " }\n", "}" ]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": { "vscode": { "languageId": "csharp" } },
|
||||
"outputs": [],
|
||||
"source": [ "var qb = new QuantBook();\n", "var symbol = qb.AddData<CustomDataType>(\"CustomDataType\", Resolution.Hour).Symbol;\n", "\n", "var start = new DateTime(2017, 8, 20);\n", "var end = start.AddHours(48);\n", "var history = qb.History<CustomDataType>(symbol, start, end, Resolution.Hour).ToList();\n", "\n", "if (history.Count == 0)\n", "{\n", " throw new Exception(\"No history data returned\");\n", "}" ]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".NET (C#)",
|
||||
"language": "C#",
|
||||
"name": ".net-csharp"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".cs",
|
||||
"mimetype": "text/x-csharp",
|
||||
"name": "C#",
|
||||
"pygments_lexer": "csharp",
|
||||
"version": "9.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
|
||||
namespace QuantConnect.Tests.Research.RegressionTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template framework for regression testing of research notebooks
|
||||
/// </summary>
|
||||
public class BasicTemplateCustomDataTypeHistoryResearchPython : IRegressionResearchDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected output from the reading the raw notebook file
|
||||
/// </summary>
|
||||
/// <remarks>Requires to be implemented last in the file <see cref="ResearchRegressionTests.UpdateResearchRegressionOutputInSourceFile"/>
|
||||
/// get should start from next line</remarks>
|
||||
public string ExpectedOutput =>
|
||||
"{ \"cells\": [ { \"cell_type\": \"markdown\", \"id\": \"d0ea3064\", \"metadata\": { \"papermill\": { \"duration\": 0.003996, \"end_t" +
|
||||
"ime\": \"2023-02-17T21:33:10.586532\", \"exception\": false, \"start_time\": \"2023-02-17T21:33:10.582536\", \"status\": \"completed\" " +
|
||||
"}, \"tags\": [] }, \"source\": [ \"\", \"## Welcome to " +
|
||||
"The QuantConnect Research Page\", \"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\", \"#### Con" +
|
||||
"tribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb\" ] }, { \"cell_type\": \"m" +
|
||||
"arkdown\", \"id\": \"e3e3d0c7\", \"metadata\": { \"papermill\": { \"duration\": 0.003965, \"end_time\": \"2023-02-17T21:33:10.593525\"," +
|
||||
" \"exception\": false, \"start_time\": \"2023-02-17T21:33:10.589560\", \"status\": \"completed\" }, \"tags\": [] }, \"source\": " +
|
||||
"[ \"## QuantBook Basics\", \"\", \"### Start QuantBook\", \"- Add the references and imports\", \"- Create a QuantBook instance\" ] " +
|
||||
"}, { \"cell_type\": \"code\", \"execution_count\": 1, \"id\": \"d0e8fcfc\", \"metadata\": { \"execution\": { \"iopub.execute_input\": " +
|
||||
"\"2023-02-17T21:33:10.602549Z\", \"iopub.status.busy\": \"2023-02-17T21:33:10.601530Z\", \"iopub.status.idle\": \"2023-02-17T21:33:10.616522Z\"" +
|
||||
", \"shell.execute_reply\": \"2023-02-17T21:33:10.614535Z\" }, \"papermill\": { \"duration\": 0.021984, \"end_time\": \"2023-02-17T21" +
|
||||
":33:10.618527\", \"exception\": false, \"start_time\": \"2023-02-17T21:33:10.596543\", \"status\": \"completed\" }, \"tags\": [] }" +
|
||||
", \"outputs\": [], \"source\": [ \"import warnings\", \"warnings.filterwarnings(\\\"ignore\\\")\" ] }, { \"cell_type\": \"code\", \"" +
|
||||
"execution_count\": 2, \"id\": \"a845a7ca\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2023-02-17T21:33:10.627549Z\", " +
|
||||
"\"iopub.status.busy\": \"2023-02-17T21:33:10.627549Z\", \"iopub.status.idle\": \"2023-02-17T21:33:15.142098Z\", \"shell.execute_reply\": \"202" +
|
||||
"3-02-17T21:33:15.140599Z\" }, \"papermill\": { \"duration\": 4.526574, \"end_time\": \"2023-02-17T21:33:15.149104\", \"exception\": " +
|
||||
"false, \"start_time\": \"2023-02-17T21:33:10.622530\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [" +
|
||||
" \"# Load in our startup script, required to set runtime for PythonNet\", \"%run ./start.py\" ] }, { \"cell_type\": \"code\", \"executio" +
|
||||
"n_count\": 3, \"id\": \"9b0cd81c\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2023-02-17T21:33:15.162102Z\", \"iopub." +
|
||||
"status.busy\": \"2023-02-17T21:33:15.160599Z\", \"iopub.status.idle\": \"2023-02-17T21:33:15.266621Z\", \"shell.execute_reply\": \"2023-02-17T" +
|
||||
"21:33:15.263102Z\" }, \"papermill\": { \"duration\": 0.117533, \"end_time\": \"2023-02-17T21:33:15.270138\", \"exception\": false, " +
|
||||
" \"start_time\": \"2023-02-17T21:33:15.152605\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ \"cl" +
|
||||
"ass CustomDataType(PythonData):\", \"\", \" def GetSource(self, config: SubscriptionDataConfig, date: datetime, isLive: bool) -> Subscription" +
|
||||
"DataSource:\", \" source = \\\"https://www.dl.dropboxusercontent.com/s/d83xvd7mm9fzpk0/path_to_my_csv_data.csv?dl=0\\\"\", \" retu" +
|
||||
"rn SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)\", \"\", \" def Reader(self, config: SubscriptionDataConfig, line: " +
|
||||
"str, date: datetime, isLive: bool) -> BaseData:\", \" if not (line.strip()):\", \" return None\", \"\", \" data =" +
|
||||
" line.split(',')\", \" obj_data = CustomDataType()\", \" obj_data.Symbol = config.Symbol\", \"\", \" try:\", \" " +
|
||||
" obj_data.Time = datetime.strptime(data[0], '%Y-%m-%d %H:%M:%S') + timedelta(hours=20)\", \" obj_data[\\\"open\\\"] = float(data" +
|
||||
"[1])\", \" obj_data[\\\"high\\\"] = float(data[2])\", \" obj_data[\\\"low\\\"] = float(data[3])\", \" obj_da" +
|
||||
"ta[\\\"close\\\"] = float(data[4])\", \" obj_data.Value = obj_data[\\\"close\\\"]\", \"\", \" # property for asserting " +
|
||||
"the correct data is fetched\", \" obj_data[\\\"some_property\\\"] = \\\"some property value\\\"\", \" except ValueError:\", " +
|
||||
" \" return None\", \"\", \" return obj_data\", \"\", \" def __str__ (self):\", \" return f\\\"Time: {self.T" +
|
||||
"ime}, Value: {self.Value}, SomeProperty: {self['some_property']}, Open: {self['open']}, High: {self['high']}, Low: {self['low']}, Close: {self['close'" +
|
||||
"]}\\\"\" ] }, { \"cell_type\": \"code\", \"execution_count\": 4, \"id\": \"e21f2b04\", \"metadata\": { \"execution\": { \"iopub.exe" +
|
||||
"cute_input\": \"2023-02-17T21:33:15.282600Z\", \"iopub.status.busy\": \"2023-02-17T21:33:15.281102Z\", \"iopub.status.idle\": \"2023-02-17T21:" +
|
||||
"33:17.198103Z\", \"shell.execute_reply\": \"2023-02-17T21:33:17.196601Z\" }, \"papermill\": { \"duration\": 1.926991, \"end_time\": " +
|
||||
"\"2023-02-17T21:33:17.200100\", \"exception\": false, \"start_time\": \"2023-02-17T21:33:15.273109\", \"status\": \"completed\" }, \"" +
|
||||
"tags\": [] }, \"outputs\": [], \"source\": [ \"# Create an instance\", \"qb = QuantBook()\", \"symbol = qb.AddData(CustomDataType, \\\"" +
|
||||
"CustomDataType\\\", Resolution.Hour).Symbol\", \"\", \"startDate = datetime(2017, 8, 20)\", \"endDate = startDate + timedelta(hours=48)\", " +
|
||||
" \"history = list(qb.History[CustomDataType](symbol, startDate, endDate, Resolution.Hour))\", \"\", \"if len(history) == 0:\", \" raise Ex" +
|
||||
"ception(\\\"No history data returned\\\")\" ] } ], \"metadata\": { \"kernelspec\": { \"display_name\": \"Python 3 (ipykernel)\", \"language\":" +
|
||||
" \"python\", \"name\": \"python3\" }, \"language_info\": { \"codemirror_mode\": { \"name\": \"ipython\", \"version\": 3 }, \"file_exte" +
|
||||
"nsion\": \".py\", \"mimetype\": \"text/x-python\", \"name\": \"python\", \"nbconvert_exporter\": \"python\", \"pygments_lexer\": \"ipython3\"," +
|
||||
" \"version\": \"3.8.10\" }, \"papermill\": { \"default_parameters\": {}, \"duration\": 13.405899, \"end_time\": \"2023-02-17T21:33:20.058754" +
|
||||
"\", \"environment_variables\": {}, \"exception\": null, \"input_path\": \"C:\\\\Users\\\\jhona\\\\QuantConnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\\\\R" +
|
||||
"esearch\\\\RegressionTemplates\\\\BasicTemplateCustomDataTypeHistoryResearchPython.ipynb\", \"output_path\": \"C:\\\\Users\\\\jhona\\\\QuantConnect\\\\L" +
|
||||
"ean\\\\Tests\\\\bin\\\\Debug\\\\Research\\\\RegressionTemplates\\\\BasicTemplateCustomDataTypeHistoryResearchPython-output.ipynb\", \"parameters\": " +
|
||||
"{}, \"start_time\": \"2023-02-17T21:33:06.652855\", \"version\": \"2.4.0\" }, \"vscode\": { \"interpreter\": { \"hash\": \"9650cb4e16cdd4a8" +
|
||||
"e8e2d128bf38d875813998db22a3c986335f89e0cb4d7bb2\" } } }, \"nbformat\": 4, \"nbformat_minor\": 5}";
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"## Welcome to The QuantConnect Research Page\n",
|
||||
"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\n",
|
||||
"#### Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## QuantBook Basics\n",
|
||||
"\n",
|
||||
"### Start QuantBook\n",
|
||||
"- Add the references and imports\n",
|
||||
"- Create a QuantBook instance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import warnings\n",
|
||||
"warnings.filterwarnings(\"ignore\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load in our startup script, required to set runtime for PythonNet\n",
|
||||
"%run ./start.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class CustomDataType(PythonData):\n",
|
||||
"\n",
|
||||
" def GetSource(self, config: SubscriptionDataConfig, date: datetime, isLive: bool) -> SubscriptionDataSource:\n",
|
||||
" source = \"https://www.dl.dropboxusercontent.com/s/d83xvd7mm9fzpk0/path_to_my_csv_data.csv?dl=0\"\n",
|
||||
" return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile)\n",
|
||||
"\n",
|
||||
" def Reader(self, config: SubscriptionDataConfig, line: str, date: datetime, isLive: bool) -> BaseData:\n",
|
||||
" if not (line.strip()):\n",
|
||||
" return None\n",
|
||||
"\n",
|
||||
" data = line.split(',')\n",
|
||||
" obj_data = CustomDataType()\n",
|
||||
" obj_data.Symbol = config.Symbol\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" obj_data.Time = datetime.strptime(data[0], '%Y-%m-%d %H:%M:%S') + timedelta(hours=20)\n",
|
||||
" obj_data[\"open\"] = float(data[1])\n",
|
||||
" obj_data[\"high\"] = float(data[2])\n",
|
||||
" obj_data[\"low\"] = float(data[3])\n",
|
||||
" obj_data[\"close\"] = float(data[4])\n",
|
||||
" obj_data.Value = obj_data[\"close\"]\n",
|
||||
"\n",
|
||||
" # property for asserting the correct data is fetched\n",
|
||||
" obj_data[\"some_property\"] = \"some property value\"\n",
|
||||
" except ValueError:\n",
|
||||
" return None\n",
|
||||
"\n",
|
||||
" return obj_data\n",
|
||||
"\n",
|
||||
" def __str__ (self):\n",
|
||||
" return f\"Time: {self.Time}, Value: {self.Value}, SomeProperty: {self['some_property']}, Open: {self['open']}, High: {self['high']}, Low: {self['low']}, Close: {self['close']}\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create an instance\n",
|
||||
"qb = QuantBook()\n",
|
||||
"symbol = qb.AddData(CustomDataType, \"CustomDataType\", Resolution.Hour).Symbol\n",
|
||||
"\n",
|
||||
"startDate = datetime(2017, 8, 20)\n",
|
||||
"endDate = startDate + timedelta(hours=48)\n",
|
||||
"history = list(qb.History[CustomDataType](symbol, startDate, endDate, Resolution.Hour))\n",
|
||||
"\n",
|
||||
"if len(history) == 0:\n",
|
||||
" raise Exception(\"No history data returned\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "9650cb4e16cdd4a8e8e2d128bf38d875813998db22a3c986335f89e0cb4d7bb2"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
|
||||
namespace QuantConnect.Tests.Research.RegressionTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template framework for regression testing of research notebooks
|
||||
/// </summary>
|
||||
public class BasicTemplateResearchCSharp : IRegressionResearchDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected output from the reading the raw notebook file
|
||||
/// </summary>
|
||||
/// <remarks>Requires to be implemented last in the file <see cref="ResearchRegressionTests.UpdateResearchRegressionOutputInSourceFile"/>
|
||||
/// get should start from next line</remarks>
|
||||
public string ExpectedOutput =>
|
||||
"{ \"cells\": [ { \"cell_type\": \"markdown\", \"id\": \"a4652bd4\", \"metadata\": { \"papermill\": { \"duration\": 0.005036, \"end_t" +
|
||||
"ime\": \"2022-03-02T20:44:55.508287\", \"exception\": false, \"start_time\": \"2022-03-02T20:44:55.503251\", \"status\": \"completed\" " +
|
||||
"}, \"tags\": [] }, \"source\": [ \"\", \"## Welcome to " +
|
||||
"The QuantConnect Research Page\", \"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\", \"#### Con" +
|
||||
"tribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb\" ] }, { \"cell_type\": \"m" +
|
||||
"arkdown\", \"id\": \"acb5aec0\", \"metadata\": { \"papermill\": { \"duration\": 0.002024, \"end_time\": \"2022-03-02T20:44:55.513310\"," +
|
||||
" \"exception\": false, \"start_time\": \"2022-03-02T20:44:55.511286\", \"status\": \"completed\" }, \"tags\": [] }, \"source\": " +
|
||||
"[ \"## QuantBook Basics\", \"\", \"### Start QuantBook\", \"- Add the references and imports\", \"- Create a QuantBook instance\" ] " +
|
||||
"}, { \"cell_type\": \"code\", \"execution_count\": 1, \"id\": \"39de525f\", \"metadata\": { \"execution\": { \"iopub.execute_input\": " +
|
||||
"\"2022-03-02T20:44:55.529252Z\", \"iopub.status.busy\": \"2022-03-02T20:44:55.522252Z\", \"iopub.status.idle\": \"2022-03-02T20:44:57.058250Z\"" +
|
||||
", \"shell.execute_reply\": \"2022-03-02T20:44:57.052865Z\" }, \"papermill\": { \"duration\": 1.542006, \"end_time\": \"2022-03-02T20" +
|
||||
":44:57.058250\", \"exception\": false, \"start_time\": \"2022-03-02T20:44:55.516244\", \"status\": \"completed\" }, \"tags\": [] }" +
|
||||
", \"outputs\": [ { \"data\": { \"text/html\": [ \"\", \"<div>\", \" <div id='dotnet-interactive-this-cell-4972.Micr" +
|
||||
"osoft.DotNet.Interactive.Http.HttpPort' style='display: none'>\", \" The below script needs to be able to find the current output cell; t" +
|
||||
"his is an easy method to get it.\", \" </div>\", \" <script type='text/javascript'>\", \"async function probeAddresses(probing" +
|
||||
"Addresses) {\", \" function timeout(ms, promise) {\", \" return new Promise(function (resolve, reject) {\", \" " +
|
||||
"setTimeout(function () {\", \" reject(new Error('timeout'))\", \" }, ms)\", \" promise.then(res" +
|
||||
"olve, reject)\", \" })\", \" }\", \"\", \" if (Array.isArray(probingAddresses)) {\", \" for (let i =" +
|
||||
" 0; i < probingAddresses.length; i++) {\", \"\", \" let rootUrl = probingAddresses[i];\", \"\", \" if (!" +
|
||||
"rootUrl.endsWith('/')) {\", \" rootUrl = `${rootUrl}/`;\", \" }\", \"\", \" try {\", " +
|
||||
" \" let response = await timeout(1000, fetch(`${rootUrl}discovery`, {\", \" method: 'POST',\", \" " +
|
||||
" cache: 'no-cache',\", \" mode: 'cors',\", \" timeout: 1000,\", \" " +
|
||||
" headers: {\", \" 'Content-Type': 'text/plain'\", \" },\", \" body:" +
|
||||
" probingAddresses[i]\", \" }));\", \"\", \" if (response.status == 200) {\", \" " +
|
||||
" return rootUrl;\", \" }\", \" }\", \" catch (e) { }\", \" }\", \" }\"," +
|
||||
" \"}\", \"\", \"function loadDotnetInteractiveApi() {\", \" probeAddresses([\\\"http://192.168.29.151:1000/\\\", \\\"http:/" +
|
||||
"/127.0.0.1:1000/\\\"])\", \" .then((root) => {\", \" // use probing to find host url and api resources\", \" //" +
|
||||
" load interactive helpers and language services\", \" let dotnetInteractiveRequire = require.config({\", \" context: '4972.M" +
|
||||
"icrosoft.DotNet.Interactive.Http.HttpPort',\", \" paths:\", \" {\", \" 'dotnet-interactive'" +
|
||||
": `${root}resources`\", \" }\", \" }) || require;\", \"\", \" window.dotnetInteractiveRequire" +
|
||||
" = dotnetInteractiveRequire;\", \"\", \" window.configureRequireFromExtension = function(extensionName, extensionCacheBuster) {" +
|
||||
"\", \" let paths = {};\", \" paths[extensionName] = `${root}extensions/${extensionName}/resources/`;\", " +
|
||||
" \" \", \" let internalRequire = require.config({\", \" context: extensionCacheBuster,\"" +
|
||||
", \" paths: paths,\", \" urlArgs: `cacheBuster=${extensionCacheBuster}`\", \" " +
|
||||
" }) || require;\", \"\", \" return internalRequire\", \" };\", \" \", \" d" +
|
||||
"otnetInteractiveRequire([\", \" 'dotnet-interactive/dotnet-interactive'\", \" ],\", \" " +
|
||||
" function (dotnet) {\", \" dotnet.init(window);\", \" },\", \" function (error) " +
|
||||
"{\", \" console.log(error);\", \" }\", \" );\", \" })\", \" ." +
|
||||
"catch(error => {console.log(error);});\", \" }\", \"\", \"// ensure `require` is available globally\", \"if ((typeof(requir" +
|
||||
"e) !== typeof(Function)) || (typeof(require.config) !== typeof(Function))) {\", \" let require_script = document.createElement('script');\"," +
|
||||
" \" require_script.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js');\", \" require_scri" +
|
||||
"pt.setAttribute('type', 'text/javascript');\", \" \", \" \", \" require_script.onload = function() {\", \" loa" +
|
||||
"dDotnetInteractiveApi();\", \" };\", \"\", \" document.getElementsByTagName('head')[0].appendChild(require_script);\", \"" +
|
||||
"}\", \"else {\", \" loadDotnetInteractiveApi();\", \"}\", \"\", \" </script>\", \"</div>\" ] }, " +
|
||||
" \"metadata\": {}, \"output_type\": \"display_data\" }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"" +
|
||||
"Initialize.csx: Loading assemblies from D:\\\\quantconnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] } ], \"source\": [ \"// QuantBook C# Res" +
|
||||
"earch Environment\", \"// For more information see https://www.quantconnect.com/docs/research/overview\", \"#load \\\"./Initialize.csx\\\"\" ]" +
|
||||
" }, { \"cell_type\": \"code\", \"execution_count\": 2, \"id\": \"ceb0015a\", \"metadata\": { \"execution\": { \"iopub.execute_input\"" +
|
||||
": \"2022-03-02T20:44:57.066259Z\", \"iopub.status.busy\": \"2022-03-02T20:44:57.066259Z\", \"iopub.status.idle\": \"2022-03-02T20:44:57.188021" +
|
||||
"Z\", \"shell.execute_reply\": \"2022-03-02T20:44:57.187022Z\" }, \"papermill\": { \"duration\": 0.126763, \"end_time\": \"2022-03-02" +
|
||||
"T20:44:57.188021\", \"exception\": false, \"start_time\": \"2022-03-02T20:44:57.061258\", \"status\": \"completed\" }, \"tags\": [] " +
|
||||
" }, \"outputs\": [ { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.140 TRACE:: Config.GetV" +
|
||||
"alue(): debug-mode - Using default value: False\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"2" +
|
||||
"0220302 20:44:57.141 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: \" ] }, { " +
|
||||
" \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.141 TRACE:: Config.Get(): Configuration key not found" +
|
||||
". Key: plugin-directory - Using default value: \" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"2" +
|
||||
"0220302 20:44:57.142 TRACE:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default value: \" ] }, { \"n" +
|
||||
"ame\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.142 TRACE:: Composer(): Loading Assemblies from D:\\\\qua" +
|
||||
"ntconnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] }, { \"" +
|
||||
"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.168 TRACE:: Config.Get(): Configuration key not found. K" +
|
||||
"ey: version-id - Using default value: \" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 2" +
|
||||
"0:44:57.169 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: ../../../Data/\" ] }, { \"name" +
|
||||
"\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.169 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v" +
|
||||
"2.5.0.0 Mode: DEBUG (64bit) Host: P3561-70DPBL3\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"2" +
|
||||
"0220302 20:44:57.171 TRACE:: Engine.Main(): Started 2:14 AM\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\"" +
|
||||
": [ \"20220302 20:44:57.173 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager\" " +
|
||||
" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"20220302 20:44:57.179 TRACE:: Config.Get(): Configur" +
|
||||
"ation key not found. Key: data-permission-manager - Using default value: DataPermissionManager\" ] }, { \"name\": \"stdout\", \"outp" +
|
||||
"ut_type\": \"stream\", \"text\": [ \"20220302 20:44:57.180 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder" +
|
||||
" - Using default value: D:\\\\quantconnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream" +
|
||||
"\", \"text\": [ \"20220302 20:44:57.185 TRACE:: Config.Get(): Configuration key not found. Key: object-store-root - Using default value: ./st" +
|
||||
"orage\" ] } ], \"source\": [ \"#load \\\"./QuantConnect.csx\\\"\", \"\", \"using QuantConnect;\", \"using QuantConnect.Data;\"," +
|
||||
" \"using QuantConnect.Algorithm;\", \"using QuantConnect.Research;\" ] }, { \"cell_type\": \"code\", \"execution_count\": 3, \"id\": \"" +
|
||||
"e81ef855\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2022-03-02T20:44:57.200095Z\", \"iopub.status.busy\": \"2022-03-0" +
|
||||
"2T20:44:57.199026Z\", \"iopub.status.idle\": \"2022-03-02T20:44:58.393456Z\", \"shell.execute_reply\": \"2022-03-02T20:44:58.392457Z\" }, " +
|
||||
" \"papermill\": { \"duration\": 1.200436, \"end_time\": \"2022-03-02T20:44:58.393456\", \"exception\": false, \"start_time\": \"2022-" +
|
||||
"03-02T20:44:57.193020\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [ { \"name\": \"stdout\", \"output_type\":" +
|
||||
" \"stream\", \"text\": [ \"PythonEngine.Initialize(): Runtime.Initialize()...\" ] }, { \"name\": \"stdout\", \"output_type\"" +
|
||||
": \"stream\", \"text\": [ \"Runtime.Initialize(): Py_Initialize...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream" +
|
||||
"\", \"text\": [ \"Runtime.Initialize(): PyEval_InitThreads...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", " +
|
||||
" \"text\": [ \"Runtime.Initialize(): Initialize types...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"te" +
|
||||
"xt\": [ \"Runtime.Initialize(): Initialize types end.\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\":" +
|
||||
" [ \"Runtime.Initialize(): AssemblyManager.Initialize()...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"te" +
|
||||
"xt\": [ \"Runtime.Initialize(): AssemblyManager.UpdatePath()...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", " +
|
||||
" \"text\": [ \"PythonEngine.Initialize(): GetCLRModule()...\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"t" +
|
||||
"ext\": [ \"PythonEngine.Initialize(): clr GetManifestResourceStream...\" ] } ], \"source\": [ \"var qb = new QuantBook();\", \"v" +
|
||||
"ar spy = qb.AddEquity(\\\"SPY\\\");\" ] }, { \"cell_type\": \"code\", \"execution_count\": 4, \"id\": \"06cd5f47\", \"metadata\": { \"e" +
|
||||
"xecution\": { \"iopub.execute_input\": \"2022-03-02T20:44:58.408454Z\", \"iopub.status.busy\": \"2022-03-02T20:44:58.408454Z\", \"iopub.st" +
|
||||
"atus.idle\": \"2022-03-02T20:44:58.449457Z\", \"shell.execute_reply\": \"2022-03-02T20:44:58.449457Z\" }, \"papermill\": { \"duration\":" +
|
||||
" 0.048992, \"end_time\": \"2022-03-02T20:44:58.449457\", \"exception\": false, \"start_time\": \"2022-03-02T20:44:58.400465\", \"statu" +
|
||||
"s\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ \"var startDate = new DateTime(2021,1,1);\", \"var endDate = ne" +
|
||||
"w DateTime(2021,12,31);\", \"var history = qb.History(qb.Securities.Keys, startDate, endDate, Resolution.Daily);\" ] }, { \"cell_type\": \"co" +
|
||||
"de\", \"execution_count\": 5, \"id\": \"37b045b2\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2022-03-02T20:44:58.46348" +
|
||||
"5Z\", \"iopub.status.busy\": \"2022-03-02T20:44:58.463485Z\", \"iopub.status.idle\": \"2022-03-02T20:44:58.611572Z\", \"shell.execute_repl" +
|
||||
"y\": \"2022-03-02T20:44:58.611572Z\" }, \"papermill\": { \"duration\": 0.156117, \"end_time\": \"2022-03-02T20:44:58.611572\", \"exc" +
|
||||
"eption\": false, \"start_time\": \"2022-03-02T20:44:58.455455\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [ { " +
|
||||
" \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"SPY: O: 374.075 H: 374.2245 L: 363.6392 C: 367.5863 V: 94685703\" " +
|
||||
"] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"SPY: O: 366.8487 H: 371.2642 L: 366.8487 C: 370.118 V: " +
|
||||
"54790079\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"SPY: O: 368.4634 H: 375.7495 L: 367.9152" +
|
||||
" C: 372.3307 V: 93254510\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"SPY: O: 374.9521 H: 378." +
|
||||
"65 L: 374.693 C: 377.8626 V: 62474792\" ] }, { \"name\": \"stdout\", \"output_type\": \"stream\", \"text\": [ \"SPY: O: 379" +
|
||||
".3876 H: 380.2448 L: 375.8791 C: 380.0156 V: 63370827\" ] } ], \"source\": [ \"foreach(var slice in history.Take(5)) {\", \" Conso" +
|
||||
"le.WriteLine(slice.Bars[spy.Symbol].ToString());\", \"}\" ] }, { \"cell_type\": \"code\", \"execution_count\": null, \"id\": \"bd2ab8d7\"" +
|
||||
", \"metadata\": { \"papermill\": { \"duration\": 0.006983, \"end_time\": \"2022-03-02T20:44:58.626572\", \"exception\": false, \"" +
|
||||
"start_time\": \"2022-03-02T20:44:58.619589\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [] } ], \"met" +
|
||||
"adata\": { \"kernelspec\": { \"display_name\": \".NET (C#)\", \"language\": \"C#\", \"name\": \".net-csharp\" }, \"language_info\": { \"fil" +
|
||||
"e_extension\": \".cs\", \"mimetype\": \"text/x-csharp\", \"name\": \"C#\", \"pygments_lexer\": \"csharp\", \"version\": \"9.0\" }, \"papermi" +
|
||||
"ll\": { \"default_parameters\": {}, \"duration\": 7.291395, \"end_time\": \"2022-03-02T20:45:01.252292\", \"environment_variables\": {}, \"e" +
|
||||
"xception\": null, \"input_path\": \"D:\\\\quantconnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\\\\BasicTemplateResearchCSharp.ipynb\", \"output_path\": \"" +
|
||||
"D:\\\\quantconnect\\\\Lean\\\\Tests\\\\bin\\\\Debug\\\\BasicTemplateResearchCSharp-output.ipynb\", \"parameters\": {}, \"start_time\": \"2022-03-0" +
|
||||
"2T20:44:53.960897\", \"version\": \"2.3.4\" } }, \"nbformat\": 4, \"nbformat_minor\": 5}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"## Welcome to The QuantConnect Research Page\n",
|
||||
"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\n",
|
||||
"#### Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## QuantBook Basics\n",
|
||||
"\n",
|
||||
"### Start QuantBook\n",
|
||||
"- Add the references and imports\n",
|
||||
"- Create a QuantBook instance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"// QuantBook C# Research Environment\n",
|
||||
"// For more information see https://www.quantconnect.com/docs/research/overview\n",
|
||||
"#load \"./Initialize.csx\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#load \"./QuantConnect.csx\"\n",
|
||||
"\n",
|
||||
"using QuantConnect;\n",
|
||||
"using QuantConnect.Data;\n",
|
||||
"using QuantConnect.Algorithm;\n",
|
||||
"using QuantConnect.Research;"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var qb = new QuantBook();\n",
|
||||
"var spy = qb.AddEquity(\"SPY\");"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"var startDate = new DateTime(2021,1,1);\n",
|
||||
"var endDate = new DateTime(2021,12,31);\n",
|
||||
"var history = qb.History(qb.Securities.Keys, startDate, endDate, Resolution.Daily);"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"foreach(var slice in history.Take(5)) {\n",
|
||||
" Console.WriteLine(slice.Bars[spy.Symbol].ToString());\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".NET (C#)",
|
||||
"language": "C#",
|
||||
"name": ".net-csharp"
|
||||
},
|
||||
"language_info": {
|
||||
"file_extension": ".cs",
|
||||
"mimetype": "text/x-csharp",
|
||||
"name": "C#",
|
||||
"pygments_lexer": "csharp",
|
||||
"version": "9.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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.Interfaces;
|
||||
|
||||
namespace QuantConnect.Tests.Research.RegressionTemplates
|
||||
{
|
||||
/// <summary>
|
||||
/// Basic template framework for regression testing of research notebooks
|
||||
/// </summary>
|
||||
public class BasicTemplateResearchPython : IRegressionResearchDefinition
|
||||
{
|
||||
/// <summary>
|
||||
/// Expected output from the reading the raw notebook file
|
||||
/// </summary>
|
||||
/// <remarks>Requires to be implemented last in the file <see cref="ResearchRegressionTests.UpdateResearchRegressionOutputInSourceFile"/>
|
||||
/// get should start from next line</remarks>
|
||||
public string ExpectedOutput =>
|
||||
"{ \"cells\": [ { \"cell_type\": \"markdown\", \"id\": \"f5416762\", \"metadata\": { \"papermill\": { \"duration\": 0.001898, \"end_t" +
|
||||
"ime\": \"2024-06-06T22:15:49.572477\", \"exception\": false, \"start_time\": \"2024-06-06T22:15:49.570579\", \"status\": \"completed\" " +
|
||||
"}, \"tags\": [] }, \"source\": [ \"\", \"## Welcome to " +
|
||||
"The QuantConnect Research Page\", \"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\", \"#### Con" +
|
||||
"tribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb\" ] }, { \"cell_type\": \"m" +
|
||||
"arkdown\", \"id\": \"44ed65de\", \"metadata\": { \"papermill\": { \"duration\": 0.001, \"end_time\": \"2024-06-06T22:15:49.574475\", " +
|
||||
" \"exception\": false, \"start_time\": \"2024-06-06T22:15:49.573475\", \"status\": \"completed\" }, \"tags\": [] }, \"source\": [ " +
|
||||
" \"## QuantBook Basics\", \"\", \"### Start QuantBook\", \"- Add the references and imports\", \"- Create a QuantBook instance\" ] }, " +
|
||||
" { \"cell_type\": \"code\", \"execution_count\": 1, \"id\": \"677a4f25\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2" +
|
||||
"024-06-06T22:15:49.577476Z\", \"iopub.status.busy\": \"2024-06-06T22:15:49.577476Z\", \"iopub.status.idle\": \"2024-06-06T22:15:49.581464Z\", " +
|
||||
" \"shell.execute_reply\": \"2024-06-06T22:15:49.581464Z\" }, \"papermill\": { \"duration\": 0.006902, \"end_time\": \"2024-06-06T22:1" +
|
||||
"5:49.582478\", \"exception\": false, \"start_time\": \"2024-06-06T22:15:49.575576\", \"status\": \"completed\" }, \"tags\": [] }, " +
|
||||
" \"outputs\": [], \"source\": [ \"import warnings\", \"warnings.filterwarnings(\\\"ignore\\\")\" ] }, { \"cell_type\": \"code\", \"ex" +
|
||||
"ecution_count\": 2, \"id\": \"e752d505\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2024-06-06T22:15:49.584480Z\", \"" +
|
||||
"iopub.status.busy\": \"2024-06-06T22:15:49.584480Z\", \"iopub.status.idle\": \"2024-06-06T22:15:51.028418Z\", \"shell.execute_reply\": \"2024-" +
|
||||
"06-06T22:15:51.028418Z\" }, \"papermill\": { \"duration\": 1.445955, \"end_time\": \"2024-06-06T22:15:51.029433\", \"exception\": fa" +
|
||||
"lse, \"start_time\": \"2024-06-06T22:15:49.583478\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ " +
|
||||
" \"# Load in our startup script, required to set runtime for PythonNet\", \"%run ./start.py\" ] }, { \"cell_type\": \"code\", \"execution_" +
|
||||
"count\": 3, \"id\": \"08d48a2d\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2024-06-06T22:15:51.032433Z\", \"iopub.st" +
|
||||
"atus.busy\": \"2024-06-06T22:15:51.032433Z\", \"iopub.status.idle\": \"2024-06-06T22:15:51.344980Z\", \"shell.execute_reply\": \"2024-06-06T22" +
|
||||
":15:51.344980Z\" }, \"papermill\": { \"duration\": 0.315568, \"end_time\": \"2024-06-06T22:15:51.345999\", \"exception\": false, " +
|
||||
" \"start_time\": \"2024-06-06T22:15:51.030431\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ \"# Cr" +
|
||||
"eate an instance\", \"qb = QuantBook()\", \"\", \"# Select asset data\", \"spy = qb.AddEquity(\\\"SPY\\\")\" ] }, { \"cell_type\": \"" +
|
||||
"markdown\", \"id\": \"07f707ad\", \"metadata\": { \"papermill\": { \"duration\": 0.000998, \"end_time\": \"2024-06-06T22:15:51.348997\"" +
|
||||
", \"exception\": false, \"start_time\": \"2024-06-06T22:15:51.347999\", \"status\": \"completed\" }, \"tags\": [] }, \"source\":" +
|
||||
" [ \"### Historical Data Requests\", \"\", \"We can use the QuantConnect API to make Historical Data Requests. The data will be presented as " +
|
||||
"multi-index pandas.DataFrame where the first index is the Symbol.\", \"\", \"For more information, please follow the [link](https://www.quantcon" +
|
||||
"nect.com/docs#Historical-Data-Historical-Data-Requests).\" ] }, { \"cell_type\": \"code\", \"execution_count\": 4, \"id\": \"ef440f9e\", \"" +
|
||||
"metadata\": { \"execution\": { \"iopub.execute_input\": \"2024-06-06T22:15:51.352999Z\", \"iopub.status.busy\": \"2024-06-06T22:15:51.35299" +
|
||||
"9Z\", \"iopub.status.idle\": \"2024-06-06T22:15:51.356860Z\", \"shell.execute_reply\": \"2024-06-06T22:15:51.356860Z\" }, \"papermill\":" +
|
||||
" { \"duration\": 0.00689, \"end_time\": \"2024-06-06T22:15:51.357885\", \"exception\": false, \"start_time\": \"2024-06-06T22:15:51.35" +
|
||||
"0995\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ \"startDate = DateTime(2021,1,1)\", \"endDat" +
|
||||
"e = DateTime(2021,12,31)\" ] }, { \"cell_type\": \"code\", \"execution_count\": 5, \"id\": \"33a5fd5d\", \"metadata\": { \"execution\":" +
|
||||
" { \"iopub.execute_input\": \"2024-06-06T22:15:51.361875Z\", \"iopub.status.busy\": \"2024-06-06T22:15:51.360883Z\", \"iopub.status.idle\"" +
|
||||
": \"2024-06-06T22:15:51.453871Z\", \"shell.execute_reply\": \"2024-06-06T22:15:51.453871Z\" }, \"papermill\": { \"duration\": 0.095009, " +
|
||||
" \"end_time\": \"2024-06-06T22:15:51.454884\", \"exception\": false, \"start_time\": \"2024-06-06T22:15:51.359875\", \"status\": \"comp" +
|
||||
"leted\" }, \"scrolled\": true, \"tags\": [] }, \"outputs\": [], \"source\": [ \"# Gets historical data from the subscribed assets, t" +
|
||||
"he last 360 datapoints with daily resolution\", \"h1 = qb.History(qb.Securities.Keys, startDate, endDate, Resolution.Daily)\", \"\", \"if h1." +
|
||||
"shape[0] < 1:\", \" raise Exception(\\\"History request resulted in no data\\\")\" ] }, { \"cell_type\": \"markdown\", \"id\": \"e8f9c90" +
|
||||
"d\", \"metadata\": { \"papermill\": { \"duration\": 0.000996, \"end_time\": \"2024-06-06T22:15:51.457883\", \"exception\": false, " +
|
||||
" \"start_time\": \"2024-06-06T22:15:51.456887\", \"status\": \"completed\" }, \"tags\": [] }, \"source\": [ \"### Indicators\", \"" +
|
||||
"\", \"We can easily get the indicator of a given symbol with QuantBook. \", \"\", \"For all indicators, please checkout QuantConnect Indicato" +
|
||||
"rs [Reference Table](https://www.quantconnect.com/docs#Indicators-Reference-Table)\" ] }, { \"cell_type\": \"code\", \"execution_count\": 6, " +
|
||||
" \"id\": \"dcc7e1f0\", \"metadata\": { \"execution\": { \"iopub.execute_input\": \"2024-06-06T22:15:51.461887Z\", \"iopub.status.busy\": " +
|
||||
"\"2024-06-06T22:15:51.461887Z\", \"iopub.status.idle\": \"2024-06-06T22:15:51.502741Z\", \"shell.execute_reply\": \"2024-06-06T22:15:51.502741" +
|
||||
"Z\" }, \"papermill\": { \"duration\": 0.044872, \"end_time\": \"2024-06-06T22:15:51.503757\", \"exception\": false, \"start_time" +
|
||||
"\": \"2024-06-06T22:15:51.458885\", \"status\": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [ \"# Example with BB" +
|
||||
", it is a datapoint indicator\", \"# Define the indicator\", \"bb = BollingerBands(30, 2)\", \"\", \"# Gets historical data of indicator\"" +
|
||||
", \"bbdf = qb.IndicatorHistory(bb, \\\"SPY\\\", startDate, endDate, Resolution.Daily).data_frame\", \"\", \"# drop undesired fields\", \"bbdf = b" +
|
||||
"bdf.drop('standarddeviation', axis=1)\", \"\", \"if bbdf.shape[0] < 1:\", \" raise Exception(\\\"Bollinger Bands resulted in no data\\\")\"" +
|
||||
" ] }, { \"cell_type\": \"code\", \"execution_count\": null, \"id\": \"3095c061\", \"metadata\": { \"papermill\": { \"duration\": 0." +
|
||||
"001003, \"end_time\": \"2024-06-06T22:15:51.506759\", \"exception\": false, \"start_time\": \"2024-06-06T22:15:51.505756\", \"status\"" +
|
||||
": \"completed\" }, \"tags\": [] }, \"outputs\": [], \"source\": [] } ], \"metadata\": { \"kernelspec\": { \"display_name\": \"Python 3" +
|
||||
" (ipykernel)\", \"language\": \"python\", \"name\": \"python3\" }, \"language_info\": { \"codemirror_mode\": { \"name\": \"ipython\", \"" +
|
||||
"version\": 3 }, \"file_extension\": \".py\", \"mimetype\": \"text/x-python\", \"name\": \"python\", \"nbconvert_exporter\": \"python\", \"" +
|
||||
"pygments_lexer\": \"ipython3\", \"version\": \"3.11.7\" }, \"papermill\": { \"default_parameters\": {}, \"duration\": 6.254067, \"end_time\"" +
|
||||
": \"2024-06-06T22:15:54.143637\", \"environment_variables\": {}, \"exception\": null, \"input_path\": \"D:\\\\QuantConnect\\\\MyLean\\\\Lean\\\\T" +
|
||||
"ests\\\\bin\\\\Debug\\\\Research\\\\RegressionTemplates\\\\BasicTemplateResearchPython.ipynb\", \"output_path\": \"D:\\\\QuantConnect\\\\MyLean\\\\L" +
|
||||
"ean\\\\Tests\\\\bin\\\\Debug\\\\Research\\\\RegressionTemplates\\\\BasicTemplateResearchPython-output.ipynb\", \"parameters\": {}, \"start_time\":" +
|
||||
" \"2024-06-06T22:15:47.889570\", \"version\": \"2.4.0\" } }, \"nbformat\": 4, \"nbformat_minor\": 5}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"## Welcome to The QuantConnect Research Page\n",
|
||||
"#### Refer to this page for documentation https://www.quantconnect.com/docs/research/overview#\n",
|
||||
"#### Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Research/BasicQuantBookTemplate.ipynb"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## QuantBook Basics\n",
|
||||
"\n",
|
||||
"### Start QuantBook\n",
|
||||
"- Add the references and imports\n",
|
||||
"- Create a QuantBook instance"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import warnings\n",
|
||||
"warnings.filterwarnings(\"ignore\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Load in our startup script, required to set runtime for PythonNet\n",
|
||||
"%run ./start.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create an instance\n",
|
||||
"qb = QuantBook()\n",
|
||||
"\n",
|
||||
"# Select asset data\n",
|
||||
"spy = qb.AddEquity(\"SPY\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Historical Data Requests\n",
|
||||
"\n",
|
||||
"We can use the QuantConnect API to make Historical Data Requests. The data will be presented as multi-index pandas.DataFrame where the first index is the Symbol.\n",
|
||||
"\n",
|
||||
"For more information, please follow the [link](https://www.quantconnect.com/docs#Historical-Data-Historical-Data-Requests)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"startDate = DateTime(2021,1,1)\n",
|
||||
"endDate = DateTime(2021,12,31)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution\n",
|
||||
"h1 = qb.History(qb.Securities.Keys, startDate, endDate, Resolution.Daily)\n",
|
||||
"\n",
|
||||
"if h1.shape[0] < 1:\n",
|
||||
" raise Exception(\"History request resulted in no data\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Indicators\n",
|
||||
"\n",
|
||||
"We can easily get the indicator of a given symbol with QuantBook. \n",
|
||||
"\n",
|
||||
"For all indicators, please checkout QuantConnect Indicators [Reference Table](https://www.quantconnect.com/docs#Indicators-Reference-Table)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Example with BB, it is a datapoint indicator\n",
|
||||
"# Define the indicator\n",
|
||||
"bb = BollingerBands(30, 2)\n",
|
||||
"\n",
|
||||
"# Gets historical data of indicator\n",
|
||||
"bbdf = qb.IndicatorHistory(bb, \"SPY\", startDate, endDate, Resolution.Daily).data_frame\n",
|
||||
"\n",
|
||||
"# drop undesired fields\n",
|
||||
"bbdf = bbdf.drop('standarddeviation', axis=1)\n",
|
||||
"\n",
|
||||
"if bbdf.shape[0] < 1:\n",
|
||||
" raise Exception(\"Bollinger Bands resulted in no data\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
Reference in New Issue
Block a user