合約量化開發(案例版)丨合約量化系統開發(技術說明)丨合約量化系統原始碼規則

xiaofufu發表於2023-02-23

  “量化交易”有著兩層含義:一是從狹義上來講,是指量化交易的內容,將交易條件轉變成為程式,自動下單;二是從廣義上來講,是指系統交易方法,就是一個整合的交易系統。即為根據一系列交易條件,智慧化輔助決策體系,將豐富的從業經驗與交易條件相結合,在交易過程管理好風險控制。


  #繪製所有程式碼價格圖


  def all_plot_pct(codes,names,days,begin_count,end_count=-1):


  path='./image/'


  Dir=Path(path)


  if not Dir.exists():


  os.mkdir(Dir)


  #file=path+code


  #df=pd.read_csv(file)

  #codes=df['ts_code'].values[begin_count:end_count]


  i=0


  count_earnings=0


  count_suc=0


  count_fail=0


  count_hold_days=0


  for code,name in zip(codes,names):


  i=i+1


  earnings,suc,fail,index_array,pct_array,hold_days=test(code,name=name,days=days,begin_count=begin_count,end_count=end_count)


  if suc==-1:


  continue


  count_hold_days=count_hold_days+hold_days


  name=str.replace(name,'*','')


  if earnings>0:


  file_dir=path+'AAA_%s_%s%d%d++%.1f++%.1f.png'%(code,name,suc,fail,suc*100/(fail+suc+1),earnings)


  elif earnings<-0.01:


  file_dir=path+'BBB_%s_%s%d%d——%.1f——%.1f.png'%(code,name,suc,fail,suc*100/(fail+suc+1),earnings)


  else:


  file_dir=path+'OOO_%s_%s%d%d——%.1f——%.1f.png'%(code,name,suc,fail,suc*100/(fail+suc+1),earnings)


  plot_pct(code,index_array,pct_array,begin_count=begin_count,end_count=end_count,writefilename=file_dir)


  print("codes%s%s earnings%.2f"%(code,name,earnings))


  count_earnings=count_earnings+earnings


  count_suc=count_suc+suc


  count_fail=count_fail+fail


  print('count_suc',count_suc)


  print('count_fail',count_fail)


  print('count_earnings','%.1f'%count_earnings)


  print("suc",'%.1f'%(count_suc/(count_suc+count_fail+1)*100))


  print("earnings pre",i,'%.1f'%(count_earnings/(count_suc+count_fail+1)),count_hold_days)


  #回測指定程式碼運作結果


  def test(ts_code,name,days,begin_count,end_count,low_pct=-10,heigh_pct=20,isdebug=False):


  #print(ts_codes,'kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk')


  df=load_data(ts_code)


  #if end_count==0:


  date=df['trade_date'].values


  close=df['close'].values


  change=df['change'].values


  pct_change=df['pct_chg'].values


  price=15


  if len(close)<2:


  return-1,-1,-1,-1,-1,-1


  if close[-1]<price:


  return-1,-1,-1,-1,-1,-1


  index_array=np.array([])


  pct_array=np.array([])


  suc=0


  fail=0


  hold_days=0


  earnings=0


  power=0.0


  print(ts_code,name)


  #low_pct=-5


  #heigh_pct=5


  #for i in range(begin_count+1,end_count):


  i=begin_count


  while i>=begin_count and i<end_count:


  i=i+1


  if i>=end_count:


  break


  if i<len(pct_change)*-1+1:


  continue


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

相關文章