简体   繁体   English

如果一个参数组合不返回任何结果,则 apply.paramset 没有结果

[英]No results from apply.paramset if one parameter combination returns nothing

I've been encountering an issue when optimizing a strategy using the apply.paramset function in quantstrat.在 quantstrat 中使用 apply.paramset function 优化策略时遇到问题。

The issue I am having appears to be the same as the one here: Quantstrat: apply.paramset fails due to combine error for certain paramater distributions, but not others我遇到的问题似乎与此处的问题相同: Quantstrat:apply.paramset 由于某些参数分布的组合错误而失败,但不是其他的

The optimization works well if all of the parameter combinations return at least one transaction, however, if one of the combinations doesn't return a transaction then the results for all of the combinations are lost/NULL, typically with the following error:如果所有参数组合都返回至少一个事务,则优化效果很好,但是,如果其中一个组合不返回事务,则所有组合的结果都将丢失/NULL,通常会出现以下错误:

"simpleError in match.names(clabs, names(xi)): names do not match previous names" “match.names(clabs,names(xi))中的simpleError:名称与以前的名称不匹配”

I have provided a short example below where it produces one successful parameter combination that produces a number of transactions (.nlist = 10 and.sdlist = 1) and one combination which doesn't produce any transactions (.nlist = 10 and.sdlist = 20).我在下面提供了一个简短的示例,它生成一个成功的参数组合,该组合产生多个事务(.nlist = 10 和 .sdlist = 1)和一个不产生任何事务的组合(.nlist = 10 和 .sdlist = 20)。

I would like to be able to extract the tradeStats for this optimization from the "results" environment, but due to the error the results become NULL.我希望能够从“结果”环境中提取此优化的 tradeStats,但由于错误,结果变为 NULL。

What would be the best way to solve this problem?解决这个问题的最佳方法是什么?

# 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)

Hopefully I have provided enough information, if not please let me know and I'll try to elaborate.希望我提供了足够的信息,如果没有,请告诉我,我会尽力详细说明。

Thanks in advance提前致谢

Edit : The obvious answer to the question would be to not choose parameters which have a range which is too large, in other words don't cast the net too wide, but even if the parameters didn't span such large ranges this issue could still arise if you were applying a small parameter optimisation on a large number of assets/datasets.编辑:这个问题的明显答案是不要选择范围太大的参数,换句话说,不要把网络撒得太宽,但即使参数没有跨越这么大的范围,这个问题也可能如果您在大量资产/数据集上应用小参数优化,仍然会出现。 For example, applying the parameters: ".nlist = c(10,12)" and ".sdlist = 1" (which are successful in the above example) to a number of different stocks in this case, It may not work for all of them and will therefore encounter this problem too.例如,在这种情况下将参数:“.nlist = c(10,12)”和“.sdlist = 1”(在上面的例子中是成功的)应用于许多不同的股票,它可能不适用于所有他们中的一个,因此也会遇到这个问题。

Any input would be greatly appreciated.任何投入将不胜感激。

The 20 standard deviation indicator is resulting in no trades, and the resulting rbind() of the tradeStats from the different param.combo strategy results is throwing an error. 20 标准差指标导致没有交易,并且来自不同 param.combo 策略结果的 tradeStats 生成的 rbind() 引发错误。 We should handle these errors more gracefully, and at least inform the user and allow the code to continue executing.我们应该更优雅地处理这些错误,至少通知用户并允许代码继续执行。 I have created an issue here - https://github.com/braverock/quantstrat/issues/121 .我在这里创建了一个问题 - https://github.com/braverock/quantstrat/issues/121

Your code will work fine with a more realistic standard deviation, say.sdlist = c(1, 2).您的代码可以在更实际的标准偏差下正常工作,say.sdlist = c(1, 2)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM