Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fit a normal inverse gaussian distribution to my data using optim
    primarykey
    data
    text
    <p>Please forgive my lack of knowledge,.I would be very thankful for some help. Here is my problem: I was using optim to estimate parameters of a model and I get this error message "Error in optim(x0, fn = riskll, method = "L-BFGS-B", lower = lbs, upper = ubs, :<br> L-BFGS-B needs finite values of 'fn'"</p> <p>Below is the R code I have written.</p> <pre><code>library('GeneralizedHyperbolic') data=read.table(file="MSCI_USA.csv",sep=',',header=T) data=data[1:8173,] #starting value x0 &lt;- 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 &lt;- c(-5, -5, -5, -0.99999, 0.00001, 0, -1, 0.1, 1.2000001, -2) ubs&lt;- c( 5, 5, 10, 0.99999, 5, 2, 0, 3, 1000, 10) #the likelihood function riskll &lt;- function(data,para) { m0 &lt;- para[1] m1 &lt;- para[2] omega &lt;- para[3] tau &lt;- para[4] a &lt;- para[5] b &lt;- para[6] beta &lt;- para[7] theta &lt;- para[8] gamma &lt;- para[9] phi &lt;- para[10] T &lt;- nrow(data) ret &lt;- data[,2]; rate &lt;- 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 &lt;- -1*sum(log(dnig(vx,param=param))) return(riskll) } #optimization optim(x0,fn=riskll,method ="L-BFGS-B",lower=lbs,upper=ubs, data = data) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload