Dear R-users I need to calibrate kappa, rho, eta, theta, v0 in the following code, see below. However when I run it, I get:
y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)} > nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, > upper =ub) Error in dots[[1L]][[1L]] : object of type 'closure' is not subsettable And I don't know what this mean and what I am doing wrong. Can anyone help me? Here is my code and data set. Best Rikke http://r.789695.n4.nabble.com/file/n3752886/S%26P_500_calls%2C_jan-jun_2010.csv S%26P_500_calls%2C_jan-jun_2010.csv marketdata <- read.csv(file="S&P 500 calls, jan-jun 2010.csv", header=TRUE, sep=";") spot <- read.csv(file="S&P 500 spot and return 2010.csv", header=TRUE, sep=";") #------------------------- Values ---------------------------------- #### Data imported S0 <- 1136.03 X <- marketdata[1:460,9] t <- marketdata[1:460,17]/365 #Notice the T is measured in years now implvol <- marketdata[1:460,12] k <- log(X/(S0*exp(r-q)*t)) ###### Initial values kappa <- 0.0663227 # Lambda = -kappa rho <- -0.6678461 eta <- 0.002124704 theta <- 0.0001421415 v0 <- 0.0001421415 q <- 0.02145608 r <- 0.01268737 #----------------------------------------------------------------------------- #### The price of a Call option (Eq. (5.6) of The Volatility Surface, Gatheral) # In terms of log moneyness Price_call <- function(phi, k, t) { integrand <- function(u) {Re(exp(-1i*u*k)*phi(u - 1i/2, t)/(u^2 + 1/4))} res <- S0*exp(-q*t) - exp(k/2)/pi*integrate(integrand,lower=0,upper=Inf)$value return(res) } Price_callVec <- function(phi, k, t) { mapply(Price_call, phi, k, t) } # The characteric formula for the Heston model (Eq. XX) phiHeston <- function(kappa, rho, eta, theta, v0) { lambda <- - kappa function(u, t) { alpha <- -u*u/2 - 1i*u/2 beta <- lambda - rho*eta*1i*u gamma <- eta^2/2 d <- sqrt(beta*beta - 4*alpha*gamma) rplus <- (beta + d)/(eta^2) rminus <- (beta - d)/(eta^2) g <- rminus / rplus D <- rminus * (1 - exp(-d*t))/ (1 - g*exp(-d*t)) C <- lambda* (rminus * t - 2/eta^2 * log( (1 - g*exp(-(d*t)))/(1 - g)) ) return(exp(C*theta + D*v0)) } } ## Calculating the Heston model price with fourier HestonCall<-function(k,t) { res<-Price_callVec(phiHeston(kappa, rho, eta, theta, v0),k,t) return(res) } ##### Vectorizing the function to handle vectors of strikes and maturities HestonCallVec <- function(k,t) { mapply (HestonCall, k, t) } lb <- c(0, -0.9, 0, 0, 0) ub <- c(100, 0.9, 0.5, 1, 1) difference <- function(k, t, S0, X, r, implvol, q, kappa, rho, eta, theta, v0) { return(HestonCallVec(k,t) - BS_Call(S0, X, t, r, implvol, q)) } y <- function(kappahat, rhohat, etahat, thetahat, v0hat) {sum(difference(k, t, S0, X, r, implvol, q, kappahat, rhohat, etahat, thetahat, v0hat)^2)} nlminb(start=list(kappa, rho, eta, theta, v0), objective = y, lower =lb, upper =ub) -- View this message in context: http://r.789695.n4.nabble.com/Error-message-object-of-type-closure-is-not-subsettable-tp3752886p3752886.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.