QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
calibrationhelper.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2015 Peter Caspers
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file calibrationhelper.hpp
22 \brief Calibration helper class
23*/
24
25#ifndef quantlib_interest_rate_modelling_calibration_helper_h
26#define quantlib_interest_rate_modelling_calibration_helper_h
27
29#include <ql/quote.hpp>
32#include <list>
33#include <utility>
34
35namespace QuantLib {
36
37 class PricingEngine;
38
39 //! abstract base class for calibration helpers
41 public:
42 virtual ~CalibrationHelper() = default;
43 //! returns the error resulting from the model valuation
44 virtual Real calibrationError() = 0;
45 };
46
47 //! liquid Black76 market instrument used during calibration
49 public:
52
54 CalibrationErrorType calibrationErrorType = RelativePriceError,
56 const Real shift = 0.0)
57 : volatility_(std::move(volatility)), volatilityType_(type), shift_(shift),
58 calibrationErrorType_(calibrationErrorType) {
60 }
61
62 void performCalculations() const override {
64 }
65
66 //! returns the volatility Handle
68
69 //! returns the volatility type
71
72 //! returns the actual price of the instrument (from volatility)
73 Real marketValue() const { calculate(); return marketValue_; }
74
75 //! returns the price of the instrument according to the model
76 virtual Real modelValue() const = 0;
77
78 //! returns the error resulting from the model valuation
79 Real calibrationError() override;
80
81 virtual void addTimesTo(std::list<Time>& times) const = 0;
82
83 //! Black volatility implied by the model
85 Real accuracy,
86 Size maxEvaluations,
87 Volatility minVol,
88 Volatility maxVol) const;
89
90 //! Black or Bachelier price given a volatility
92
93 void setPricingEngine(const ext::shared_ptr<PricingEngine>& engine) {
94 engine_ = engine;
95 }
96
97 protected:
100 ext::shared_ptr<PricingEngine> engine_;
103
104 private:
105 class ImpliedVolatilityHelper;
107 };
108
109}
110
111
112#endif
liquid Black76 market instrument used during calibration
virtual void addTimesTo(std::list< Time > &times) const =0
void performCalculations() const override
Volatility impliedVolatility(Real targetValue, Real accuracy, Size maxEvaluations, Volatility minVol, Volatility maxVol) const
Black volatility implied by the model.
virtual Real modelValue() const =0
returns the price of the instrument according to the model
Real calibrationError() override
returns the error resulting from the model valuation
Handle< Quote > volatility() const
returns the volatility Handle
Real marketValue() const
returns the actual price of the instrument (from volatility)
BlackCalibrationHelper(Handle< Quote > volatility, CalibrationErrorType calibrationErrorType=RelativePriceError, const VolatilityType type=ShiftedLognormal, const Real shift=0.0)
const CalibrationErrorType calibrationErrorType_
ext::shared_ptr< PricingEngine > engine_
void setPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
VolatilityType volatilityType() const
returns the volatility type
virtual Real blackPrice(Volatility volatility) const =0
Black or Bachelier price given a volatility.
abstract base class for calibration helpers
virtual Real calibrationError()=0
returns the error resulting from the model valuation
virtual ~CalibrationHelper()=default
Shared handle to an observable.
Definition: handle.hpp:41
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
std::size_t Size
size of a container
Definition: types.hpp:58
framework for calculation on demand and result caching
Definition: any.hpp:35
STL namespace.
purely virtual base class for market observables
volatility types
Interest-rate term structure.