以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  混合持仓如何编写  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=77858)

--  作者:michael000
--  发布时间:2015/4/22 9:57:55
--  混合持仓如何编写
想请教下,假如我有两个策略做同一个品种,一个策略持仓为2手多,另一个为1手空,其实这时我综合持仓为1手多,想问下有没有方法可以参考两个策略的holding来下单,因为这样大大节省了手续费和保证金,特别如果多个策略做一个品种时,更是如此
--  作者:jinzhe
--  发布时间:2015/4/22 10:10:21
--  

如果是图表交易的话,这样的持仓是不会互相影响的,各管各的持仓,

还是你认为下两手多1手空之后,对冲之后就是1手多,所以就只要1手多的手续费?


--  作者:qwer123
--  发布时间:2015/4/22 10:10:55
--  
//股指期货自动交易程序(净单交易)
//编制:
//日期:

r1:=barslast(date<>ref(date,1));
//********************************
rr1:=stkindiex(\'if00\',\'qq25.持仓\',0,22,80,0);
rr2:=stkindiex(\'if00\',\'qq25.持仓\',0,22,85,0);
rr3:=stkindiex(\'if00\',\'qq25.持仓\',0,22,90,0);


r12:=rr1+rr2+rr3,noaxis;

//***************第一遍***************
if holding=0 and r12>0 then buy(1,r12,limitr,c);
if holding=0 and r12<0 then buyshort(1,abs(r12),limitr,c);

if holding>0 and r12>0 and holding>r12 then sell(1,holding-r12,limitr,c);
if holding>0 and r12>0 and holding<r12 then buy(1,r12-holding,limitr,c);
if holding>0 and r12<0 then
begin
sell(1,holding,limitr,c);
buyshort(1,abs(r12),limitr,c);
end

if holding<0 and r12<0 and holding>r12 then buyshort(1,holding-r12,limitr,c);
if holding<0 and r12<0 and holding<r12 then sellshort(1,r12-holding,limitr,c);
if holding<0 and r12>0 then
begin
sellshort(1,holding,limitr,c);
buy(1,r12,limitr,c);
end 

if (r12=0 or time>=151500) and holding>0 then sell(holding>0,holding,limitr,c);
if (r12=0 or time>=151500) and holding<0 then sellshort(holding<0,abs(holding),limitr,c);
//********************************
盈亏:asset-1000000,colorred,linethick1,noaxis;
日盈亏:asset-ref(asset,todaybar),noaxis,colorred,linethick0;
持仓:holding,linethick0;


注意,如果是1根k线开几次仓,“第一遍”之后的语句就要运行几遍
你还有一个错误理解,这个方法并不能节省交易费的,自己好好琢磨一下。

--  作者:michael000
--  发布时间:2015/4/22 10:14:45
--  
呵呵,的确是的,只有刚好几个策略在同一条k线时出现信号才会有节省交易费用的效果,谢谢前辈无私分享!
--  作者:michael000
--  发布时间:2015/4/22 10:20:25
--  
看了下,还是要用引用,我之前也是觉得可能要用引用才能写出来,但我租用的服务器交易,怕品种多策略多的话这样引用机器受不了,除了引用我是想过把同一品种的数个策略用虚拟持仓的方式写进去,最后计算虚拟持仓的数量来真实下单