【发布时间】: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.rule和enable.rule的输出分配回pairStrat? -
我不确定我是否理解您的问题。我知道 pairStrat 是我的策略对象,定义为:
pairStrat <- strategy('pairStrat')。修改后的demo完整代码在https://bitbucket.org/marital_weeping/pair_trade-modified
标签: r quantstrat blotter