QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
ctsmmcapletcalibration.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) 2007 Ferdinando Ametrano
5 Copyright (C) 2007 Mark Joshi
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#ifndef quantlib_ctsmm_caplet_calibration_hpp
22#define quantlib_ctsmm_caplet_calibration_hpp
23
27#include <ql/shared_ptr.hpp>
28#include <vector>
29
30namespace QuantLib {
31
32 class PiecewiseConstantVariance;
33 class Matrix;
34
36 public:
37 virtual ~CTSMMCapletCalibration() = default;
39 EvolutionDescription evolution,
40 ext::shared_ptr<PiecewiseConstantCorrelation> corr,
41 std::vector<ext::shared_ptr<PiecewiseConstantVariance> > displacedSwapVariances,
42 std::vector<Volatility> mktCapletVols, // displaced??
43 ext::shared_ptr<CurveState> cs,
44 Spread displacement); // ??
45 // modifiers
46 bool calibrate(Natural numberOfFactors,
47
48 Natural maxIterations,
49 Real tolerance,
50
51 Natural innerMaxIterations = 100,
52 Real innerTolerance = 1e-8);
53 // inspectors
54 Natural failures() const;
55 Real deformationSize() const;
56
57 Real capletRmsError() const;
58 Real capletMaxError() const;
59 Real swaptionRmsError() const;
60 Real swaptionMaxError() const;
61
62 const std::vector<Matrix>& swapPseudoRoots() const;
63 const Matrix& swapPseudoRoot(Size i) const;
64
65 const std::vector<Volatility>& mktCapletVols() const;
66 const std::vector<Volatility>& mdlCapletVols() const;
67 const std::vector<Volatility>& mktSwaptionVols() const;
68 const std::vector<Volatility>& mdlSwaptionVols() const;
69 const std::vector<Volatility>& timeDependentCalibratedSwaptionVols(Size i) const;
70 const std::vector<Volatility>& timeDependentUnCalibratedSwaptionVols(Size i) const;
71
72
73 static void performChecks(
74 const EvolutionDescription& evolution,
76 const std::vector<ext::shared_ptr<
78 displacedSwapVariances,
79 const std::vector<Volatility>& mktCapletVols,
80 const CurveState& cs);
81
82 const ext::shared_ptr<CurveState>& curveState() const;
83 std::vector<Spread> displacements() const;
84 protected:
85 virtual Natural calibrationImpl_(Natural numberOfFactors,
86
87 Natural innerMaxIterations,
88 Real innerTolerance) = 0;
89 // input
91 ext::shared_ptr<PiecewiseConstantCorrelation> corr_;
92 std::vector<ext::shared_ptr<PiecewiseConstantVariance> >
94
95 std::vector<Volatility> mktCapletVols_, mdlCapletVols_;
96 std::vector<Volatility> mktSwaptionVols_, mdlSwaptionVols_;
97 std::vector<std::vector<Volatility> > timeDependentCalibratedSwaptionVols_;
98
99 ext::shared_ptr<CurveState> cs_;
102 // working variables
103 std::vector<Volatility> usedCapletVols_;
104 // results
110 std::vector<Matrix> swapCovariancePseudoRoots_;
111 };
112
113 // inline
114
115 inline const std::vector<Volatility>&
117 return mktCapletVols_;
118 }
119
120 inline const std::vector<Volatility>&
122 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
123 return mdlCapletVols_;
124 }
125
126 inline const std::vector<Volatility>&
128 return mktSwaptionVols_;
129 }
130
131 inline const std::vector<Volatility>&
133 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
134 return mdlSwaptionVols_;
135 }
136
138 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
139 return failures_;
140 }
141
143 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
144 return deformationSize_;
145 }
146
148 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
149 return capletRmsError_;
150 }
151
153 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
154 return capletMaxError_;
155 }
156
158 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
159 return swaptionRmsError_;
160 }
161
163 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
164 return swaptionMaxError_;
165 }
166
167 inline const std::vector<Matrix>&
169 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
171 }
172
173 inline const Matrix&
175 QL_REQUIRE(calibrated_, "not successfully calibrated yet");
177 i << "is an invalid index, must be less than "
180 }
181
182 inline const ext::shared_ptr<CurveState>&
184 return cs_;
185 }
186
187 inline std::vector<Spread>
189 return std::vector<Volatility>(numberOfRates_, displacement_);
190 }
191
192}
193
194#endif
ext::shared_ptr< PiecewiseConstantCorrelation > corr_
std::vector< std::vector< Volatility > > timeDependentCalibratedSwaptionVols_
const std::vector< Volatility > & timeDependentCalibratedSwaptionVols(Size i) const
std::vector< Volatility > mktCapletVols_
ext::shared_ptr< CurveState > cs_
const ext::shared_ptr< CurveState > & curveState() const
std::vector< Volatility > mktSwaptionVols_
bool calibrate(Natural numberOfFactors, Natural maxIterations, Real tolerance, Natural innerMaxIterations=100, Real innerTolerance=1e-8)
static void performChecks(const EvolutionDescription &evolution, const PiecewiseConstantCorrelation &corr, const std::vector< ext::shared_ptr< PiecewiseConstantVariance > > &displacedSwapVariances, const std::vector< Volatility > &mktCapletVols, const CurveState &cs)
virtual ~CTSMMCapletCalibration()=default
std::vector< Spread > displacements() const
std::vector< Volatility > mdlSwaptionVols_
std::vector< ext::shared_ptr< PiecewiseConstantVariance > > displacedSwapVariances_
const std::vector< Volatility > & mdlSwaptionVols() const
virtual Natural calibrationImpl_(Natural numberOfFactors, Natural innerMaxIterations, Real innerTolerance)=0
const std::vector< Matrix > & swapPseudoRoots() const
const Matrix & swapPseudoRoot(Size i) const
std::vector< Volatility > usedCapletVols_
const std::vector< Volatility > & mktSwaptionVols() const
const std::vector< Volatility > & timeDependentUnCalibratedSwaptionVols(Size i) const
const std::vector< Volatility > & mktCapletVols() const
std::vector< Volatility > mdlCapletVols_
const std::vector< Volatility > & mdlCapletVols() const
std::vector< Matrix > swapCovariancePseudoRoots_
Curve state for market-model simulations
Definition: curvestate.hpp:41
Market-model evolution description.
Matrix used in linear algebra.
Definition: matrix.hpp:41
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Spread
spreads on interest rates
Definition: types.hpp:74
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Maps shared_ptr to either the boost or std implementation.