3

您好我正在尝试了解如何让 DEoptim 使用并行处理来工作,但我正在努力将正确的参数放入函数中以使其工作......下面是一个可重复的示例(它具有财务背景)但它是为创建 7 个资产的随机投资组合而设计的,以针对 ES 进行优化。它的灵感来自http://mpra.ub.uni-muenchen.de/28187/1/RJwrapper.pdfhttp://files.meetup.com/1772780/20120201_Ulrich_Parallel_DEoptim.pdf

其中第二个确实包含并行选项,但希望使用 unix 分叉而不是 SOCK 集群。

require(quantmod)
require(PerformanceAnalytics)
require(DEoptim)

tickers <- c("^GSPC","^IXIC","^TNX", "DIA","USO","GLD","SLV","UNG","^VIX","F","^FTSE","GS","MS","MSFT","MCD","COKE","AAPL","GOOG","T","C","BHP","RIO","CMG")
getSymbols(tickers)
tickers <- gsub("\\^","",tickers)

x <- lapply(tickers, function(x){ClCl(get(x))})
comb <- na.omit(do.call(merge,x))
colnames(comb) <- paste0(tickers,".cc")

obj <- function(w) {
 if (sum(w) == 0) { w <- w + 1e-2 }
 w <- w / sum(w)
 CVaR <- ES(weights = w,
 method = "gaussian",
 portfolio_method = "component",
 mu = mu,
 sigma = sigma)
 tmp1 <- CVaR$ES
 tmp2 <- max(CVaR$pct_contrib_ES - 0.225, 0)
 out <- tmp1 + 1e3 * tmp2
}

comb1 <- comb[,sample(1:ncol(comb),7)]
no.of.assets <- ncol(comb1)
mu <- colMeans(comb1)
sigma <- cov(comb1)


## The non-parallel version
output <- DEoptim(fn = obj,lower = rep(0, no.of.assets), upper = rep(1, no.of.assets))

## The parallel version that doesn't seem to work...
output <- DEoptim(fn = obj,lower = rep(0, no.of.assets), upper = rep(1, no.of.assets), DEoptim.control(itermax=10000, trace=250, parallelType="parallel", packages=c("PerformanceAnalytics"), parVar=c("mu","sigma")))

我收到以下错误消息

Error in missing(packages) : 'missing' can only be used for arguments
4

0 回答 0