小编use*_*652的帖子

在R量子代码中循环 - 如何使其更快?

在quantstrat包中,我找到了applyRule函数缓慢的主要罪魁祸首之一,并想知道是否有更高效的写入while循环.任何反馈都会有所帮助.任何人都可以将这部分包装成并行R.

作为一种选择,申请会有效吗?或者我应该将此部分重新编写为新函数,例如ruleProc和nextIndex?我也在沉迷于Rcpp,但这可能是一个特殊的问题.非常感谢任何帮助和建设性的建议?

   while (curIndex) {
    timestamp = Dates[curIndex]
    if (isTRUE(hold) & holdtill < timestamp) {
        hold = FALSE
        holdtill = NULL
    }
    types <- sort(factor(names(strategy$rules), levels = c("pre",
        "risk", "order", "rebalance", "exit", "enter", "entry",
        "post")))
    for (type in types) {
        switch(type, pre = {
            if (length(strategy$rules[[type]]) >= 1) {
              ruleProc(strategy$rules$pre, timestamp = timestamp,
                path.dep = path.dep, mktdata = mktdata, portfolio = portfolio,
                symbol = symbol, ruletype = type, mktinstr = mktinstr)
            }
        }, risk = {
            if (length(strategy$rules$risk) >= 1) …
Run Code Online (Sandbox Code Playgroud)

r while-loop quantstrat

5
推荐指数
1
解决办法
2268
查看次数

标签 统计

quantstrat ×1

r ×1

while-loop ×1