# R Optimization Function Test

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Using Kalman Filter for CIR interest rate model parameter estimation was introduced at my previously post Kalman Filter finance, soon after that I got a few comments saying the final results are unstable and highly depend on the initial values, that’s true, local vs global minimum is never ending.**Quantitative Finance Collector**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post is therefore

**a sample test**of the optimization functions in R as I started to move from Matlab to R recently, and R allows us to choose the method we’d like to use for minimization.

**Purpose**: to estimate the parameters for Vasicek interest rate model;

**Function to be minimized**: similar as in Kalman Filter finance, where a CIR model is used instead;

**Number of Parameters**: 8

**Data**: two years time series of 3 month, 6 month, 1 year and 5 year US interest rate;

**R function to be tested**: nlm, optim(Nelder-Mead), optim(BFGS), optim(SANN), nlminb, optim (L-BFGS-B)

The true values are listed in the paper “

*estimating and testing exponential-affine term structure models by kalman filter*“, abs.tol and rel.tol are set to be 1e-6 wherever possible, derivative is not given and unconstrained optimization is prefered

I intentionally set the starting values far away from the true ones in order to see which one is able to find closest answers, obviously nlminb outperforms all others and returns almost the true values, I change the starting values randomly and still,

**nlminb is the best**and all R functions finish within seconds.

Check several alternative R optimization packages if you are not satisfied.

Tags – r , optimization , filter

**Read the full post at R Optimization Function Test**.

To

**leave a comment**for the author, please follow the link and comment on their blog:**Quantitative Finance Collector**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.