【问题标题】:QUANTSTRAT - apply.paramset issueQUANTSTRAT - apply.paramset 问题
【发布时间】:2016-04-13 17:00:51
【问题描述】:

我正在尝试优化交易策略的 MACD 参数,但不幸的是我被paramset.label 值所困。这是代码:

################################# MACD PARAMETERS OPTIMIZATION

.fastMA <- (20:40)
.slowMA <- (30:70)
.nsamples = 10

strat.st <- 'volStrat'

# Paramset

add.distribution(strat.st,
                 paramset.label = 'EMA',
                 component.type = 'indicator',
                 component.label = 'macd.out', 
                 variable = list(n = .fastMA),
                 label = 'nFast'
)

add.distribution(strat.st,
                 paramset.label = 'EMA',
                 component.type = 'indicator',
                 component.label = 'macd.out', 
                 variable = list(n = .slowMA),
                 label = 'nSlow'
)

add.distribution.constraint(strat.st,
                            paramset.label = 'EMA',
                            distribution.label.1 = 'nFast',
                            distribution.label.2 = 'nSlow',
                            operator = '<',
                            label = 'nFast<nSlow'
)

results <- apply.paramset(strat.st, 
                          paramset.label = 'EMA', 
                          portfolio = portfolio2.st, 
                          account = account.st, 
                          nsamples = .nsamples, 
                          verbose = TRUE)

stats <- results$tradeStats

print(stats)

当我运行它时,每个样本都会出现这个错误:

    evaluation # 1:
$param.combo
    nFast nSlow
379    23    51

[1] "Processing param.combo 379"
    nFast nSlow
379    23    51
result of evaluating expression:
<simpleError in strategy[[components.type]][[index]]: subscript out of bounds>
got results for task 1
numValues: 1, numResults: 1, stopped: FALSE
returning status FALSE

然后,对于最后一个,这是错误:

evaluation # 10:
$param.combo
    nFast nSlow
585    40    60

[1] "Processing param.combo 585"
    nFast nSlow
585    40    60
result of evaluating expression:
<simpleError in strategy[[components.type]][[index]]: subscript out of bounds>
got results for task 10
numValues: 10, numResults: 10, stopped: FALSE
first call to combine function
evaluating call object to combine results:
  fun(result.1, result.2, result.3, result.4, result.5, result.6, 
    result.7, result.8, result.9, result.10)
error calling combine function:
<simpleError in fun(result.1, result.2, result.3, result.4, result.5, result.6,     result.7, result.8, result.9, result.10): attempt to select less than one element>
numValues: 10, numResults: 10, stopped: TRUE

我真的不明白我该如何解决它。 谁能解决这个问题?

非常感谢

【问题讨论】:

    标签: optimization quantstrat


    【解决方案1】:

    OPTIMIZATION部分之前没有给出代码,这里只是我的猜测方向。

    我知道您想测试 20:40 和 30:70,但在您的 OPTIMIZATION 代码中,您添加了两个指向“component.label = 'macd.out'”的分布。

    我做过类似的测试,虽然它们都使用 MA 类型的指标,但它们通常不应该指向相同的 MA 数据(“component.label = 'macd.out'”),这些代码工作了一个分发点到“component.label”。 label = 'fast'" 和另一个指向 "component.label = 'slow'" 因为它们指向不同的数据,以便进行比较。

    你可以尝试往这个方向调试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 2020-06-05
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多