第10行
df1['c_ma30'] = TA.SMA(df1,30,column='close')#原来的跟21重合了,搞错了
第13
#21日均线的斜率是否大于0,来判断是否盘整等
df1['ma21xielv_d0_flag'] = np.where(df1['ma21xielv']>=0,1,0)
df1['d21_0_count'] = ta.SUM(df1['ma21xielv_d0_flag'], timeperiod=15)
#盘平df1['d21_0_count'] = ta.SUM(df1['ma21xielv_d0_flag'], timeperiod=5),表示的是21日均线斜率在5天内大于0的天数
df1['panping'] = np.where((df1['pan_nei_14count']>9) & (df1['d21_0_count']>2) & (abs(df1['ma21xielv'])<0.12),1,0)
#长箱体突破
df1['xttp'] = np.where((df1['panping']==1) & (df1['close']>df1['c_up_12per']) & (df1['close']>df1['close'].shift(2)) & (df1['close']>df1['close'].shift(3)),1,0)
#盘升,后一日比前一日的收盘价高,15个里面有多个这样的,且最后一日的比较高,14日的斜率为正,比10个以上都高,盘跌类似 df1 = df1.drop(['hdq_flag','qdh_flag','hdq_flag_count15','qdh_flag_count15','c_up_12per','c_down_12per','c_shitf1_nei_flag','c_shitf2_nei_flag','c_shitf3_nei_flag','c_shitf4_nei_flag','c_shitf5_nei_flag','c_shitf6_nei_flag','c_shitf7_nei_flag','c_shitf8_nei_flag','c_shitf9_nei_flag','c_shitf1_nei_flag','c_shitf10_nei_flag','c_shitf11_nei_flag','c_shitf12_nei_flag','c_shitf13_nei_flag','c_shitf0_nei_flag'],axis=1) #先排序,不然shift之类的就会错 欢迎分享,转载请注明来源:内存溢出
#中间无大跌,无大涨,不超过1次
df1['hdq_flag'] = np.where((df1['high'])>(df1['high'].shift(1)),1,0)
df1['qdh_flag'] = np.where((df1['low'])<(df1['low'].shift(1)),1,0)
df1['hdq_flag_count15'] = ta.SUM(df1['hdq_flag'], timeperiod=15)
df1['qdh_flag_count15'] = ta.SUM(df1['qdh_flag'], timeperiod=15)
df1['pansheng_flag'] = np.where((df1['hdq_flag_count15']>9) & (df1['d21_0_count']>9) & (df1['close']>df1['close'].shift(14)) ,1,0)
df1['pandie_flag'] = np.where((df1['qdh_flag_count15']>9) & (df1['d21_0_count']<5) & (df1['close']
df1 = df1.sort_values(by=['ts_code','date'],ascending=True)
#重点对多头进行处理,控制多头的天数
df1['duotou'] = np.where((df1['c_ma5']-df1['c_ma21']>0) & (df1['c_ma21']-df1['c_ma30']>0) & (df1['ma21xielv']>0),1,0)#np.where可以实现casewhen同等功能·1
df1['duotou_5'] = ta.SUM(df1['duotou'], timeperiod=5)
df1['duotou_10'] = ta.SUM(df1['duotou'], timeperiod=10)
df1['duotou_5_10'] = df1['duotou_10'] - df1['duotou_5']
df1['duotou_count'] = np.select([((df1['duotou_5_10']>0) & (df1['duotou_5']==0)),
((df1['duotou_5_10']==0) & (df1['duotou_5']==0)),
((df1['duotou_5_10']>0) & (df1['duotou_5']>0)),
((df1['duotou_5_10']==0) & (df1['duotou_5']>0))],[-1,0,1,2])
df1 = df1.drop(['duotou','duotou_5','duotou_10','duotou_5_10'],axis=1)
评论列表(0条)