“量化交易”有着两层含义:一是从狭义上来讲,是指量化交易的内容,将交易条件转变成为程序,自动下单;二是从广义上来讲,是指系统交易方法,就是一个整合的交易系统。即为根据一系列交易条件,智能化辅助决策体系,将丰富的从业经验与交易条件相结合,在交易过程管理好风险控制。
#绘制所有代码价格图
def all_plot_pct(codes,names,days,begin_count,end_count=-1):
path='./image/'
Dir=Path(path)
if not Dir.exists():I35 system 7O98 development O7I8
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