在quantstrat中实现stoplimit顺序时出错

时间:2015-02-12 14:02:43

标签: r quantstrat blotter

在quantstrat的pair_trade.R演示中添加ordertype=stoplimit止损实施规则后(只有下面显示的短边),

# stop loss for short order (child)
add.rule(strategy=pairStrat, name = 'ruleSignal', arguments=list(sigcol='short',
    sigval=TRUE,
    replace=FALSE, 
    orderside='short', 
    ordertype='stoplimit', 
    tmult=TRUE, 
    prefer='Close',
    TxnFees='TxnCost',
    threshold=quote(.stoplossPercent), 
    orderqty='all', 
    orderset='ocoshort'),
type='chain', parent='Enter_Short',
label='StopLoss_Short',
enabled=FALSE)

并通过以下方式启用它:

enable.rule(pairStrat,'chain',"StopLoss_Long","StopLoss_Short")

我收到错误:

Error in if (grepl(label, strategy$rules[[type]][[i]]$label)) strategy$rules[[type]][[i]]$enabled <- enabled :
  argument is of length zero

采用单一的工具组合策略,一种非常类似的方法仍然是成功的。

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

如果我将add.ruleenable.rule的输出分配回pairStrat,那么bitbucket code会为我竞争(与所有其他add.rule个来电一样在演示中)。

# wrong
add.rule(strategy=pairStrat, ...)
enable.rule(pairStrat,'chain',"StopLoss_Long","StopLoss_Short")
# correct
pairStrat <- add.rule(strategy=pairStrat, ...)
pairStrat <- enable.rule(pairStrat,'chain',"StopLoss_Long","StopLoss_Short")