我想编写一个股票交易模型
N:=INTPART((7-C)/0.05);
T=((7-C)/0.05;
买入条件:T=N,并且现在的价格低于上次买入的价格,买入量为10*N;
卖出条件:价格等于1.
大概是这么个意思,请老师给我帮帮忙
INTPART
这个函数什么意思?
n:=round((7-c)/0.05);
T:=(7-C)/0.05;
variable:m=0;
if holding=0 and t=n and m=0 then begin
buy(1,10*n,market);
m:=1;
end
if holding=0 and m=1 and t=0 and c<enterprice then buy(1,10*n,market);
if h>=1 and l<=1 then sell(1,0,market);
老师,这里不需要四舍五入,只需要取整就可以了。
n:=INTPART((7-c)/0.05);
T:=(7-C)/0.05;
if date=1120502 and time=093100 then begin
buy(1,1,THISCLOSE);
end
if t=n and c<enterprice then buy(1,10*n,THISCLOSE);
if h>=1 and c<=1 then sell(1,1,THISCLOSE);
修改之后的程序差不多是这个样子。
但是在计算的时候,出了问题。应该是每0.05就买入一次的,但是实际上每隔0.25才买入一次。还请老师帮我看看问题出在哪里
取整,有向上取整,向下取整,四舍五入取整,这个不是随便的问题,要定义好
推理 (7-c)/0.05= (7-c)*20/(0.05*20)=(7-c)*20/1
就是推断(7-c)*20是不是整数
而根据上面的推断,
求某个数是不是整数的办法是
mod((7-c)*20*10,10)=0
所以你的下单条件要修改成
T:=(7-C)/0.05;
variable:m=0;
cond:=mod(t*20*10,10)=0;
if holding=0 and cond and m=0 then begin
buy(1,10*n,market);
m:=1;
end
if holding=0 and m=1 and cond and l<enterprice then buy(1,10*n,market);
if h>=1 and l<=1 then sell(1,0,market);