R - quantstrat订单相互抵消

Sil*_*oon 4 r quantstrat

如何在quantstrat中输入相互抵消的订单?例如,一旦我进入交易,我立即开出两个订单:"止损"和"获利".一旦填满,另一个将被取消.

#Enter signal 

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE, orderqty=100,
                                    ordertype="market", orderside="long", 
                                    pricemethod="market", osFUN=osMaxPos),
                     type="enter", path.dep=TRUE)

#Stop loss

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE, 
                                    orderqty="all", ordertype="stoplimit", 
                                    orderside="short", threshold=-5, 
                                    tmult=FALSE), 
                     type="exit", path.dep=TRUE)

#Take profit

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE,
                                    orderqty="all", ordertype="stoplimit", 
                                    orderside="short", threshold=5, 
                                    tmult=FALSE),
                     type="exit", path.dep=TRUE) 
Run Code Online (Sandbox Code Playgroud)

目前,他们正在独立工作.

Bri*_*son 8

SVN r 1010将代码添加到quantstrat,以便更容易使用OCO(One Cancels Other)订单集.有一个在"金叉"演示的例子在这里,它使用新暴露出的orderset参数对出口订单提供OCO功能.

您需要使用当前的svn(r1010或更高版本)才能使用此功能.我还会注意到订单大小调整功能现在有点破,我们正在努力.

您使用订单集的示例如下所示:

#Enter signal 

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE, orderqty=100,
                                    ordertype="market", orderside="long", 
                                    pricemethod="market", osFUN=osMaxPos),
                     type="enter", path.dep=TRUE)

#Stop loss

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE, 
                                    orderqty="all", ordertype="stoplimit", 
                                    orderside="long", threshold=-5, 
                                    tmult=FALSE, orderset='altexits'), 
                     type="exit", path.dep=TRUE)

#Take profit

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE,
                                    orderqty="all", ordertype="stoplimit", 
                                    orderside="long", threshold=5, 
                                    tmult=FALSE, orderset='altexits'),
                     type="exit", path.dep=TRUE) 
Run Code Online (Sandbox Code Playgroud)

注意添加的orderset ="altexits"参数的参数列表ruleSignal.