如果一个参数组合不返回任何内容,则apply.paramset不会产生结果 [英] No results from apply.paramset if one parameter combination returns nothing

查看:134
本文介绍了如果一个参数组合不返回任何内容,则apply.paramset不会产生结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been encountering an issue when optimizing a strategy using the apply.paramset function in quantstrat.

我遇到的问题似乎与这里的问题相同: Quantstrat:apply.paramset失败是由于某些参数分布的组合误差,而不是其他

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

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

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:

"match.names(clabs,names(xi))中的simpleError:名称与以前的名称不匹配"

"simpleError in match.names(clabs, names(xi)): names do not match previous names"

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

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

我希望能够从结果"环境中提取用于此优化的tradeStats,但是由于错误,结果将变为NULL.

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.

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

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.

预先感谢

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

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.

任何输入将不胜感激.

推荐答案

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

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. 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.

您的代码可以更合理地使用标准偏差,例如.sdlist = c(1,2).

Your code will work fine with a more realistic standard deviation, say .sdlist = c(1, 2).

这篇关于如果一个参数组合不返回任何内容,则apply.paramset不会产生结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