2

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

# 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

然而,一种非常相似的方法在单一工具组合策略中取得了成功。

我在这里想念什么?

4

1 回答 1

2

如果我将输出分配给并返回给,您的bitbucket 代码将为我运行(就像演示中的所有其他调用一样)。add.ruleenable.rulepairStratadd.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")
于 2015-02-13T14:29:32.010 回答