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-07-14 12:12:42 +00:00
|
|
|
|
"engine.setStartDate('20160101') # 设置回测用的数据起始日期"
|
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-07-14 12:12:42 +00:00
|
|
|
|
"2017-07-14 20:10:59.807000\t开始载入数据\n",
|
|
|
|
|
"2017-07-14 20:10:59.859000\t载入完成,数据量:69994\n",
|
|
|
|
|
"2017-07-14 20:10:59.859000\t开始回测\n",
|
|
|
|
|
"2017-07-14 20:10:59.872000\t策略初始化完成\n",
|
|
|
|
|
"2017-07-14 20:10:59.872000\t策略启动完成\n",
|
|
|
|
|
"2017-07-14 20:10:59.872000\t开始回放数据\n",
|
|
|
|
|
"2017-07-14 20:11:04.727000\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-07-14 12:12:42 +00:00
|
|
|
|
"2017-07-14 20:11:05.963000\t计算按日统计结果\n",
|
|
|
|
|
"2017-07-14 20:11:05.981000\t------------------------------\n",
|
|
|
|
|
"2017-07-14 20:11:05.981000\t首个交易日:\t2016-01-11\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t最后交易日:\t2017-03-20\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总交易日:\t289\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t盈利交易日\t146\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t亏损交易日:\t143\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t起始资金:\t1000000\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t结束资金:\t973,109.83\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总收益率:\t-2.69\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总盈亏:\t-26,890.17\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t最大回撤: \t-162,300.57\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总手续费:\t28,270.17\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总滑点:\t60,300.0\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总成交金额:\t942,339,000.0\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t总成交笔数:\t1,004.0\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均盈亏:\t-93.05\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均手续费:\t97.82\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均滑点:\t208.65\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均成交金额:\t3,260,688.58\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均成交笔数:\t3.47\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t日均收益率:\t-0.02%\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\t收益标准差:\t1.11%\n",
|
|
|
|
|
"2017-07-14 20:11:05.982000\tSharpe Ratio:\t-0.27\n"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAoAAAAOlCAYAAAD921YSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3XtclHX6//EXp/HAcMojSAGa56QUNA11q82tdtesXEVQ\nd0srs1i31I1cy9CtrL4e8rtofVu3dstDqLuunfZXWYqraSmGaIonFNEhD4kKqIDO/P64HJiBAYZh\nOHo9Hw8fyj333HPPRx3eXJ+Th8VisaCUUkoppa4bng19A0oppZRSqn5pAFRKKaWUus5oAFRKKaWU\nus5oAFRKKaWUus5oAFRKKaWUus5oAFRKKaWUus54N/QNKKWUO504cYJhw4bRvXt3LBYLV69epXXr\n1iQmJtKvX79Knzdjxgy6devGo48+Wo93q5RSDUMDoFKq2WnZsiVr164t/fo///kPM2bM4PPPP2/A\nu1JKqcZDA6BSqtnLy8ujffv2ALz88svs3r2bwsJCLBYLL7/8Mn379rU7f82aNaxatYorV65w7tw5\nnnjiCcaMGcPatWv58ssv8fT0J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z\nSUpKIjk5mdDQUJ544gkyMzMxm83s2LGD1atXk5uby+9//3vWrFnD4sWLGT58OA8++CDvvPMOK1eu\n5JFHHqmzRlFKKaVU49SlSxcWL17MsWPHaNu2La+//jobN27k6aefJjAwkFatWjFgwACOHTsGlFUA\nJ0yYwKxZs/jXv/6Fp6c
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"text/plain": [
|
2017-07-14 12:12:42 +00:00
|
|
|
|
"<matplotlib.figure.Figure at 0x119e6350>"
|
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-07-14 12:12:42 +00:00
|
|
|
|
"2017-07-14 20:11:13.701000\t计算回测结果\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t------------------------------\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t第一笔交易:\t2016-01-11 09:33:00\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t最后一笔交易:\t2017-03-20 15:00:00\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t总交易次数:\t503.0\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t总盈亏:\t-26,980.93\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t最大回撤: \t-160,499.28\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t平均每笔盈利:\t-53.64\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t平均每笔滑点:\t120.0\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t平均每笔佣金:\t56.26\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t胜率\t\t38.17%\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t盈利交易平均值\t7,882.85\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t亏损交易平均值\t-4,953.34\n",
|
|
|
|
|
"2017-07-14 20:11:13.722000\t盈亏比:\t1.59\n"
|
2017-06-02 13:44:28 +00:00
|
|
|
|
]
|
2017-07-14 12:12:42 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"data": {
|
|
|
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAsgAAASZCAYAAADGqegeAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzs3Xl8VPW5P/DPJJkkJJM9ZN9IIGEJYUlQypIiimIt1avs\nolWorfRGq8iV2lsRrBVqJbb3gr9qaauXRba6VL2tt4iSAi4hCBEx7EsgAZJMlpkJM5nJzO+Ph5M5\nM5l9PUOe9+vFizCZTM7khORznnm+z1dmMplMYIwxxhhjjAEAwoJ9AIwxxhhjjEkJB2TGGGOMMcZE\nOCAzxhhjjDEmwgGZMcYYY4wxEQ7IjDHGGGOMiXBAZowxxhhjTERSAbmtrQ3Tpk3D2bNnceHCBSxc\nuBCLFi3C6tWr++6zY8cO3HfffZg/fz4+/fRTAIBOp8Pjjz+O+++/Hz/5yU/Q3t4OADh8+DDmzp2L\nhQsXYv369cF4SowxxhhjLMRIJiAbDAY899xziI6OBgCsWbMGy5Ytw+bNm2E0GrF79260trZi06ZN\n2L59OzZu3Ih169ZBr9fjrbfeQnFxMbZs2YK7774br776KgBg1apVqK6uxtatW1FfX4+GhoZgPkXG\nGGOMMRYCJBOQf/Ob32DBggVIS0uDyWTCsWPHU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feHh1A957RqgUgHDh3NA9rXubtq1UK32TV9ucbFlQG5vl8YkEnGLBQdk+8QBmf+vMcYYC7AbPiCb\nTCY899xzmD9/Ph588EE0NjbavmN7u/0KMkCh+K23gBEj6Je2FMLWjeTaNSAmhhZGurINs61Ks7BA\nD+gfPpVKaYRRcYuFVBc
|
|
|
|
|
"text/plain": [
|
|
|
|
|
"<matplotlib.figure.Figure at 0x123c1670>"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
"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",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"source": [
|
|
|
|
|
"# 显示前10条成交记录\n",
|
|
|
|
|
"for i in range(10):\n",
|
|
|
|
|
" print engine.tradeDict[str(i+1)].__dict__"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
2017-07-14 01:05:11 +00:00
|
|
|
|
"execution_count": null,
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"metadata": {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
2017-07-14 01:05:11 +00:00
|
|
|
|
"outputs": [],
|
2017-06-02 13:44:28 +00:00
|
|
|
|
"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",
|
|
|
|
|
"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
|
|
|
|
|
}
|