Skip to content
Prev 268742 / 398502 Next

Calibrating the risk free interest rate using nlminb

Newbie wrote:
1. it seems that your function difference contains an error: Superfluous
closing )
2. difference contains another possible error: it is not using the last
argument mid
It's using the global variable mid_bidask.

It should read

difference <- function (S0, K, T, r, sigma, q, mid)
{
return(BS_Call(S0, strike, T, r, sigma, q)- mid)
}

Your function returns a vector of length 460 as you correctly said.
But in  the documentation of nlminb it clearly states that the objective
must return a scalar value.
(NB. It doesn't seem to check?)

So in function f you should at least reduce the vector to a scalar.
In this case I would minimize the sum of the differences squared to prevent
the optimization routine
from getting negative values for differences.
So define f as follows

f <- function(x) sum(difference(S0, strike, T, x, implvol, q, mid_bidask)^2)

and then 

nlminb(start=r, f)

gives
$par
[1] 0.01268534

$objective
[1] 3140.738

$convergence
[1] 0

$iterations
[1] 5

$evaluations
function gradient 
       8        5 

$message
[1] "relative convergence (4)"

If you try nlm and optim (with method="BFGS) you'll get similar results.

It's up to you to decide if the outcome is plausible/acceptable.

Berend



--
View this message in context: http://r.789695.n4.nabble.com/Calibrating-the-risk-free-interest-rate-using-nlminb-tp3747509p3747758.html
Sent from the R help mailing list archive at Nabble.com.