Пример #1
0
def fl_ordercsv():
    '''函数 ---分离策略结果集'''
    op = file_op()
    cl_df = op.get_txt('order.csv')
    #策略名去重
    clname_li11 = cl_df.clname.values.tolist()
    clname_li = (list(set(clname_li11)))

    for na in clname_li:
        files1 = '{}.txt'.format(na[-3:])
        df = cl_df[cl_df.clname == na]
        df.to_csv(files1)

    return 0
Пример #2
0
def fl_ordercsv():
	'''函数 ---分离策略结果集'''
	op=file_op()
	cl_df=op.get_txt('order.csv')
	#分类文件名去重
	fil=list(set(cl_df.files.values.tolist()))
	#print(fil)

	for na in fil:
		files1=na+'.txt'
		df=cl_df[cl_df.files==na]
		#print(na,files1)
		#print(df.head())
		df.to_csv(files1)
	return 0
Пример #3
0
    def getbasc(self, code1list):
        '''函数--获取基础信息,根据列表['000001','all']'''
        csv_path = 'd:/stock_csv/{}.csv'.format('basc')
        if 'all' in code1list: print('获取所有Stock')
        jk = file_op()
        df = jk.get_from_csv(csv_path)
        st_list = []
        co_list = df.index.values.tolist()

        for co in co_list:
            s_code = getSixDigitalStockCode(co)

            if s_code not in code1list and 'all' not in code1list:
                continue
            s_name = df[df.index == co].name.values[-1]
            s_totals = df[df.index == co].totals.values[-1]
            s_hy = df[df.index == co].industry.values[-1]
            s = Stock(code=s_code, name=s_name, hangye=s_hy, totals=s_totals)
            st_list.append(s)
        #返回Stock list
        return st_list
Пример #4
0
def get_all_orderresult():
	'''函数--获取给点集合代码所有策略'''
	order_js_list=[]
	tt=[]
	jk=jiekou()

	#大名单列表存入tt
	op=file_op()
	dmd_li1=op.get_txt('sv_dmd1.csv').code.values.tolist()
	for code in dmd_li1:
		co=getSixDigitalStockCode(code)
		tt.append(co)

	#tt=['600359','600609','002498',	'002238','300415','000987',	'600598','000931']#tt=['all']
	#tt=['300216','002238','300415','000987',	'600598','000931']
	st_list=jk.getbasc(tt)#获取符合的代码Stock,,tt=['all']
	#容错
	if len(st_list)==0:
		print('没有符合的代码')
		return 0
	#获取所有策略结果
	for s in st_list:
		jg_li=getorderresult(s)#获取策略结果
		order_js_list.extend(jg_li)#集合所有结果

	#结果集存入order.csv
	#加入时间节点
	gxrq = datetime.datetime.now().strftime('%Y%m%d')
	gxsj = datetime.datetime.now().strftime('%H%M')
	gx=gxrq+gxsj
	
	columns_li=[ 'code', 'name','cl','cljg','qz','files']
	if len(order_js_list)>0:
		if len(order_js_list[-1])!=len(columns_li):
			print("数据列数量不等")
		df=DataFrame(order_js_list,columns=columns_li)
		df['gxsj']=str(gx)
		df.to_csv('order.csv')#为增加方式

	return 0
