0

请原谅我缺乏知识,我将非常感谢您的帮助。这是我的问题:我使用 optim 来估计模型的参数,我收到此错误消息“优化错误(x0,fn = riskll,方法 =“L-BFGS-B”,下 = 磅,上 = ubs, :
L-BFGS-B 需要 'fn' 的有限值"

下面是我写的 R 代码。

library('GeneralizedHyperbolic')
data=read.table(file="MSCI_USA.csv",sep=',',header=T)
data=data[1:8173,]
#starting value
x0 <- c(-0.011,0.146, 0.013,   0.639, 0.059,0.939,  -0.144  ,  1.187,    1.601,          -0.001)
#lower bound and upper bound
lbs <- c(-5,    -5,    -5,  -0.99999, 0.00001,   0,   -1,    0.1,    1.2000001,    -2)
ubs<-  c( 5,     5,    10,   0.99999,    5,      2,     0,    3,      1000,        10)
#the likelihood function
riskll <- function(data,para) {
m0 <- para[1]
m1 <- para[2]
omega <- para[3]
tau <- para[4]
a <- para[5]
b <- para[6]
beta <- para[7]
theta <- para[8]
gamma <- para[9]
phi <- para[10]
T <- nrow(data)
ret <- data[,2];
rate <- data[,3]
exret=100*(ret+1-((rate/100)+1)^(1/365))

h = rep(0,T);
vx = rep(0,T);
h[1] = 10000*exret[1]^2
vx[1] = (exret[1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[1])/h[1]
for ( i in (2:T) ) {
h[i] = (omega+a*(abs(h[i-1]*vx[i-1])-tau*h[i-1]*vx[i-1])^theta+b*(h[i-  1]^theta))^(1/theta)    
vx[i] = (exret[i]-phi*exret[i-1]-m0-(m1+beta*((gamma^0.5)/(gamma^2+beta^2)^0.5))*h[i])/h[i]  
}

mu = -1*beta*((gamma^0.5)/(gamma^2+beta^2)^0.5)
delta=((gamma^1.5)/(gamma^2+beta^2)^0.5)
alpha=gamma
beta=beta
param = c(mu, delta, alpha, beta)
riskll <- -1*sum(log(dnig(vx,param=param)))

return(riskll)
}


#optimization
optim(x0,fn=riskll,method ="L-BFGS-B",lower=lbs,upper=ubs, data = data)
4

1 回答 1

0

我不确定,但我会仔细看看这一行:

riskll <- -1*sum(log(dnig(vx,param=param)))

log 函数在其参数接近零时接近负无穷大。而且它根本没有为否定论点定义。也许错误消息是在警告您这种可能性。

于 2013-05-20T09:29:33.100 回答