【问题标题】:Error implementing a stoplimit order in quantstrat在 quantstrat 中执行 stoplimit 订单时出错
【发布时间】:2015-02-12 14:02:42
【问题描述】:

在 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

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

我在这里错过了什么?

【问题讨论】:

  • 我无法复制此错误。您是否将add.ruleenable.rule 的输出分配回pairStrat
  • 我不确定我是否理解您的问题。我知道 pairStrat 是我的策略对象,定义为:pairStrat &lt;- strategy('pairStrat') 。修改后的demo完整代码在https://bitbucket.org/marital_weeping/pair_trade-modified

标签: r quantstrat blotter


【解决方案1】:

如果我将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")

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多