Пример #5
0
def bakanddraw(code,typ,start,end,path):
	'''取重要数据备份并保存图片'''
	kk=jiekou()
	op=file_op()
	
	ktype=typ
	df=kk.getkl(code,ktype)
	if end>start and end<len(df):
		df=df[start:end]
	
	dat11=df.iloc[-1:].date.values[0].split()[0]
	#保存路径和文件
	file1='{0}-{1}-bak-{2}.csv'.format(code,ktype,dat11)
	df.to_csv(file1)
	print(file1)

	hh=gu_zb(0)
	name=''

	#取4个类型的CCi
	if df.empty:
		return 0
	cci=hh.cci(df)
	ln=len(cci)
	
	total=ln-14
	if ln<total:
		total=ln
	PLUS_DI,MINUS_DI,ADX,ADXR=hh.dmi(df)
	df=df[-total:]
	cci=cci[-total:]
	MINUS_DI=MINUS_DI[-total:]
	PLUS_DI=PLUS_DI[-total:]
	ADX=ADX[-total:]
	ADXR=ADXR[-total:]
	
	#4个类型的顶点
	#画出最后3条线

	fig, ax = plt.subplots(3, 1, figsize=(16,8))
	ax[0].set_title(name+code+'--'+ktype,fontproperties = 'SimHei',fontsize = 20)
	ax[1].plot(cci,'r')
	ax[2].plot(ADX,'r')
	ax[2].plot(PLUS_DI,'y')
	ax[2].plot(MINUS_DI,'b')
	ax[2].plot(ADXR,'g')
	ax[2].axhline(y=80, color='b', linestyle=':')
	ax[2].axhline(y=50, color='b', linestyle=':')
	ax[2].axhline(y=20, color='b', linestyle=':')
	#取顶点
	up_li2=hh.gjbc(df)
	dw_li2=hh.gj_d_bl(df)

	print(up_li2)
	if len(up_li2)>4:
		up=up_li2[-4:]
	else:
		up=up_li2

	if len(dw_li2)>2:
		dw=dw_li2[-2:]
	else:
		dw=dw_li2

	for u in up:
		y1=u[1]
		y2=u[3]
		x1=u[0]
		x2=u[2]
		k=(y2-y1)/(x2-x1)
		if k>0:continue
		b=y2-k*x2
		c1=(300-b)/k
		c2=(-200-b)/k
		if c2>total:
			c2=total
		if c1<0:
			c1=0
		l_x=np.linspace(c1,c2,10)
		y=k*l_x+b
		ax[1].plot(l_x,y,'-.y')
	for u in dw:
		y1=u[1]
		y2=u[3]
		x1=u[0]
		x2=u[2]
		k=(y2-y1)/(x2-x1)
		if k<0:continue
		b=y2-k*x2
		c1=(200-b)/k
		c2=(-350-b)/k
		if c1>total:
			c1=total
		if c2<0:
			c2=0
		l_x=np.linspace(c1,c2,10)
		y=k*l_x+b
		ax[1].plot(l_x,y,'-.y')
	#画K线
	mpf.candlestick2_ochl(ax=ax[0],opens=df["open"].values.tolist(), closes=df["close"].values, highs=df["high"].values, lows=df["low"].values,width=0.7,colorup='r',colordown='g',alpha=0.7)
	ax[1].axhline(y=100, color='b', linestyle=':')
	ax[1].axhline(y=-100, color='b', linestyle=':')
	#文字
	plt.style.use('ggplot')
	plt.show()
	return 1
Пример #6
0
def aiyb():
	tt=[]
	jk=jiekou()
	#大名单列表存入tt
	op=file_op()
	dmd_li1=op.get_txt('sv_dmd1.csv').code.values.tolist()
	for code in dmd_li1:
		co=getSixDigitalStockCode(code)
		tt.append(co)
	tt=['002498','600359','600609']
	st_list=jk.getbasc(tt)#获取符合的代码Stock,,tt=['all']
	iii=0
	#str_pcci=(co.p_cci).__doc__
	#print(str_pcci)
	#return 0
	for s in  st_list:
		iii+=1
		#获取k线记基础指标
		szb=stockzb(s)
		d=D_kl()#日线修饰,实时数据
		#应用策略
		szb.decorator(d)#日线修饰
		szb.getk()#获取k线

		#详细分析
		co=cciorder(szb)
		b=co.cci_dmi()
		md1=[]
		for x in b:
			
			if x[0]=='dw' and x[3]=='cci':
				
				md1.append(x[1])
			if x[0]=='dw' and x[8]=='cci':
			
				md1.append(x[6])
		code2=co.getcode()
		name=co.getname()
		#md1=[]
		yb_li=[]
		yb_li30=[]
		for xh in md1:
			
			l_cci=co.p_cci(xh)
			l_adx=co.p_adx(xh)
			l_vol=co.p_vol(xh)
			l_macd=co.p_macd(xh)
			l_boll=co.p_boll(xh)
			l_gj=co.p_gj(xh)
			l_tj=co.tj(xh)
			date_xh=co.df.loc[xh].date
			tjlb=0
			if l_tj[2]<=0:
				tjlb=-1
			elif l_tj[2]>0 and l_tj[2]<10:
				tjlb=1
			elif l_tj[2]>=10 and l_tj[2]<20:
				tjlb=2
			elif l_tj[2]>=20:
				tjlb=3
			else:
				tjlb=0
	
			yb_li30.append([code2,date_xh]+l_cci[1:]+l_adx[1:]+l_macd[1:]+l_boll[1:]+l_vol+l_gj+[tjlb])
			#elif l_tj[1]>10 or l_tj[2]>10 and l_tj[3]>0:
				#print(l_tj)
				#yb_li.append([code2,date_xh]+l_cci+l_adx+l_macd+l_boll+l_vol+l_gj+l_tj)
			#print(l_cci+l_adx+l_macd+l_boll+l_vol+l_gj+l_tj)
		#print(iii,len(yb_li),yb_li30)
		#df=DataFrame(yb_li)
		#df.to_csv('d:/aiyb10.csv',mode='a',header=False,encoding='utf-8')
		gxrq = datetime.datetime.now().strftime('%Y-%m-%d')
		files1='d:/aiyb{}.csv'.format(gxrq)
		df2=DataFrame(yb_li30)
		df2.to_csv(files1,mode='a',header=False,encoding='utf-8')

	return 0
Пример #7
0
 def get_date(self):
     file1 = self.file1
     fo = file_op()
     df = fo.get_from_csv(file1)
     #df=''
     return df