QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
calibrationhelper.hpp
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
25#ifndef quantlib_interest_rate_modelling_calibration_helper_h
26#define quantlib_interest_rate_modelling_calibration_helper_h
27
28#include <ql/patterns/lazyobject.hpp>
29#include <ql/quote.hpp>
30#include <ql/termstructures/volatility/volatilitytype.hpp>
31#include <ql/termstructures/yieldtermstructure.hpp>
32#include <list>
33#include <utility>
34
35namespace QuantLib {
36
37 class PricingEngine;
38
41 public:
42 virtual ~CalibrationHelper() = default;
44 virtual Real calibrationError() = 0;
45 };
46
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
68
71
73 Real marketValue() const { calculate(); return marketValue_; }
74
76 virtual Real modelValue() const = 0;
77
79 Real calibrationError() override;
80
81 virtual void addTimesTo(std::list<Time>& times) const = 0;
82
85 Real accuracy,
86 Size maxEvaluations,
87 Volatility minVol,
88 Volatility maxVol) const;
89
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
Definition: any.hpp:35
STL namespace.