Files
quantconnect--lean/Research/KitchenSinkCSharpQuantBookTemplate.ipynb
T
Colton Sellers 9167882ab2 Feature Notebook Api Support (#4898)
* Modify Notebook scripts to load API instance

* Modify docker to move script to IPython profile

* Fix dockerfile copying of start.py

* Fix break for C# cloud and docker load

* Unnecessary path finding

* Update example notebooks

* Update documentation

* Address review

* Adjust readme

* Poor choice of words
2020-10-30 21:05:09 -03:00

201 lines
5.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![QuantConnect Logo](https://cdn.quantconnect.com/web/i/qc_notebook_logo_rev0.png)\n",
"## Welcome to The QuantConnect Research Page\n",
"#### Refer to this page for documentation https://www.quantconnect.com/docs#Introduction-to-Jupyter\n",
"#### Contribute to this template file https://github.com/QuantConnect/Lean/blob/master/Jupyter/BasicCSharpQuantBookTemplate.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## QuantBook Basics\n",
"The following example is ready to be used in our Docker container, reference the ReadMe for more details on setting this up.\n",
"\n",
"\n",
"\n",
"In order to use this notebook locally you will need to make a few small changes:\n",
"\n",
"1. Either create the notebook in your build folder (`bin/debug`) **or** set working directory of the notebook to it like so in the first cell:\n",
"\n",
" ```Directory.SetCurrentDirectory(\"PathToLean/Lean/Launcher/bin/Debug/\");```\n",
"\n",
"2. Load \"QuantConnect.csx\" instead of \"../QuantConnect.csx\", this is again because of the Notebook position relative to the build files. \n",
"\n",
"### Start QuantBook\n",
"- Load \"QuantConnect.csx\" with all the basic imports\n",
"- Create a QuantBook instance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#load \"../QuantConnect.csx\"\n",
"var qb = new QuantBook();"
]
},
{
"source": [
"### Using the Web API\n",
"Our script `QuantConnect.csx` automatically loads an instance of the web API for you to use.**\n",
"\n",
"Look at Lean's [Api](https://github.com/QuantConnect/Lean/tree/master/Api) class for more functions to interact with the cloud\n",
"\n",
"\n",
"##### **Note: This will only connect if you have your User ID and Api token in `config.json` "
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Show that our api object is connected to the Web Api\n",
"Console.WriteLine(api.Connected);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Get our list of projects from the cloud and print their names\n",
"var projectResponse = api.ListProjects();\n",
"foreach (var project in projectResponse.Projects) {\n",
" Console.WriteLine(project.Name);\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Selecting Asset Data\n",
"Checkout the QuantConnect [docs](https://www.quantconnect.com/docs#Initializing-Algorithms-Selecting-Asset-Data) to learn how to select asset data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"var spy = qb.AddEquity(\"SPY\");\n",
"var eur = qb.AddForex(\"EURUSD\");\n",
"var btc = qb.AddCrypto(\"BTCUSD\");\n",
"var fxv = qb.AddData<FxcmVolume>(\"EURUSD_Vol\", Resolution.Hour);"
]
},
{
"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": [
"// Gets historical data from the subscribed assets, the last 360 datapoints with daily resolution\n",
"var h1 = qb.History(qb.Securities.Keys, 360, Resolution.Daily);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Gets historical data from the subscribed assets, from the last 30 days with daily resolution\n",
"var h2 = qb.History(qb.Securities.Keys, TimeSpan.FromDays(360), Resolution.Daily);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Gets historical data from the subscribed assets, between two dates with daily resolution\n",
"var h3 = qb.History(btc.Symbol, new DateTime(2014,1,1), DateTime.Now, Resolution.Daily);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Only fetchs historical data from a desired symbol\n",
"var h4 = qb.History(spy.Symbol, 360, Resolution.Daily);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Only fetchs historical data from a desired symbol\n",
"var h5 = qb.History<QuoteBar>(eur.Symbol, TimeSpan.FromDays(360), Resolution.Daily);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Fetchs custom data\n",
"var h6 = qb.History<FxcmVolume>(fxv.Symbol, TimeSpan.FromDays(360));"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "C#",
"language": "csharp",
"name": "csharp"
},
"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.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}