以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  [讨论]交易函数可否统计过去一段时间内的平均盈亏等数据  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=65829)

--  作者:choir2001
--  发布时间:2014/6/5 11:08:22
--  [讨论]交易函数可否统计过去一段时间内的平均盈亏等数据
比如过去3个月的平均单笔盈利。现有的交易函数好像都没有时间限制。
--  作者:jinzhe
--  发布时间:2014/6/5 11:26:16
--  
这个得要枚举计算,比较麻烦
--  作者:jinzhe
--  发布时间:2014/6/5 11:29:14
--  
单笔盈利就是把盈利的交易做平均计算,亏损的不计算在内?
--  作者:choir2001
--  发布时间:2014/6/5 12:47:29
--  

是的。例如AVGWIN

 

建议把常用交易统计函数都加入一个时间限定参数


--  作者:jinzhe
--  发布时间:2014/6/5 13:50:57
--  

这里只枚举了6月份的计算方式,用户可以参考下面的写法自行编写一下其他月份的:

 

variable:ss=0;
ma5:=ma(c,5);
ma10:=ma(c,10);

if cross(ma5,ma10) then begin
 sellshort(1,0,market);
 buy(holding=0,1,market);
end

if cross(ma10,ma5) then begin
 sell(1,0,market);
 buyshort(holding=0,1,market);
end//简单的交易范例,用作计算交易盈利的样本
h1:=holding;
nn:=barslast(month=2);//计算3个月之内一共有多少根k线
yinglicishu:count(numprofit(1)>0 and h1=-1 and ref(h1,1)=1 or (h1=1 and ref(h1,1)=-1) ,nn);//盈利次数

if ((h1=-1 and ref(h1,1)=1) or (h1=1 and ref(h1,1)=-1)) and numprofit(1)>0 then ss:=ss+numprofit(1);

ss2:ss-ref(ss,nn);//3个月内的总盈利
avg_yingli:ss2/yinglicishu;

 


--  作者:choir2001
--  发布时间:2014/6/5 19:34:59
--  
这也行,谢谢~