Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
parametrization.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file parametrization.hpp
20 \brief base class for model parametrizations
21 \ingroup models
22*/
23
24#ifndef quantext_model_parametrization_hpp
25#define quantext_model_parametrization_hpp
26
27#include <ql/currency.hpp>
28#include <ql/math/array.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! Parametrization
35/*! Base class for classes representing model parameters. There is a disctinction between "actual" and "raw"
36 parameters. The "actual" parameter value is the true value of the parameter, e.g. 0.20 to represent a black scholes
37 volatility of 20%. The "raw" parameter is derived from the actual parameter by applying a transformation
38
39 actual value = direct( raw value )
40 raw value = inverse( actual value )
41
42 The idea behind that is that the optimization during a model calibration can be performed as an unconstrained
43 optimization which usually works more stable and is faster than a constrained optimization. For example, to ensure
44 a positive black volatility one can use the transformation
45
46 direct ( x ) = x * x
47
48 To ensure a valid correlation one can use the transformation
49
50 direct ( x ) = (atan( x ) + pi / 2) / pi
51
52 and so forth. To implement you own transformation you can overwrite the direct() and inverse() methods. The default
53 implementation of these methods represents the trivial transformation (identity, i.e. direct( x ) = x ).
54
55 \ingroup models
56 */
58public:
59 Parametrization(const Currency& currency, const std::string& name = "");
60 virtual ~Parametrization() {}
61
62 /*! the currency associated to this parametrization */
63 virtual const Currency& currency() const;
64
65 /*! the times associated to parameter i */
66 virtual const Array& parameterTimes(const Size) const;
67
68 /*! the number of parameters in this parametrization */
69 virtual Size numberOfParameters() const { return 0; }
70
71 /*! the actual parameter values */
72 virtual Array parameterValues(const Size) const;
73
74 /*! the parameter storing the raw parameter values */
75 virtual const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const;
76
77 /*! this method should be called when input parameters
78 linked via references or pointers change in order
79 to ensure consistent results */
80 virtual void update() const;
81
82 /*! return a name (inflation index, equity name, credit name, etc.) */
83 const std::string& name() const { return name_; }
84
85 /*! transformations between raw and actual parameters */
86 virtual Real direct(const Size, const Real x) const;
87 virtual Real inverse(const Size, const Real y) const;
88
89protected:
90 /*! step size for numerical differentiation */
91 const Real h_, h2_;
92 /*! adjusted central difference scheme */
93 Time tr(const Time t) const;
94 Time tl(const Time t) const;
95 Time tr2(const Time t) const;
96 Time tm2(const Time t) const;
97 Time tl2(const Time t) const;
98
99private:
100 Currency currency_;
101 std::string name_;
102 const Array emptyTimes_;
103 const QuantLib::ext::shared_ptr<Parameter> emptyParameter_;
104};
105
106// inline
107
108inline void Parametrization::update() const {}
109
110inline Time Parametrization::tr(const Time t) const { return t > 0.5 * h_ ? t + 0.5 * h_ : h_; }
111
112inline Time Parametrization::tl(const Time t) const { return std::max(t - 0.5 * h_, 0.0); }
113
114inline Time Parametrization::tr2(const Time t) const { return t > h2_ ? t + h2_ : 2.0 * h2_; }
115
116inline Time Parametrization::tm2(const Time t) const { return t > h2_ ? t : h2_; }
117
118inline Time Parametrization::tl2(const Time t) const { return std::max(t - h2_, 0.0); }
119
120inline Real Parametrization::direct(const Size, const Real x) const { return x; }
121
122inline Real Parametrization::inverse(const Size, const Real y) const { return y; }
123
124inline const Currency& Parametrization::currency() const { return currency_; }
125
126inline const Array& Parametrization::parameterTimes(const Size) const { return emptyTimes_; }
127
128inline const QuantLib::ext::shared_ptr<Parameter> Parametrization::parameter(const Size) const { return emptyParameter_; }
129
130inline Array Parametrization::parameterValues(const Size i) const {
131 const Array& tmp = parameter(i)->params();
132 Array res(tmp.size());
133 for (Size ii = 0; ii < res.size(); ++ii) {
134 res[ii] = direct(i, tmp[ii]);
135 }
136 return res;
137}
138
139} // namespace QuantExt
140
141#endif
virtual const Array & parameterTimes(const Size) const
virtual const QuantLib::ext::shared_ptr< Parameter > parameter(const Size) const
const std::string & name() const
const QuantLib::ext::shared_ptr< Parameter > emptyParameter_
Time tl(const Time t) const
Time tm2(const Time t) const
virtual const Currency & currency() const
virtual Real inverse(const Size, const Real y) const
Time tl2(const Time t) const
virtual Size numberOfParameters() const
Time tr(const Time t) const
virtual void update() const
virtual Real direct(const Size, const Real x) const
virtual Array parameterValues(const Size) const
Time tr2(const Time t) const
parameter giving access to calibration machinery