作者是五个题目党

2019-12-23 05:45栏目:威尼斯网站

importpandasasdfdf1=df.read_csv('G:/python/xingda/XAUUSD/XAUUSD-1H.csv',#此处为数据文件地址,请自行修改为本电脑的地址)df1['buy']=0df1['sell']=0df1['Balance']=0df1['累计投入资金']=0df1['每次买币数量']=0df1['币市值']=0df1['累计买币数量']=0#收盘价close1=df1['CLOSE']close1=close1.map(float)#10日最低价min1=close1.rolling(7).min()#10日最高价max1=close1.rolling(7).max()#涨幅gain=min1/max1ask1=df1['CLOSE']gain1=(close1.rolling(1).sum()-close1.rolling(1).sum())/close1#多单进场foriindf1.index:if(ask1.at[i]=max1.at[i]):df1['buy'].at[i]=10#空单进场foriindf1.index:if(ask1.at[i]=min1.at[i]):df1['sell'].at[i]=10df1['累计投入资金']=df1['buy'].cumsum()c_rate=0.002#手续费,回测一定要精确df1['每次买币数量']=df1['buy']/df1['CLOSE']*(1-c_rate)#每个周期买入币的数量,扣除了手续费df1['累计买币数量']=df1['每次买币数量'].cumsum()#累计买入币的数量df1['币市值']=df1['累计买币数量']*df1['CLOSE']#多单平仓foriindf1.index:ifdf1['每次买币数量'].at[i]0:df1['Balance'].at[i]=df1['每次买币数量'].at[i]*close1.at[i 7]#df1['buy']=0print(df1['Balance'].sum()),df1['累计投入资金']

版权声明:本文由威尼斯网站发布于威尼斯网站,转载请注明出处:作者是五个题目党