【发布时间】: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