I have the following function that is to be minimized:
calloptim <- function( under,strike, rf, ttoe,par) {(-(under*par[1]
-strike*exp(-rf*ttoe)*par[2]))^2}
I create the following object:
res<- nlminb(c(1,1), calloptim, under= 90, strike = 100, rf =0.05, ttoe=3)
res
$par
[1] 0.9771973 1.0218072
$objective
[1] 3.412923e-16
$convergence
[1] 1
$iterations
[1] 2
$evaluations
function gradient
34 4
$message
[1] "false convergence (8)"
This is fine but now I want to grab to $par estimate values and put them in a vector so I can use them for other calculations.
How do you isolate and save only parts of the result of an object?
The following are all roughly equivalent:
Look at the help page for
?Extractfor details. I often find looking at thestr()of the object helpful when trying to find where to grab things from, i.e. either the name to of the object to extract or it’s numerical location within the object you’re looking at (1 in this case).