現貨期權合約量化/量化合約/秒合約/永續合約/交易所繫統開發(開發案例及原始碼)

xiaofufu發表於2023-02-23

  “量化交易”有著兩層含義:


  【一】是從狹義上來講,是指量化交易的內容,將交易條件轉變成為程式,自動下單;


  【二】是從廣義上來講,是指系統交易方法,就是一個整合的交易系統。


  即為根據一系列交易條件,智慧化輔助決策體系,將豐富的從業經驗與交易條件相結合,在交易過程管理好風險控制。


  #繪製指定程式碼價格圖


  def plot_pct(ts_code,index_array,pct_array,begin_count,end_count=-1,writefilename='temp.png'):


  df=load_data(ts_code)


  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()


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2936753/,如需轉載,請註明出處,否則將追究法律責任。

相關文章