chore: import upstream snapshot with attribution
This commit is contained in:
@@ -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