vnpy/examples/TurtleStrategy/.ipynb_checkpoints/run-checkpoint.ipynb

113 lines
2.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"from datetime import datetime\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from turtleEngine import BacktestingEngine"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"投资组合的合约代码['IF99', 'I99', 'CU99', 'TA99']\n",
"投资组合的初始价值10000000\n",
"IF99数据加载完成总数据量1185\n",
"I99数据加载完成总数据量1185\n",
"CU99数据加载完成总数据量1185\n",
"TA99数据加载完成总数据量1185\n",
"全部数据加载完成\n",
"开始回放K线数据\n",
"K线数据回放结束\n",
"开始统计回测结果\n",
"------------------------------\n",
"首个交易日:\t2014-01-02 00:00:00\n",
"最后交易日:\t2018-11-09 00:00:00\n",
"总交易日:\t1185\n",
"盈利交易日\t523\n",
"亏损交易日:\t552\n",
"起始资金:\t10000000\n",
"结束资金:\t54,093,646.23\n",
"总收益率:\t440.94%\n",
"年化收益:\t37.23%\n",
"总盈亏:\t44,093,646.23\n",
"最大回撤: \t-7,822,360.7\n",
"百分比最大回撤: -18.09%\n",
"总手续费:\t607,834.31\n",
"总滑点:\t170,572.2\n",
"总成交笔数:\t571.0\n",
"日均盈亏:\t37,209.83\n",
"日均手续费:\t512.94\n",
"日均滑点:\t143.94\n",
"日均成交笔数:\t0.0\n",
"日均收益率:\t0.16%\n",
"收益标准差:\t1.6%\n",
"Sharpe Ratio\t1.5\n"
]
}
],
"source": [
"engine = BacktestingEngine()\n",
"engine.setPeriod(datetime(2014, 1, 1), datetime(2018, 12, 30))\n",
"engine.initPortfolio('setting.csv', 10000000)\n",
"\n",
"engine.loadData()\n",
"engine.runBacktesting()\n",
"engine.showResult()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"tradeList = engine.getTradeData('000300')\n",
"for trade in tradeList:\n",
" print '%s %s %s %s@%s' %(trade.vtSymbol, trade.direction, trade.offset,\n",
" trade.volume, trade.price)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}