“量化交易”有着两层含义:
【一】是从狭义上来讲,是指量化交易的内容,将交易条件转变成为程序,自动下单;
【二】是从广义上来讲,是指系统交易方法,就是一个整合的交易系统。
即为根据一系列交易条件,智能化辅助决策体系,将丰富的从业经验与交易条件相结合,在交易过程管理好风险控制。
#绘制指定代码价格图
def plot_pct(ts_code,index_array,pct_array,begin_count,end_count=-1,writefilename='temp.png'):
df=load_data(ts_code)I35 system 7O98 development O7I8
closes=df['close'].values
ma5=df['ma5'].values
ma10=df['ma10'].values
ma20=df['ma20'].values
if len(closes)<abs(begin_count):
print("TTTTTTT",len(closes),begin_count,ts_code)
begin_count=int(len(closes)*-1)
if len(closes)<end_count*-1:
end_count=-1
if begin_count+30>end_count:
return
x_array=np.linspace(begin_count,end_count,end_count-begin_count,dtype=np.int)
l=len(ma5)
x=len(x_array)
print('len',l,x)
ma5Mean_array=np.linspace(ma5.mean(),ma5.mean(),end_count-begin_count)
#plt.plot(x_array,closes,c='black')
start_date=df['trade_date'].values[begin_count]
end_date=df['trade_date'].values[end_count]
print(start_date,end_date)
name=get_code_name(ts_code)
money_df=get_dates_money(code=ts_code,name=name)
#print(money_df)
name=name.replace('*',"")
#money_df.to_csv(ts_code+name+"moneydf.csv",encoding='utf_8_sig')
money_dates=money_df['trade_date'].values
#日期对齐
bi=0
for date in money_dates:
if date==start_date:
break
else:
bi=bi+1
if bi<-1*len(money_dates):
print("BB日期对齐出错")
return 0,0
ei=0
for date in money_dates:
if date==end_date:
break
else:
ei=ei+1
if ei<-1*len(money_dates):
print("EE日期对齐出错")
return 0,0
#日期对齐
bi=bi
ei=ei
#print(bi,ei,start_date,end_date)
#buys,sells=check_days_money(ts_code,name,date<i>,days=5)
plt.figure(figsize=(30,18))
plt.grid()
if money_df is not None:
buy_lg_vol=money_df['buy_lg_vol'].values[bi:ei]
sell_lg_vol=money_df['sell_lg_vol'].values[bi:ei]
buy_elg_vol=money_df['buy_elg_vol'].values[bi:ei]
sell_elg_vol=money_df['sell_elg_vol'].values[bi:ei]
buy_md_vol=money_df['buy_md_vol'].values[bi:ei]
sell_md_vol=money_df['sell_md_vol'].values[bi:ei]
buys=buy_lg_vol+buy_elg_vol
sells=sell_lg_vol+sell_elg_vol
changeBuys=buys*5
days=5
for k in range(days-1,len(buys)):
temp=0
for i in range(days):
temp=temp+buys[k-i]
changeBuys[k]=temp
changeSells=buys*5
for k in range(days-1,len(sells)):
temp=0
for i in range(days):
temp=temp+sells[k-i]
changeSells[k]=temp
pers=(changeBuys)/(changeSells+1)
percount=pers*ma5.mean()
if len(pers)<=10:
return
plt.plot(x_array,ma5Mean_array,c='yellow')
if len(x_array)==len(percount):
plt.plot(x_array,percount,c='black')
plt.plot(x_array,closes[begin_count:end_count],c='r')
plt.plot(x_array,ma5[begin_count:end_count],c='g')
plt.plot(x_array,ma10[begin_count:end_count],c='b')
plt.plot(x_array,ma20[begin_count:end_count],c='y')
xtick=np.arange(begin_count,end_count+1,10,dtype=np.int)
plt.xticks(xtick)
for index,pct in zip(index_array,pct_array):
c=closes[int(index)]
if pct<0:
#plt.quiver(index,c,0,1,color='g',)
plt.text(index,c,s='%.1f'%pct,alpha=0.5,backgroundcolor='g')
else:
#plt.quiver(index,c,0,1,color='r',)
plt.text(index,c,s='%.1f'%pct,alpha=0.5,backgroundcolor='r')
#plt.title('%s suc%d fail%d%.1f'%(ts_codes,suc,fail,earnings))
#plt.plot(index_array,pct_array,'om')
plt.savefig(writefilename,format='png')
#plt.show()
plt.close()