分享

#策略分享#熊市不用跑!【网格交易学习】年化收益36.128% | RiceQuant米筐量化社区 ...

 昵称36538943 2017-01-19
回测收益回测年化收益基准收益AlphaBetaSharpe最大回撤
44.459%44.459%4.583%0.40620.44751.146626.855%
  • 收益
    1个月(策略&基准)
    3个月(策略&基准)
    6个月(策略&基准)
    12个月(策略&基准)
  • 2015.01
    0.061    -0.057
    N/A    N/A
    N/A    N/A
    N/A    N/A
  • 2015.02
    0.019    0.066
    N/A    N/A
    N/A    N/A
    N/A    N/A
  • 2015.03
    0.044    0.125
    0.137    0.112
    N/A    N/A
    N/A    N/A
  • 2015.04
    0.005    0.152
    0.079    0.416
    N/A    N/A
    N/A    N/A
  • 2015.05
    0.051    0.011
    0.100    0.344
    N/A    N/A
    N/A    N/A
  • 2015.06
    -0.073    -0.119
    -0.015    0.084
    0.124    0.228
    N/A    N/A
  • 2015.07
    0.081    -0.110
    0.051    -0.203
    0.128    0.138
    N/A    N/A
  • 2015.08
    -0.064    -0.121
    -0.103    -0.337
    -0.002    -0.065
    N/A    N/A
  • 2015.09
    0.050    -0.047
    -0.022    -0.253
    -0.049    -0.223
    N/A    N/A
  • 2015.10
    0.108    0.072
    0.098    -0.077
    0.118    -0.262
    N/A    N/A
  • 2015.11
    0.130    0.026
    0.365    0.061
    0.163    -0.297
    N/A    N/A
  • 2015.12
    0.019    0.039
    0.243    0.132
    0.291    -0.130
    0.432    0.025
  • 阿尔法
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    0.029
    N/A
    N/A
    N/A
  • 2015.02
    0.052
    N/A
    N/A
    N/A
  • 2015.03
    0.010
    0.098
    N/A
    N/A
  • 2015.04
    -0.026
    -0.014
    N/A
    N/A
  • 2015.05
    0.004
    0.036
    N/A
    N/A
  • 2015.06
    -0.025
    -0.056
    0.065
    N/A
  • 2015.07
    0.034
    0.074
    0.075
    N/A
  • 2015.08
    0.058
    0.004
    -0.003
    N/A
  • 2015.09
    0.055
    0.105
    0.021
    N/A
  • 2015.10
    0.166
    0.167
    0.232
    N/A
  • 2015.11
    0.109
    0.286
    0.329
    N/A
  • 2015.12
    0.083
    0.095
    0.369
    0.403
  • 贝塔
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    0.029
    N/A
    N/A
    N/A
  • 2015.02
    0.052
    N/A
    N/A
    N/A
  • 2015.03
    0.010
    0.098
    N/A
    N/A
  • 2015.04
    -0.026
    -0.014
    N/A
    N/A
  • 2015.05
    0.004
    0.036
    N/A
    N/A
  • 2015.06
    -0.025
    -0.056
    0.065
    N/A
  • 2015.07
    0.034
    0.074
    0.075
    N/A
  • 2015.08
    0.058
    0.004
    -0.003
    N/A
  • 2015.09
    0.055
    0.105
    0.021
    N/A
  • 2015.10
    0.166
    0.167
    0.232
    N/A
  • 2015.11
    0.109
    0.286
    0.329
    N/A
  • 2015.12
    0.083
    0.095
    0.369
    0.403
  • 夏普比率
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    0.784
    N/A
    N/A
    N/A
  • 2015.02
    1.221
    N/A
    N/A
    N/A
  • 2015.03
    0.976
    2.016
    N/A
    N/A
  • 2015.04
    0.558
    1.056
    N/A
    N/A
  • 2015.05
    0.433
    1.396
    N/A
    N/A
  • 2015.06
    -0.692
    -0.749
    1.126
    N/A
  • 2015.07
    -0.273
    0.213
    0.773
    N/A
  • 2015.08
    -0.213
    -0.658
    -0.166
    N/A
  • 2015.09
    -0.359
    -0.157
    -0.297
    N/A
  • 2015.10
    0.851
    0.261
    0.288
    N/A
  • 2015.11
    0.956
    1.199
    0.416
    N/A
  • 2015.12
    0.791
    0.994
    0.789
    1.129
  • 索提诺比率
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    0.285
    N/A
    N/A
    N/A
  • 2015.02
    0.512
    N/A
    N/A
    N/A
  • 2015.03
    0.436
    0.851
    N/A
    N/A
  • 2015.04
    0.203
    0.405
    N/A
    N/A
  • 2015.05
    0.145
    0.506
    N/A
    N/A
  • 2015.06
    -0.268
    -0.279
    0.442
    N/A
  • 2015.07
    -0.196
    0.139
    0.460
    N/A
  • 2015.08
    -0.235
    -0.595
    -0.132
    N/A
  • 2015.09
    -0.396
    -0.176
    -0.283
    N/A
  • 2015.10
    1.049
    0.316
    0.306
    N/A
  • 2015.11
    1.507
    1.558
    0.475
    N/A
  • 2015.12
    0.906
    1.313
    0.939
    1.138
  • 信息比率
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    1.066
    N/A
    N/A
    N/A
  • 2015.02
    0.837
    N/A
    N/A
    N/A
  • 2015.03
    -1.743
    0.178
    N/A
    N/A
  • 2015.04
    -3.152
    -3.419
    N/A
    N/A
  • 2015.05
    -1.004
    -1.782
    N/A
    N/A
  • 2015.06
    0.315
    -0.567
    -0.467
    N/A
  • 2015.07
    1.159
    1.105
    -0.038
    N/A
  • 2015.08
    0.928
    0.956
    0.224
    N/A
  • 2015.09
    0.498
    0.911
    0.563
    N/A
  • 2015.10
    1.033
    0.790
    1.193
    N/A
  • 2015.11
    1.024
    1.527
    1.467
    N/A
  • 2015.12
    0.572
    0.675
    1.393
    1.085
  • 收益波动率
    1个月(策略&基准)
    3个月(策略&基准)
    6个月(策略&基准)
    12个月(策略&基准)
  • 2015.01
    0.034    0.106
    N/A    N/A
    N/A    N/A
    N/A    N/A
  • 2015.02
    0.041    0.119
    N/A    N/A
    N/A    N/A
    N/A    N/A
  • 2015.03
    0.038    0.084
    0.051    0.136
    N/A    N/A
    N/A    N/A
  • 2015.04
    0.039    0.091
    0.045    0.107
    N/A    N/A
    N/A    N/A
  • 2015.05
    0.039    0.129
    0.050    0.143
    N/A    N/A
    N/A    N/A
  • 2015.06
    0.058    0.188
    0.063    0.201
    0.082    0.242
    N/A    N/A
  • 2015.07
    0.113    0.237
    0.117    0.261
    0.125    0.285
    N/A    N/A
  • 2015.08
    0.183    0.250
    0.188    0.292
    0.194    0.329
    N/A    N/A
  • 2015.09
    0.244    0.197
    0.263    0.267
    0.270    0.335
    N/A    N/A
  • 2015.10
    0.251    0.118
    0.293    0.209
    0.314    0.333
    N/A    N/A
  • 2015.11
    0.213    0.110
    0.286    0.146
    0.342    0.327
    N/A    N/A
  • 2015.12
    0.155    0.113
    0.223    0.131
    0.345    0.298
    0.354    0.384
  • 最大回撤
    1个月
    3个月
    6个月
    12个月
  • 2015.01
    0.012
    N/A
    N/A
    N/A
  • 2015.02
    0.015
    N/A
    N/A
    N/A
  • 2015.03
    0.022
    0.022
    N/A
    N/A
  • 2015.04
    0.032
    0.032
    N/A
    N/A
  • 2015.05
    0.022
    0.032
    N/A
    N/A
  • 2015.06
    0.094
    0.094
    0.094
    N/A
  • 2015.07
    0.133
    0.133
    0.133
    N/A
  • 2015.08
    0.190
    0.190
    0.190
    N/A
  • 2015.09
    0.269
    0.269
    0.269
    N/A
  • 2015.10
    0.178
    0.269
    0.269
    N/A
  • 2015.11
    0.081
    0.178
    0.269
    N/A
  • 2015.12
    0.090
    0.090
    0.269
    0.269

