以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  [求助]请教如何求出单位时间内的平均浮盈  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=63798)

--  作者:saintlucifer
--  发布时间:2014/4/11 14:16:23
--  [求助]请教如何求出单位时间内的平均浮盈
前几天 @jinzhe 老大给编写了一个求全体交易平均浮盈的语句,请问如何修改成求单位时间内(例如n个月内)的平均浮盈呢?附上老大的语句:

hh:hhv(openprofit,enterbars+1);

variable:n=0,k=0;

if 平多条件 and holding>0 then begin

   sell.......;

   N:=N+hh;

   k:=k+1;

end

 

if 平空条件 and holding<0 then begin

   sellshort........;

   n:=n+hh;

   K:=k+1;

end

 

每次最大浮赢是HH

总和是N

平均是N/K


--  作者:jinzhe
--  发布时间:2014/4/11 14:29:43
--  

hh:hhv(openprofit,enterbars+1);

variable:n=0,k=0;

if 平多条件 and holding>0 then begin

   sell.......;

   N:=N+hh;

   k:=k+1;

end

 

if 平空条件 and holding<0 then begin

   sellshort........;

   n:=n+hh;

   K:=k+1;

end

 

if month<>ref(month,1) then n:=0;

 

这个是每个月开始就把全局变量重置为0,算作是每月独立计算


--  作者:saintlucifer
--  发布时间:2014/4/11 14:52:32
--  
如果我想每n个月独立计算一次,是不是就改成

if month<>ref(month+n-1,1) then n:=0;

--  作者:jinzhe
--  发布时间:2014/4/11 15:13:04
--  

不是,要判断跨年的。比较复杂,就举个2个月的例子

hh:hhv(openprofit,enterbars+1);

variable:n=0,k=0;

variable:yuefen=0;

 

if 开多条件 and holding=0 then begin

    buy........;

    yuefen:=month;

end

 

if 开空条件 and holding=0 then begin

    buyshort.......;

    yuefen:=month;

end

 

if 平多条件 and holding>0 then begin

   sell.......;

   N:=N+hh;

   k:=k+1;

end

 

if 平空条件 and holding<0 then begin

   sellshort........;

   n:=n+hh;

   K:=k+1;

end

 

首先就如上面写的,加了一个记录月份的全局变量

 

 

然后判断当前月份:

if (month=3 or month=4 or...........or month=12) and month=yuefen+2 then n:=0 //这里简略的写了,用户一定不能简略,3-12月全部写齐

if month=1 and yuefen=11 then n:=0; 

if month=2 and yuefen=12 then n:=0;

 

这里就要判断跨年,不能和3月-12月写成一样的,1月2月独立判断

 

 

 

 

类似的3个月,4个月,都是要像这样进行枚举判断

 


--  作者:saintlucifer
--  发布时间:2014/4/11 15:24:01
--  
好的,收到~~~~~~