2018-11-11 03:45:27 +00:00
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"execution_count": null,
|
2018-11-11 03:45:27 +00:00
|
|
|
|
"metadata": {},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"%matplotlib inline\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"from datetime import datetime\n",
|
2018-11-11 06:57:51 +00:00
|
|
|
|
"\n",
|
|
|
|
|
"import numpy as np\n",
|
2018-11-11 03:45:27 +00:00
|
|
|
|
"import matplotlib.pyplot as plt\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"from turtleEngine import BacktestingEngine"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"execution_count": null,
|
2018-11-11 03:45:27 +00:00
|
|
|
|
"metadata": {
|
|
|
|
|
"scrolled": false
|
|
|
|
|
},
|
2018-11-11 07:25:59 +00:00
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"投资组合的合约代码['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"
|
2018-11-11 07:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
2018-11-11 03:45:27 +00:00
|
|
|
|
"source": [
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"engine = BacktestingEngine()\n",
|
|
|
|
|
"engine.setPeriod(datetime(2014, 1, 1), datetime(2018, 12, 30))\n",
|
|
|
|
|
"engine.initPortfolio('setting.csv', 10000000)\n",
|
|
|
|
|
"\n",
|
2018-11-11 06:57:51 +00:00
|
|
|
|
"engine.loadData()\n",
|
|
|
|
|
"engine.runBacktesting()\n",
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"engine.showResult()"
|
2018-11-11 03:45:27 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"execution_count": null,
|
2018-11-13 08:11:35 +00:00
|
|
|
|
"metadata": {
|
|
|
|
|
"scrolled": false
|
|
|
|
|
},
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"outputs": [],
|
2018-11-13 08:11:35 +00:00
|
|
|
|
"source": [
|
2018-11-13 15:00:38 +00:00
|
|
|
|
"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)"
|
2018-11-13 08:11:35 +00:00
|
|
|
|
]
|
2018-11-11 03:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"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
|
|
|
|
|
}
|