【问题标题】:No results from apply.paramset if one parameter combination returns nothing如果一个参数组合不返回任何结果,则 apply.paramset 没有结果
【发布时间】:2020-09-11 04:35:54
【问题描述】:

我在使用 quantstrat 中的 apply.paramset 函数优化策略时遇到了一个问题。

我遇到的问题似乎与此处的问题相同: Quantstrat: apply.paramset fails due to combine error for certain paramater distributions, but not others

如果所有参数组合都返回至少一个事务,则优化效果很好,但是,如果其中一个组合没有返回事务,则所有组合的结果都将丢失/NULL,通常会出现以下错误:

“match.names(clabs, names(xi)) 中的简单错误:名称与以前的名称不匹配”

我在下面提供了一个简短的示例,其中它产生了一个成功的参数组合,该组合产生了许多事务(.nlist = 10 和 .sdlist = 1)和一个不产生任何事务的组合(.nlist = 10 和.sdlist = 20)。

我希望能够从“结果”环境中提取此优化的 tradeStats,但由于错误,结果变为 NULL。

解决这个问题的最佳方法是什么?

# Demo from https://github.com/braverock/quantstrat/blob/master/demo/bbandParameters.R
require(foreach,quietly=TRUE)
require(iterators)
require(quantstrat)

demo('bbands',ask=FALSE)
strategy.st='bbands'

# Here I have chosen only a single parameter for the first distribution and two for the second, 1 will work but 20 will fail
.nlist  = 10
.sdlist = c(1, 20)

# Here are parameters that will successfully produce the results and tradeStats
#.nlist  = c(10,12)
#.sdlist = 1

# number of random samples of the parameter distribution to use for random run
.nsamples = 2 

add.distribution(strategy.st,
                 paramset.label = 'BBparams',
                 component.type = 'indicator',
                 component.label = 'BBands', 
                 variable = list(n = .nlist),
                 label = 'nFAST'
)

add.distribution(strategy.st,
                 paramset.label = 'BBparams',
                 component.type = 'indicator',
                 component.label = 'BBands', 
                 variable = list(sd = .sdlist),
                 label = 'nSLOW'
)


results <- apply.paramset(strategy.st, 
                          paramset.label='BBparams', 
                          portfolio.st=portfolio.st, 
                          account.st=account.st, 
                          nsamples=.nsamples, 
                          verbose=TRUE)

希望我已经提供了足够的信息,如果没有,请告诉我,我会尽力详细说明。

提前致谢

编辑:这个问题的明显答案是不要选择范围太大的参数,换句话说,不要把网络撒得太宽,但即使参数如果您在大量资产/数据集上应用小参数优化,则仍然可能出现此问题。例如,在这种情况下将参数:“.nlist = c(10,12)”和“.sdlist = 1”(在上面的例子中是成功的)应用于许多不同的股票,它可能不适用于所有他们中的一个,因此也会遇到这个问题。

任何意见将不胜感激。

【问题讨论】:

    标签: r optimization quantstrat


    【解决方案1】:

    20 标准差指标导致没有交易,并且来自不同 param.combo 策略结果的 tradeStats 生成的 rbind() 引发错误。我们应该更优雅地处理这些错误,至少通知用户并允许代码继续执行。我在这里创建了一个问题 - https://github.com/braverock/quantstrat/issues/121

    您的代码可以在更实际的标准偏差下正常工作,例如 .sdlist = c(1, 2)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多