Logo Search packages:      
Sourcecode: quantlib version File versions  Download package

model.hpp

Go to the documentation of this file.
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
 Copyright (C) 2005 StatPro Italia srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/reference/license.html>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

/*! \file model.hpp
    \brief Abstract interest rate model class
*/

#ifndef quantlib_interest_rate_model_hpp
#define quantlib_interest_rate_model_hpp

#include <ql/option.hpp>
#include <ql/Lattices/lattice.hpp>
#include <ql/ShortRateModels/parameter.hpp>
#include <ql/ShortRateModels/calibrationhelper.hpp>
#include <ql/Optimization/problem.hpp>

namespace QuantLib {

    //! Affine model class
    /*! Base class for analytically tractable models.

        \ingroup shortrate
    */
00041     class AffineModel : public virtual Observable {
      public:
        //! Implied discount curve
        virtual DiscountFactor discount(Time t) const = 0;

        virtual Real discountBondOption(Option::Type type,
                                        Real strike,
                                        Time maturity,
                                        Time bondMaturity) const = 0;
    };

    //! Term-structure consistent model class
    /*! This is a base class for models that can reprice exactly
        any discount bond.

        \ingroup shortrate
    */
00058     class TermStructureConsistentModel : public virtual Observable {
      public:
        TermStructureConsistentModel(
                              const Handle<YieldTermStructure>& termStructure)
        : termStructure_(termStructure) {}
        const Handle<YieldTermStructure>& termStructure() const {
            return termStructure_;
        }
      private:
        Handle<YieldTermStructure> termStructure_;
    };

    //! Abstract short-rate model class
    /*! \ingroup shortrate */
00072     class ShortRateModel : public Observer, public virtual Observable {
      public:
        ShortRateModel(Size nArguments);

00076         void update() {
            generateArguments();
            notifyObservers();
        }

        virtual boost::shared_ptr<NumericalMethod> tree(
                                                   const TimeGrid&) const = 0;

        //! Calibrate to a set of market instruments (caps/swaptions)
        /*! An additional constraint can be passed which must be
          satisfied in addition to the constraints of the model.
        */
        void calibrate(
                   const std::vector<boost::shared_ptr<CalibrationHelper> >&,
                   OptimizationMethod& method,
                   const Constraint& constraint = Constraint());

        const boost::shared_ptr<Constraint>& constraint() const;

        //! Returns array of arguments on which calibration is done
        Disposable<Array> params() const;
        void setParams(const Array& params);
      protected:
        virtual void generateArguments() {}

        std::vector<Parameter> arguments_;
        boost::shared_ptr<Constraint> constraint_;

      private:
        //! Constraint imposed on arguments
        class PrivateConstraint;
        //! Calibration cost function class
        class CalibrationFunction;
        friend class CalibrationFunction;
    };

    // inline definitions

    inline const boost::shared_ptr<Constraint>&
    ShortRateModel::constraint() const {
        return constraint_;
    }

00119     class ShortRateModel::PrivateConstraint : public Constraint {
      private:
00121         class Impl :  public Constraint::Impl {
          public:
            Impl(const std::vector<Parameter>& arguments)
            : arguments_(arguments) {}
00125             bool test(const Array& params) const {
                Size k=0;
                for (Size i=0; i<arguments_.size(); i++) {
                    Size size = arguments_[i].size();
                    Array testParams(size);
                    for (Size j=0; j<size; j++, k++)
                        testParams[j] = params[k];
                    if (!arguments_[i].testParams(testParams))
                        return false;
                }
                return true;
            }
          private:
            const std::vector<Parameter>& arguments_;
        };
      public:
        PrivateConstraint(const std::vector<Parameter>& arguments)
        : Constraint(boost::shared_ptr<Constraint::Impl>(
                                   new PrivateConstraint::Impl(arguments))) {}
    };

}


#endif

Generated by  Doxygen 1.6.0   Back to index