根据阿火密笈,以下的语句为母本
十八、 自己在模型里计算盈亏情况的一个简便方法。
从另外一个角度说明了金字塔的测试结果是正确的。
方法示例如下:(这里股指上的简单的均线系统为例)
variable:sumwealth=0;
ma10:=ma(c,5);
ma25:=ma(c,25);
sxf:=0.01/100;//手续费0.01%
if holding>0 and ma10<ma25 then begin
sell(1,1,thisclose);
sumwealth:=sumwealth+1*c*300*(1-sxf);//卖出时减去交易额
end
if holding<0 and ma10>ma25 then begin
sellshort(1,1,thisclose);
sumwealth:=sumwealth-1*c*300*(1+sxf);//买入时加上交易额
end
if holding=0 and ma10>ma25 then begin
buy(1,1,thisclose);
sumwealth:=sumwealth-1*c*300*(1+sxf);
end
if holding=0 and ma10<ma25 then begin
buyshort(1,1,thisclose);
sumwealth:=sumwealth+1*c*300*(1-sxf);
end
zichan:sumwealth+holding*c*300-abs(holding)*c*300*sxf,noaxis;
按照自己的策略喜欢用的格式改写了一下,得不出需要的zichan数值了,请教问题出在哪里?
variable:sumwealth=0;
ma10:ma(c,10);
ma25:ma(c,25);
BKK:=holding=0 and ma10>ma25;
SPP:=holding>0 and ma10<ma25;
SKK:=holding=0 and ma10<ma25;
BPP:=holding<0 and ma10>ma25;
手数:=1;
SELL(spp,手数, thisclose);
SELLSHORT(bpp,手数,thisclose);
BUY(bkk and state=0,手数,thisclose);
BUYSHORT(Skk and state=0,手数,thisclose);
sxf:=0.01/100;//手续费0.01%
if spp then begin
sumwealth:=sumwealth+手数*c*300*(1-sxf);//卖出时减去交易额
end
if bpp then begin
sumwealth:=sumwealth-手数*c*300*(1+sxf);//买入时加上交易额
end
if bkk and state=0 then begin
sumwealth:=sumwealth-手数*c*300*(1+sxf);
end
if Skk and state=0 then begin
sumwealth:=sumwealth+手数*c*300*(1-sxf);
END
zichan:sumwealth+holding*c*300-abs(holding)*c*300*sxf,noaxis;
但是为什么我的写法对图表中的交易信号并没有影响呢?不影响交易啊
看到不一样有阿火的程序里的ma10实际是5周期均线,如果改成ma10:=ma(c,10),同时我的开仓下单指令简单用cross函数的话,图表信号是完全一致的,但为何zich算出来还是大大不同呢?详细源码如下
谢谢
阿火:方法示例如下:(这里股指上的简单的均线系统为例)
variable:sumwealth=0;
ma10:=ma(c,10);
ma25:=ma(c,25);
sxf:=0.01/100;//手续费0.01%
if holding>0 and ma10<ma25 then begin
sell(1,1,thisclose);
sumwealth:=sumwealth+1*c*300*(1-sxf);//卖出时减去交易额
end
if holding<0 and ma10>ma25 then begin
sellshort(1,1,thisclose);
sumwealth:=sumwealth-1*c*300*(1+sxf);//买入时加上交易额
end
if holding=0 and ma10>ma25 then begin
buy(1,1,thisclose);
sumwealth:=sumwealth-1*c*300*(1+sxf);
end
if holding=0 and ma10<ma25 then begin
buyshort(1,1,thisclose);
sumwealth:=sumwealth+1*c*300*(1-sxf);
end
zichan:sumwealth+holding*c*300-abs(holding)*c*300*sxf,noaxis;
按照自己的策略喜欢用的格式改写了一下,得不出需要的zichan数值了,请教问题出在哪里?
variable:sumwealth=0;
ma10:ma(c,10);
ma25:ma(c,25);
BKK:=cross(ma10,ma25);
SPP:=holding>0 and ma10<ma25;
SKK:=cross(ma25,ma10);
BPP:=holding<0 and ma10>ma25;
手数:=1;
SELL(spp,手数, thisclose);
SELLSHORT(bpp,手数,thisclose);
BUY(bkk and state=0,手数,thisclose);
BUYSHORT(Skk and state=0,手数,thisclose);
sxf:=0.01/100;//手续费0.01%
if spp then begin
sumwealth:=sumwealth+手数*c*300*(1-sxf);//卖出时减去交易额
end
if bpp then begin
sumwealth:=sumwealth-手数*c*300*(1+sxf);//买入时加上交易额
end
if bkk and state=0 then begin
sumwealth:=sumwealth-手数*c*300*(1+sxf);
end
if Skk and state=0 then begin
sumwealth:=sumwealth+手数*c*300*(1-sxf);
END
zichan:sumwealth+holding*c*300-abs(holding)*c*300*sxf,noaxis;
1.首先在我本地测试中,可以看到k线图最前端,少了一笔交易,并不是所谓的信号一样
2.其次后面信号的差不多,但是中间的变量计算就不一样了,有些信号是不交易的,因为holding判断的存在,所以不交易,sumwealth也就不计算,但是你写的只判断条件又不判断持仓,这个时候当条件满足但是持仓不满足的情况下,交易信号是没有的,但是sumwealth却被累加计算了