Re: Model calibration with external optimizers

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Model-calibration-with-external-optimizers-tp7186p7187.html

On Mon, 2009-02-09 at 02:02 -0800, jarkki wrote:
> I am trying to use the Differential Evolution algorithm and the
> Levenberg-Marquardt implementation of Manolis Lourakis to calibrate for
> example the Heston, Bates and Merton's jump diffusion models. What is the
> 'right' or the fastest way to implement the cost function?

You don't have to.  If your model inherits from CalibratedModel, the
cost function is already written for you (along the lines you described;
you were on the right track.)  For instance, you can already use the
HestonModel or BatesModel classes this way.

What you have to do is:

- on the optimization side: write your algorithm as a class derived from
OptimizationMethod and implement its minimize() method.  The method is
passed an instance of the Problem class, from which it takes the cost
function, a constraint, and the initial value.  With those pieces, it
can perform its job in any way you see fit; when it's done, it should
store the result into the passed Problem (by calling the setCurrentValue
and setFunctionValue methods) and return the reason why it finished
(success, failure to converge, errors...)  For an example, you can look
at the available Simplex or Levenberg-Marquardt implementation.

- on the model side: if you want to implement a model (other than the
available Heston and Bates) inherit it from CalibratedModel. The base
class stores the parameters to be calibrated and provides the plumbing.
In your model class, you'll have to implement the generateArguments()
method so that it uses the current value of the parameters to set up any
object required by the pricing engines (for instance, in the HestonModel
class, it builds a Heston process.)  You'll also have to write at least
a pricing engine using your model, and a calibration helper using the
engine; see AnalyticHestonEngine and HestonModelHelper for examples.

Once you have the two pieces, the code to tie them together is already
there; you can just call

model.calibrate(helpers, optimizer, ...)

which will create the cost function, feed it to your optimizer, and
calibrate the model.  You can see how calibration is set up in the
Heston-model test cases.

Let me know if anything is still not clear.

Luigi


--

Present to inform, not to impress; if you inform, you will impress.
-- Fred Brooks



------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users