Directory of Open Source for Quantitative Finance and Trading
Username: Password: Not registered?
 
Quick Search:    (AJAX based: No need to press button)

Main : Excel : 


Category: Excel View Full Details
Download Now!Levenberg Marquardt in Excel
Submitter: vanna Date: 2009/4/4
Description:
This class contains code to perform fitting of function parameters using inputs of dependent and observed variables. It is translated from Fortran version of MINPACK.


Following is example usage of this class:
Dim levObj As New Levenberg
res = levObj.CalibrateParameters("MyFunction", x, y, p)


where
x : a vector of independent variables
y : observed values
p: vector of initial guess values for parameters
MyFunction : name of VBA function which implements the fucntion f(x,p)
res : output vector of calibrated parameter values

eg., for a function f(x)=ax^2+bx+c:
Public Function MyFunction(params As Variant, x As Variant) As Variant
  a = params(1)
  b = params(2)
  c = params(3)
  m = UBound(x)
  ReDim function_values(1 To m)
  For i = 1 To m
    xi = x(i)
    function_values(i) = a * xi * xi + b * xi + c
  Next i
  MyFunction = function_values
End Function


To check out an actual demo for usage, refer to Parameters calibration demo for Levenberg Marquardt algorithm

Got a question or problem with this link? Just enter your message and click on submit. No registration is required.

Note: A copy of this message will also be emailed to the submitter of this link
Downloaded 3491 times  3491  File Size 0 bytes  Supported Platforms Excel VBA  Home Page http://www.quantcode.com/
Rating: 0.00 (0 votes)
Rate this File | Modify | Delete | Report Broken File | Tell a Friend | Comments (55)

Poster Thread
Bazman76
Posted: 2009/8/7 6:39  Updated: 2009/8/7 6:39
Just popping in
Joined: 2009/8/6
From:
Posts: 4
 Re: Levenberg Marquardt in Excel
Hi there,

I am interested in using the function below.

But I have never used classes in VBA before. Do I have to install part or all of the code into a class module?

Are there any other differences from using a normal VBA macro?

Thanks

Baz

Poster Thread
Bazman76
Posted: 2009/8/17 9:53  Updated: 2009/8/17 9:53
Just popping in
Joined: 2009/8/6
From:
Posts: 4
 Re: Levenberg Marquardt in Excel
Please ignore previous post.

The code works perfectly thank so much for this.

I have a couple of questions though:

http://www.netlib.org/minpack/lmdif.f

It says that the function lmdif uses a modification of the LM algorithm. Can someone please explain to me how this differs from standard LM algorithm.

Also can someone point me to a good source that explains the theory behind this version of the algorithm. I have tried following the code but it is not always very clear what is happening.

Discuss this file. Just enter your message and click on submit. No registration is required.
Similar Links:
Levenberg-Marquardt for Visual C++ 2005 (Software)
Levenberg Marquardt for function minimization (Forum)
Hull White model calibration using Levenberg Marquardt (Software)
Example of using Levenberg Marquardt for Parameters calibration in Excel (Software)
Levenberg-Marquardt nonlinear least squares algorithms in C/C++ (Software)

Subscribe to RSS or daily email updates of latest quantitative finance code listings
Email address :
Copyright © 2011 QuantCode Inc. All rights reserved.