import pandas as pd import numpy as npfrom datetime import datetime, timedeltadef init(context): context.commission = 0 context.stocks = [] context.info = {} context.flag = -1 context.holdSize = 5 context.industry = ['I64', 'I65'] context.selectByIdt = True # 多空步长 context.inte = {'long':0.1,'short':-0.05} # context.tgtValue = [12,6,2,0,8,14,18,20] context.tgtValue = [10,8,4,2,0,6,12,16,18,20] context.c = 5 context.unitCash = 0 context.period = 130def getStkVar(stk) : #获取某只股票的波动率 his = history(180,'1d','close')[stk].values arr = np.array(his) sum1 = arr.sum() arr2 = arr*arr sum2 = arr2.sum() n = len(arr) mean = sum1/n var =sum2/n - mean**2 return var def doSelect (context, bar_dict): for stk in context.info.keys(): order_target_value(stk, 0) context.info = {} context.unitCash = context.portfolio.portfolio_value/(context.holdSize*20) stocks = [] for i in context.industry : stocks += industry(i) stocks = [stk for stk in stocks if stk in context.peBelow50] # stocks = index_components('000905.XSHG', date=None, country='cn') # stocks = index_components('000300.XSHG', date=None, country='cn') dic = {} for stk in stocks: dic[stk] = getStkVar(stk) s = pd.Series(dic) s.sort(ascending=False) context.stocks = s.index[:10] context.stocks = [stk for stk in context.stocks if not is_suspended(stk)] context.stocks = context.stocks[:context.holdSize] c = int(len(context.tgtValue)/2) prod = lambda x,i,n:x*(1+i*n) for stk in context.stocks: stk1 = {} stk1['initPrice'] = bar_dict[stk].close stk1['buy_price'] = [prod(stk1['initPrice'],context.inte['short'],n) for n in range(1,c+1)] stk1['sell_price'] = [prod(stk1['initPrice'],context.inte['long'],n) for n in range(1,c+1)] stk1['curValue'] = 0 context.info[stk]=stk1 def before_trading(context, bar_dict): context.flag +=1 if context.selectByIdt : fundamental_df = get_fundamentals( query().filter( fundamentals.eod_derivative_indicator.pe_ratio <50, fundamentals.eod_derivative_indicator.pe_ratio >0 ) ) context.peBelow50 = fundamental_df.columns.values# 你选择的证券的数据更新将会触发此段逻辑,例如日或分钟历史数据切片或者是实时数据切片更新def handle_bar(context, bar_dict): # 开始编写你的主要的算法逻辑 now = context.now if context.flag%context.period==0 and now.hour==9 and now.minute==31: doSelect(context, bar_dict) print (context.info) tgtValue = context.tgtValue for stk in context.info.keys(): info = context.info[stk] curPrice = bar_dict[stk].close i = context.c-1 while(i>=0): if curPrice>=info['sell_price'][i] and info['curValue']>tgtValue[i] : curValue = context.info[stk]['curValue'] order_value(stk, (tgtValue[i]-curValue)*context.unitCash) context.info[stk]['curValue'] = tgtValue[i] print ('卖出',curValue-tgtValue[i], '份', stk) break i -= 1 i = context.c-1 while(i>=0): if curPrice<=info['buy_price'][i] and info['curValue']'curValue'] order_value(stk, (tgtValue[i-context.c]-curValue)*context.unitCash) context.info[stk]['curValue'] = tgtValue[i-context.c] print ('买入',tgtValue[i-context.c]-curValue, '份', stk) break i -= 1

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约