2017-06-02 13:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 1,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"%matplotlib inline\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"from vnpy.trader.app.ctaStrategy.ctaBacktesting import BacktestingEngine, OptimizationSetting, MINUTE_DB_NAME\n",
|
|
|
|
|
"from vnpy.trader.app.ctaStrategy.strategy.strategyAtrRsi import AtrRsiStrategy"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 2,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 创建回测引擎对象\n",
|
|
|
|
|
"engine = BacktestingEngine()"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 3,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 设置回测使用的数据\n",
|
|
|
|
|
"engine.setBacktestingMode(engine.BAR_MODE) # 设置引擎的回测模式为K线\n",
|
|
|
|
|
"engine.setDatabase(MINUTE_DB_NAME, 'IF0000') # 设置使用的历史数据库\n",
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"engine.setStartDate('20120101') # 设置回测用的数据起始日期"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 4,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 配置回测引擎参数\n",
|
|
|
|
|
"engine.setSlippage(0.2) # 设置滑点为股指1跳\n",
|
|
|
|
|
"engine.setRate(0.3/10000) # 设置手续费万0.3\n",
|
|
|
|
|
"engine.setSize(300) # 设置股指合约大小 \n",
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"engine.setPriceTick(0.2) # 设置股指最小价格变动 \n",
|
|
|
|
|
"engine.setCapital(1000000) # 设置回测本金"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 5,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 在引擎中创建策略对象\n",
|
|
|
|
|
"d = {'atrLength': 11} # 策略参数配置\n",
|
|
|
|
|
"engine.initStrategy(AtrRsiStrategy, d) # 创建策略对象"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 6,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"2017-09-23 19:05:15.863000\t开始载入数据\n",
|
|
|
|
|
"2017-09-23 19:05:16.009000\t载入完成,数据量:351090\n",
|
|
|
|
|
"2017-09-23 19:05:16.009000\t开始回测\n",
|
|
|
|
|
"2017-09-23 19:05:16.027000\t策略初始化完成\n",
|
|
|
|
|
"2017-09-23 19:05:16.027000\t策略启动完成\n",
|
|
|
|
|
"2017-09-23 19:05:16.027000\t开始回放数据\n",
|
|
|
|
|
"2017-09-23 19:05:39.203000\t数据回放结束\n"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 运行回测\n",
|
|
|
|
|
"engine.runBacktesting() # 运行回测"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 7,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"2017-09-23 19:05:39.209000\t计算按日统计结果\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t------------------------------\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t首个交易日:\t2012-01-11\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t最后交易日:\t2017-07-14\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总交易日:\t1338\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t盈利交易日\t651\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t亏损交易日:\t686\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t起始资金:\t1000000\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t结束资金:\t1,601,119.34\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总收益率:\t60.11\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总盈亏:\t601,119.34\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t最大回撤: \t-185,949.45\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总手续费:\t220,760.66\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总滑点:\t457,980.0\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总成交金额:\t7,358,688,660.0\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t总成交笔数:\t7,632.0\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均盈亏:\t449.27\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均手续费:\t164.99\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均滑点:\t342.29\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均成交金额:\t5,499,767.31\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均成交笔数:\t5.7\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t日均收益率:\t0.04%\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\t收益标准差:\t1.07%\n",
|
|
|
|
|
"2017-09-23 19:05:39.282000\tSharpe Ratio:\t0.52\n"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoEAAAOlCAYAAAASGT0sAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XlYVeX2wPEvMikzOELOsymaQppjWdfMyrT8lYp6S23Q\nMisnKs0p0zTBBrSbeaubKImVt7LRSiEtU3HAq6LlSEIqijLKuH9/LDcHFBQROEdcn+fx2Wfvs88+\n7zlbdLHe912vnWEYBkoppZRS6oZSzdoNUEoppZRSlU+DQKWUUkqpG5AGgUoppZRSNyANApVSSiml\nbkAaBCqllFJK3YA0CFRKKaWUugE5WLsBSilVno4fP06fPn1o1aoVhmGQl5eHi4sLwcHBdOrUqcTX\nvfTSS7Rs2ZKRI0dWYmuVUsp6NAhUSlU51atXZ82aNQX73377LS+99BLff/+9FVullFK2RYNApVSV\nl5ycTJ06dQCYM2cOu3fvJj09HcMwmDNnDh07dixy/qeffkpkZCS5ubmcPXuWJ598kiFDhrBmzRrW\nrVtHtWrVOHr0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JHDVqFNOnT+fzzz+nWrVq\ntG3blgMHDhQ5x2Tu16xZk4ULFzJlyhTy8/Nxc3Nj0aJFeHt7884777BgwQKysrIwDIM33ngDX1/f\nSvwmlFLK+qZOlW3hIDA/H269Ffr2lf1jxyAvD+zti742LQ3eestyjQu/s/PHH/JYizsoW2JnmGml\nKiAmJoaAgABrN0MBCQk
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"text/plain": [
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"<matplotlib.figure.Figure at 0xcf3a810>"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"# 显示逐日回测结果\n",
|
|
|
|
|
"df = engine.showDailyResult()"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": 8,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"2017-09-23 19:09:02.702000\t计算回测结果\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t------------------------------\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t第一笔交易:\t2012-01-11 10:18:00\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t最后一笔交易:\t2017-07-14 15:00:00\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t总交易次数:\t3,817.0\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t总盈亏:\t601,026.05\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t最大回撤: \t-215,542.46\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t平均每笔盈利:\t157.46\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t平均每笔滑点:\t120.0\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t平均每笔佣金:\t57.84\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t胜率\t\t37.1%\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t盈利交易平均值\t8,540.18\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t亏损交易平均值\t-4,786.29\n",
|
|
|
|
|
"2017-09-23 19:09:02.824000\t盈亏比:\t1.78\n"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
2017-07-14 12:12:42 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsgAAASZCAYAAADGqegeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xl4U2X2B/BvuoTSvSwFShG0lk1ZiwiCDIIo7oOAQBFU\ncEGtKLuCsvjTAZHFhWFc0FFR2RwZUdFRFIuAKBTZxKICytKyla170ia/Pw4v9940bdM0TZv0+3ke\nnntzc5O8uS1w8ua855jsdrsdREREREQEAAio7gEQEREREdUkDJCJiIiIiHQYIBMRERER6TBAJiIi\nIiLSYYBMRERERKTDAJmIiIiISCfImy9WVFSEKVOm4OjRowgKCsL//d//ITAwEE8++SQCAgKQmJiI\nGTNmAABWrlyJFStWIDg4GGPGjEHv3r1RWFiISZMmISsrC+Hh4ZgzZw5iYmKwY8cO/OMf/0BQUBCu\nueYapKSkAAAWLVqE1NRUBAUF4amnnkL79u29+XaJiIiIyAd5NUBOTU2FzWbD8uXLsXnzZixcuBBW\nqxXjx49Hly5dMGPGDKxbtw4dO3bE0qVLsXr1ahQUFGDYsGHo0aMHli1bhpYtWyIlJQVr167F4sWL\nMW3aN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SoJFi+5RALkgADjzOD69ZJisHNnyVnR4mJjgAdI0KZy\ne7/6yv33V1XsdglMHWeQy9KypWupBCqP+OBBmdXXi42VUnqq/FtWVskAOS1Nq7WsnDunLZpMTAQO\nHJDXSUyUXGdvuPlm4I4
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"text/plain": [
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"<matplotlib.figure.Figure at 0x11504410>"
|
2017-07-14 12:12:42 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"output_type": "display_data"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
],
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"source": [
|
|
|
|
|
"# 显示逐笔回测结果\n",
|
|
|
|
|
"engine.showBacktestingResult()"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"execution_count": 11,
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"TradeID: 1, Time: 2012-01-11 09:18:00, Direction: 多, Price: 2464.4, Volume: 1\n",
|
|
|
|
|
"TradeID: 2, Time: 2012-01-11 10:18:00, Direction: 空, Price: 2448.8, Volume: 1\n",
|
|
|
|
|
"TradeID: 3, Time: 2012-01-11 10:19:00, Direction: 空, Price: 2448.4, Volume: 1\n",
|
|
|
|
|
"TradeID: 4, Time: 2012-01-11 14:21:00, Direction: 多, Price: 2456.2, Volume: 1\n",
|
|
|
|
|
"TradeID: 5, Time: 2012-01-11 14:22:00, Direction: 多, Price: 2455.6, Volume: 1\n",
|
|
|
|
|
"TradeID: 6, Time: 2012-01-11 14:57:00, Direction: 空, Price: 2444.0, Volume: 1\n",
|
|
|
|
|
"TradeID: 7, Time: 2012-01-11 14:58:00, Direction: 空, Price: 2445.8, Volume: 1\n",
|
|
|
|
|
"TradeID: 8, Time: 2012-01-12 09:51:00, Direction: 多, Price: 2452.8, Volume: 1\n",
|
|
|
|
|
"TradeID: 9, Time: 2012-01-12 09:52:00, Direction: 多, Price: 2452.0, Volume: 1\n",
|
|
|
|
|
"TradeID: 10, Time: 2012-01-12 10:31:00, Direction: 空, Price: 2455.2, Volume: 1\n"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"source": [
|
|
|
|
|
"# 显示前10条成交记录\n",
|
|
|
|
|
"for i in range(10):\n",
|
2017-09-25 05:51:24 +00:00
|
|
|
|
" d = engine.tradeDict[str(i+1)].__dict__\n",
|
|
|
|
|
" print 'TradeID: %s, Time: %s, Direction: %s, Price: %s, Volume: %s' %(d['tradeID'], d['dt'], d['direction'], d['price'], d['volume'])"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"metadata": {
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"collapsed": false
|
2017-06-02 13:44:28 +00:00
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 优化配置\n",
|
|
|
|
|
"setting = OptimizationSetting() # 新建一个优化任务设置对象\n",
|
|
|
|
|
"setting.setOptimizeTarget('capital') # 设置优化排序的目标是策略净盈利\n",
|
|
|
|
|
"setting.addParameter('atrLength', 12, 20, 2) # 增加第一个优化参数atrLength,起始12,结束20,步进2\n",
|
|
|
|
|
"setting.addParameter('atrMa', 20, 30, 5) # 增加第二个优化参数atrMa,起始20,结束30,步进5\n",
|
|
|
|
|
"setting.addParameter('rsiLength', 5) # 增加一个固定数值的参数\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"# 执行多进程优化\n",
|
|
|
|
|
"import time\n",
|
2017-09-25 05:51:24 +00:00
|
|
|
|
"start = time.time()\n",
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"engine.runParallelOptimization(AtrRsiStrategy, setting)\n",
|
|
|
|
|
"print u'耗时:%s' %(time.time()-start)"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"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
|
|
|
|
|
}
|