增加交易策略、交易指标、量化库代码等文件夹
This commit is contained in:
139
5.课程代码/2.Option_spread_strategy/使用文档/19/download_data.ipynb
Normal file
139
5.课程代码/2.Option_spread_strategy/使用文档/19/download_data.ipynb
Normal file
@@ -0,0 +1,139 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 配置迅投研数据服务\n",
|
||||
"from vnpy.trader.setting import SETTINGS\n",
|
||||
"\n",
|
||||
"SETTINGS[\"datafeed.name\"] = \"xt\"\n",
|
||||
"SETTINGS[\"datafeed.username\"] = \"token\"\n",
|
||||
"SETTINGS[\"datafeed.password\"] = \"4aff6f3b0dcfc990ec9476213ba784e17c34e757\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# 加载功能模块\n",
|
||||
"from datetime import datetime\n",
|
||||
"\n",
|
||||
"from vnpy.trader.datafeed import get_datafeed\n",
|
||||
"from vnpy.trader.object import HistoryRequest, Exchange, Interval\n",
|
||||
"\n",
|
||||
"from vnpy_sqlite import Database as SqliteDatabase\n",
|
||||
"from elite_database import Database as EliteDatabase"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 初始化数据服务\n",
|
||||
"datafeed = get_datafeed()\n",
|
||||
"datafeed.init()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"数据长度 174959\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 查询期权历史数据\n",
|
||||
"req = HistoryRequest(\n",
|
||||
" symbol=\"IFJQ00\", # 加权指数 \n",
|
||||
" # symbol=\"IF00\", # 主力连续(未平滑)\n",
|
||||
" exchange=Exchange.CFFEX,\n",
|
||||
" start=datetime(2015, 1, 1),\n",
|
||||
" end=datetime.now(),\n",
|
||||
" interval=Interval.MINUTE\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"bars = datafeed.query_bar_history(req)\n",
|
||||
"print(\"数据长度\", len(bars))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"True"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# 创建Elite数据库实例并写入数据\n",
|
||||
"db2 = EliteDatabase()\n",
|
||||
"db2.save_bar_data(bars)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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.10.9"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "1b43cb0bd93d5abbadd54afed8252f711d4681fe6223ad6b67ffaee289648f85"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
Reference in New Issue
Block a user