gpt4 book ai didi

r - ES 计算为列 : 1 产生不可靠的结果(反向风险)

转载 作者:行者123 更新时间:2023-12-04 12:06:54 25 4
gpt4 key购买 nike

我不断收到此错误:使用 DEoptim 时,ES 计算为列:1 消息产生不可靠的结果(反向风险)。也许我忽略了一些东西,所以我需要一些帮助来解决这个问题。我在网上搜索过,但似乎找不到答案。

我有一个名为 RETSxts 对象,它包含 127 行和 4 列,并且有对数返回:

library("quantmod")
library("PerformanceAnalytics")
library("DEoptim")

e <- new.env()
getSymbols("SPY;QCOR;CLNT;SRNE", from="2007-06-30", to="2007-12-31", env=e)
# combine the adjusted close values in one xts object
dataset1 <- do.call(merge, eapply(e, Ad))
# calculate returns
RETS <- na.omit(CalculateReturns(dataset1, method="log"))
# objective function
optRR.gt3 <- function(x, ret) {
retu <- ret %*% x
obj <- -CVaR(as.ts(-retu))/CVaR(as.ts(retu))
obj <- ifelse(obj>0,-obj,obj)
weight.penalty <- 100*(1-sum(x))^2
small.weight.penalty <- 100*sum(x[x<0.03])
return(obj + weight.penalty + small.weight.penalty)
}
# I am Trying to optimize the function: optRR.gt3, which minimizes CVaR
ctrl <- list(itermax=250, F=0.2, CR=0.8)
set.seed(21)
res <- DEoptim(optRR.gt3, lower=rep(0,ncol(RETS)), upper=rep(1,ncol(RETS)), control=ctrl, ret=RETS)
#ES calculation produces unreliable result (risk over 100%) for column: 1 : 3.01340769101382
#ES calculation produces unreliable result (inverse risk) for column: 1 : -0.239785868862194
#ES calculation produces unreliable result (inverse risk) for column: 1 : -0.11639331543788
#ES calculation produces unreliable result (risk over 100%) for column: 1 : 1.06315102355445
#ES calculation produces unreliable result (risk over 100%) for column: 1 : 1.05285415441624
#ES calculation produces unreliable result (risk over 100%) for column: 1 : 2.19356415811659
#ES calculation produces unreliable result (inverse risk) for column: 1 : -0.0384963731133424
#Error in DEoptim(optRR.gt3, lower = rep(0, ncol(RETS)), upper = rep(1, :
# NaN value of objective function!
#Perhaps adjust the bounds.

我已经将这段代码与其他系列的日志返回一起运行并且它有效,但有时我针对一系列运行它并得到诸如这个的错误。

最佳答案

这是因为第 1 列中的一个返回率 > 100%,这导致 CVaR 返回 NA(因为您没有尾部风险......或者您的尾部“风险”是正返回)。删除该观察,优化将运行。

R> rets <- RETS[RETS[,1]<1]
R> ctrl <- list(itermax=5, F=0.2, CR=0.8)
R> set.seed(21)
R> res <- DEoptim(optRR.gt3, lower=rep(0,ncol(rets)), upper=rep(1,ncol(rets)), control=ctrl, ret=rets)
Iteration: 1 bestvalit: -3.931392 bestmemit: 0.499045 0.233446 0.099941 0.056293
Iteration: 2 bestvalit: -3.931392 bestmemit: 0.499045 0.233446 0.099941 0.056293
Iteration: 3 bestvalit: -3.931392 bestmemit: 0.499045 0.233446 0.099941 0.056293
Iteration: 4 bestvalit: -3.931392 bestmemit: 0.499045 0.233446 0.099941 0.056293
Iteration: 5 bestvalit: -4.079845 bestmemit: 0.481677 0.208534 0.141505 0.061751

关于r - ES 计算为列 : 1 产生不可靠的结果(反向风险),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24466655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com