2017-10-07 15:25:59 +00:00
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 1,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"%matplotlib inline\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"from vnpy.trader.app.ctaStrategy.ctaBacktesting import BacktestingEngine, MINUTE_DB_NAME\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"def runBacktesting(strategyClass, settingDict, symbol, \n",
|
|
|
|
|
" startDate, endDate, slippage, \n",
|
|
|
|
|
" rate, size, priceTick):\n",
|
|
|
|
|
" \"\"\"运行单标的回测\"\"\"\n",
|
|
|
|
|
" engine = BacktestingEngine()\n",
|
|
|
|
|
" engine.setBacktestingMode(engine.BAR_MODE)\n",
|
|
|
|
|
" engine.setDatabase(MINUTE_DB_NAME, symbol)\n",
|
|
|
|
|
" engine.setStartDate(startDate)\n",
|
|
|
|
|
" engine.setEndDate(endDate)\n",
|
|
|
|
|
" engine.setSlippage(slippage)\n",
|
|
|
|
|
" engine.setRate(rate) \n",
|
|
|
|
|
" engine.setSize(size) \n",
|
|
|
|
|
" engine.setPriceTick(priceTick)\n",
|
|
|
|
|
" \n",
|
|
|
|
|
" engine.initStrategy(strategyClass, settingDict)\n",
|
|
|
|
|
" engine.runBacktesting()\n",
|
|
|
|
|
" df = engine.calculateDailyResult()\n",
|
|
|
|
|
" return df"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 2,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"2018-01-07 17:18:45.507000\t开始载入数据\n",
|
|
|
|
|
"2018-01-07 17:18:45.654000\t载入完成,数据量:348690\n",
|
|
|
|
|
"2018-01-07 17:18:45.654000\t开始回测\n",
|
|
|
|
|
"2018-01-07 17:18:45.694000\t策略初始化完成\n",
|
|
|
|
|
"2018-01-07 17:18:45.694000\t策略启动完成\n",
|
|
|
|
|
"2018-01-07 17:18:45.694000\t开始回放数据\n",
|
|
|
|
|
"2018-01-07 17:19:17.327000\t数据回放结束\n",
|
|
|
|
|
"2018-01-07 17:19:17.327000\t计算按日统计结果\n"
|
2017-10-07 15:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 运行IF回测,交易1手\n",
|
|
|
|
|
"from vnpy.trader.app.ctaStrategy.strategy.strategyAtrRsi import AtrRsiStrategy\n",
|
|
|
|
|
"df1 = runBacktesting(AtrRsiStrategy, {}, 'IF0000', \n",
|
|
|
|
|
" '20120101', '20170630', 0.2, \n",
|
|
|
|
|
" 0.3/10000, 300, 0.2)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 3,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"2018-01-07 17:19:26.235000\t开始载入数据\n",
|
|
|
|
|
"2018-01-07 17:19:26.396000\t载入完成,数据量:370838\n",
|
|
|
|
|
"2018-01-07 17:19:26.396000\t开始回测\n",
|
|
|
|
|
"2018-01-07 17:19:26.404000\t策略初始化完成\n",
|
|
|
|
|
"2018-01-07 17:19:26.404000\t策略启动完成\n",
|
|
|
|
|
"2018-01-07 17:19:26.404000\t开始回放数据\n",
|
|
|
|
|
"2018-01-07 17:19:43.626000\t数据回放结束\n",
|
|
|
|
|
"2018-01-07 17:19:43.627000\t计算按日统计结果\n"
|
2017-10-07 15:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 运行rb回测,交易16手\n",
|
|
|
|
|
"from vnpy.trader.app.ctaStrategy.strategy.strategyBollChannel import BollChannelStrategy\n",
|
|
|
|
|
"settingDict = {'fixedSize': 16}\n",
|
|
|
|
|
"df2 = runBacktesting(BollChannelStrategy, settingDict, 'rb0000', \n",
|
|
|
|
|
" '20120101', '20170630', 1, \n",
|
|
|
|
|
" 1/10000, 10, 1)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"execution_count": 4,
|
2017-10-07 15:25:59 +00:00
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"2018-01-07 17:23:24.218000\t------------------------------\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t首个交易日:\t2012-01-11\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t最后交易日:\t2017-06-30\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总交易日:\t1328\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t盈利交易日\t675\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t亏损交易日:\t653\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t起始资金:\t1000000\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t结束资金:\t2,495,104.82\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总收益率:\t149.51\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总盈亏:\t1,495,104.82\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t最大回撤: \t-151,844.23\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总手续费:\t216,395.18\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总滑点:\t556,780.0\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总成交金额:\t7,521,413,620.0\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t总成交笔数:\t8,168.0\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均盈亏:\t1,125.83\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均手续费:\t162.95\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均滑点:\t419.26\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均成交金额:\t5,663,715.08\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均成交笔数:\t6.15\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t日均收益率:\t0.07%\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\t收益标准差:\t0.97%\n",
|
|
|
|
|
"2018-01-07 17:23:24.218000\tSharpe Ratio:\t1.11\n"
|
2017-10-07 15:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoEAAAOlCAYAAAASGT0sAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xtc1FX++PEXAqPCcNUsWFRMUcugEDITJa3ccvOCmSKo\nldpFi7RIRdNYb6tmovYNbDXLdr2gqPnrZm215bBaZoJKqXQjFQEvCCoz6gDO5/fHcQbwBio4I76f\njwePz3zOnM9nzmdO5JtzddI0TUMIIYQQQtxUGti7AEIIIYQQ4vqTIFAIIYQQ4iYkQaAQQgghxE1I\ngkAh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MwmUyMGTOGAwcO4OnpyfTp0wGYPn06p06d4siRI9xxxx0sWLAAnU6HdZOX06dPM3Xq\nVPbv38/x48dxd3cnKSmJwMBAhg0bRmhoKJmZmeTn5xMeHs7cuXMB+Pbbb3nrrbfQNI3GjRszdepU\n2rdvT2ZmJklJSZw+fZoGDRoQFxdH9+7d7fW1CCGEEDb33w/PPquCrGef9eGDDypa08LCYMYM6NYN\n9Ho1a9fLS03qsGraVE36OHlSBYF794KPj2oV9PaG0lK49dYrL5dOp47OzurYooU6PvYYvPeeej1u\nnDp+95067tmjZhpbLFf+ebVJgkAHcPjwYRYsWMDdd99NWloaEyZM4N5776V///706dOH8vJyHn/8\ncQwGAz179rRdl56ejqenJ6tXrwbg73//OytWrGDKlCkA5ObmsmLFCkwmE7169WLbtm20bt2aCRMm\nsGLFCtq1a8dXX33F/Pn
|
2017-10-07 15:25:59 +00:00
|
|
|
|
"text/plain": [
|
2018-01-11 08:03:42 +00:00
|
|
|
|
"<matplotlib.figure.Figure at 0x1543a7f0>"
|
2017-10-07 15:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 合并获得组合回测结果\n",
|
|
|
|
|
"dfp = df1 + df2\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"# 注意如果被抛弃的交易日位于回测的前后,即两者不重合的日期中,则不会影响组合曲线正确性\n",
|
|
|
|
|
"# 但是如果被抛弃的交易日位于回测的中部,即两者重合的日期中,组合曲线会出现错误(丢失交易日)\n",
|
|
|
|
|
"dfp = dfp.dropna() \n",
|
|
|
|
|
"\n",
|
|
|
|
|
"# 创建回测引擎,并设置组合回测初始资金后,显示结果\n",
|
|
|
|
|
"engine = BacktestingEngine()\n",
|
|
|
|
|
"engine.setCapital(1000000)\n",
|
2017-11-30 01:44:09 +00:00
|
|
|
|
"dfp, result = engine.calculateDailyStatistics(dfp)\n",
|
|
|
|
|
"engine.showDailyResult(dfp, result)"
|
2017-10-07 15:25:59 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
2018-01-11 08:03:42 +00:00
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 5,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"2018-01-07 17:24:26.175000\t------------------------------\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t首个交易日:\t2012-01-11\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t最后交易日:\t2017-06-30\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总交易日:\t1328\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t盈利交易日\t648\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t亏损交易日:\t679\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t起始资金:\t1000000\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t结束资金:\t1,815,424.82\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总收益率:\t81.54\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总盈亏:\t815,424.82\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t最大回撤: \t-193,351.02\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总手续费:\t216,395.18\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总滑点:\t450,060.0\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总成交金额:\t7,213,172,820.0\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t总成交笔数:\t7,501.0\n",
|
|
|
|
|
"2018-01-07 17:24:26.175000\t日均盈亏:\t614.02\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t日均手续费:\t162.95\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t日均滑点:\t338.9\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t日均成交金额:\t5,431,606.04\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t日均成交笔数:\t5.65\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t日均收益率:\t0.05%\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\t收益标准差:\t1.07%\n",
|
|
|
|
|
"2018-01-07 17:24:26.176000\tSharpe Ratio:\t0.66\n"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoEAAAOlCAYAAAASGT0sAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3X18zXX/wPHX7Abb2Z17a0XuU4StcjWW6hJCxI8xVlGK\nWnRJ10i5DxXpxlQidQkhuUr35WLLSpibyU0pd2PLTYad4Wycz++Pt7OzMQzbzrG9n4+Hx/d8v+d7\nvudzztd47/35fN4fD2OMQSmllFJKlSnlXN0ApZRSSilV8jQIVEoppZQqgzQIVEoppZQqgzQIVEop\npZQqgzQIVEoppZQqgzQIVEoppZQqg7xc3QCllCpK+/fvp23btjRs2BBjDGfOnMHX15e4uDhatGhx\nwdeNGDGCBg0a0K9fvxJsrVJKuY4GgUqpUqdChQosXbo0d//rr79mxIgRfPvtty5slVJKuRcNApVS\npV5GRgbVqlUDYMKECWzevJmsrCyMMUyYMIHmzZvnO/+TTz5h0aJFnD59mqNHj/L444/Tq1cvli5d\nyvfff0+5cuXYs2cP3t7evPLKK9SrV4/Dhw8zevRodu7ciaenJ1FRUcTExGC1WnnppZf4/fffOX36\nNP/4xz/497//TblyOhpHKeVaGgQqpUqdU6dO8eCDD2KM4fjx4xw6dIgZM2awceNGDh8+zMKFCwGY\nOXMmM2fO5O2338597YkTJ/jkk0947733CAwMZNOmTfTr149evXoBsG7dOr744guqVavGhAkTmD17\nNpMmTWLMmDHceOONxMfHY7Va6d27N23atOHtt9/mlltuYdKkSdjtdoYPH87777/PY4895pLvRiml\nHDQIVEqVOud2B2/YsIEBAwbw2WefMWTIEBYsWMDevXtZs2YNFosl32t9fX155513WLFiBXv27GHb\ntm2cPHky9/mbb745N6vYuHFjvv/+ewB+/vln4uLiALBYLCxbtgyAlStXsnnzZhYvXgyAzWbDw8Oj\n+D68UkoVkgaBSqlSr3nz5tx4442sXbuWGTNm0L9/f/75z39Sp06d3GDN4cCBA0RFRREVFUV4eDjt\n2rUjISEh9/ny5cvnPvbw8MCx/LqXV/5/TlNTUwkODsZut/PGG29Qp04dAKxWa3F9TKWUuiw6KEUp\nVeo4AjOHXbt2sXv3br7++mvuueceevXqxS233MLy5cux2+35zt28eTOVKlVi0KBBREREsGLFigKv\nea4777yTTz/9FIDMzEweeeQR9u7dS6tWrfjggw8AyM7OZuDAgcybN6+IPqlSSl05zQQqpUqd7Oxs\nHnzwQUCCN8cEkAYNGvDss8/SpUsXPD09CQ8P57vvvsv32tatW7NkyRLatWuHn58fTZo0oVKlSuzZ\ns+ei7/niiy8yZswYHnjgAYwxDBw4kMaNGzNy5EgmTpxI586dOX36NBEREToeUCnlFjzMpX69VUop\npZRSpc4lM4GnT5/m+eefZ//+/eTk5DBw4EDq1avH8OHDKVeuHPXr12f06NEALFq0iIULF+Lt7c3A\ngQNp06YNNpuN5557jr///huLxcLkyZMJDg5m48aNTJw4ES8vL+68805iY2MBmD59OgkJCXh5eTFi\nxAiaNm1KRkYGw4YNw2azUa1aNSZNmpRvXI5SSimllLo8lxwT+PnnnxMcHMy8efOYNWsW48ePZ9Kk\nSQwdOpSPPvoIu93ODz/8wOHDh5k7dy4LFy5k1qxZTJ06lZycHBYsWECDBg2YN28eXbp0YcaMGQCM\nGTOG1157jfnz55OSksL27dvZunUr69atY/Hixbz22muMGzcOgPj4eDp37sxHH31Eo0aNWLBgQfF+\nK0oppZRSpdw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|
|
|
|
|
"text/plain": [
|
|
|
|
|
"<matplotlib.figure.Figure at 0x1498ad30>"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"engine = BacktestingEngine()\n",
|
|
|
|
|
"engine.setCapital(1000000)\n",
|
|
|
|
|
"df1, result = engine.calculateDailyStatistics(df1)\n",
|
|
|
|
|
"engine.showDailyResult(df1, result)"
|
|
|
|
|
]
|
|
|
|
|
},
|
2017-10-07 15:25:59 +00:00
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": []
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"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.13"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"nbformat": 4,
|
|
|
|
|
"nbformat_minor": 0
|
|
|
|
|
}
|