So I've run into this weird error in R. I have a simple function which returns an error term when comparing real and simulated prices, called hestondifferences()
.
when I try to find the local minima via:
res<-optim(fn=hestondifferences, par = c(vT=vT, rho=rho, k=k, sigma=sigma))
I get the error message:
Error in optim(fn = hestondifferences, par = c(vT = vT, rho = rho, k = k, : function cannot be evaluated at initial parameters
What confuses me is that calling the function directly with the initial parameters hestondifferences(vT, rho, k, sigma)
returns the correct value.
The function hestondifferences()
is written in a way that whenever the simulation is impossible for a certain set of parameters, it returns NA
which is in line with what optim
() expects.
hestondifferences
function? – Marijo