QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
sensitivityanalysis.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) 2008, 2010 Ferdinando Ametrano
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20/*! \file sensitivityanalysis.hpp
21 \brief sensitivity analysis function
22*/
23
24#ifndef quantlib_sensitivity_analysis_hpp
25#define quantlib_sensitivity_analysis_hpp
26
27#include <ql/types.hpp>
28#include <ql/utilities/null.hpp>
29#include <ql/shared_ptr.hpp>
30#include <vector>
31
32namespace QuantLib {
33
34 template <class T>
35 class Handle;
36 class Quote;
37 class SimpleQuote;
38 class Instrument;
39
40 //! Finite differences calculation
42 OneSide, /*!< */
43 Centered /*!< */
44 };
45
46 /*! \relates SensitivityAnalysis */
47 std::ostream& operator<<(std::ostream&,
49
50 //! utility fuction for weighted sum of NPVs
51 Real aggregateNPV(const std::vector<ext::shared_ptr<Instrument> >&,
52 const std::vector<Real>& quantities);
53
54 //! parallel shift PV01 sensitivity analysis for a SimpleQuote vector
55 /*! returns a pair of first and second derivative values calculated as
56 prescribed by SensitivityAnalysis. Second derivative might not be
57 available depending on SensitivityAnalysis value.
58
59 Empty quantities vector is considered as unit vector. The same if
60 the vector is just one single element equal to one.
61
62 All SimpleQuotes are tweaked together in a parallel fashion.
63 */
64 std::pair<Real, Real>
65 parallelAnalysis(const std::vector<Handle<SimpleQuote> >&,
66 const std::vector<ext::shared_ptr<Instrument> >&,
67 const std::vector<Real>& quantities,
68 Real shift = 0.0001,
70 Real referenceNpv = Null<Real>());
71
72 //! parallel shift PV01 sensitivity analysis for a SimpleQuote matrix
73 /*! returns a pair of first and second derivative values calculated as
74 prescribed by SensitivityAnalysis. Second derivative might not be
75 available depending on SensitivityAnalysis value.
76
77 Empty quantities vector is considered as unit vector. The same if
78 the vector is of size one.
79
80 All SimpleQuotes are tweaked together in a parallel fashion.
81 */
82 std::pair<Real, Real>
83 parallelAnalysis(const std::vector<std::vector<Handle<SimpleQuote> > >&,
84 const std::vector<ext::shared_ptr<Instrument> >&,
85 const std::vector<Real>& quantities,
86 Real shift = 0.0001,
88 Real referenceNpv = Null<Real>());
89
90 //! (bucket) PV01 sensitivity analysis for a (single) SimpleQuote
91 /*! returns a pair of first and second derivative values calculated as
92 prescribed by SensitivityAnalysis. Second derivative might not be
93 available depending on SensitivityAnalysis value.
94
95 Empty quantities vector is considered as unit vector. The same if
96 the vector is of size one.
97 */
98 std::pair<Real, Real> bucketAnalysis(const Handle<SimpleQuote>& quote,
99 const std::vector<ext::shared_ptr<Instrument> >&,
100 const std::vector<Real>& quantities,
101 Real shift = 0.0001,
103 Real referenceNpv = Null<Real>());
104
105 //! (bucket) parameters' sensitivity analysis for a (single) SimpleQuote
106 /*! returns a vector (one element for each paramet) of pair of first and
107 second derivative values calculated as prescribed by
108 SensitivityAnalysis. Second derivative might not be available
109 depending on SensitivityAnalysis value.
110
111 Empty quantities vector is considered as unit vector. The same if
112 the vector is of size one.
113 */
114 void bucketAnalysis(std::vector<Real>& deltaVector, // result
115 std::vector<Real>& gammaVector, // result
116 std::vector<Real>& referenceValues,
117 const Handle<SimpleQuote>& quote,
118 const std::vector<Handle<Quote> >& parameters,
119 Real shift = 0.0001,
121
122 //! bucket PV01 sensitivity analysis for a SimpleQuote vector
123 /*! returns a pair of first and second derivative vectors calculated as
124 prescribed by SensitivityAnalysis. Second derivative might not be
125 available depending on SensitivityAnalysis value.
126
127 Empty quantities vector is considered as unit vector. The same if
128 the vector is of size one.
129
130 The (bucket) SimpleQuotes are tweaked one by one separately.
131 */
132 std::pair<std::vector<Real>, std::vector<Real> >
133 bucketAnalysis(const std::vector<Handle<SimpleQuote> >& quotes,
134 const std::vector<ext::shared_ptr<Instrument> >&,
135 const std::vector<Real>& quantities,
136 Real shift = 0.0001,
138
139 //! bucket parameters' sensitivity analysis for a SimpleQuote vector
140 /*! returns a vector (one element for each paramet) of pair of first and
141 second derivative vectors calculated as prescribed by
142 SensitivityAnalysis. Second derivative might not be available
143 depending on SensitivityAnalysis value.
144
145 Empty quantities vector is considered as unit vector. The same if
146 the vector is of size one.
147
148 The (bucket) SimpleQuotes are tweaked one by one separately.
149 */
150 void
151 bucketAnalysis(std::vector<std::vector<Real> >& deltaMatrix, // result
152 std::vector<std::vector<Real> >& gammaMatrix, // result
153 const std::vector<Handle<SimpleQuote> >& quotes,
154 const std::vector<Handle<Quote> >& parameters,
155 Real shift = 0.0001,
157
158
159 //! bucket sensitivity analysis for a SimpleQuote matrix
160 /*! returns a pair of first and second derivative metrices calculated as
161 prescribed by SensitivityAnalysis. Second derivative might not be
162 available depending on SensitivityAnalysis value.
163
164 Empty quantities vector is considered as unit vector. The same if
165 the vector is of size one.
166
167 The (bucket) SimpleQuotes are tweaked one by one separately.
168 */
169 std::pair<std::vector<std::vector<Real> >, std::vector<std::vector<Real> > >
170 bucketAnalysis(const std::vector<std::vector<Handle<SimpleQuote> > >&,
171 const std::vector<ext::shared_ptr<Instrument> >&,
172 const std::vector<Real>& quantities,
173 Real shift = 0.0001,
175
176}
177
178#endif
Shared handle to an observable.
Definition: handle.hpp:41
template class providing a null value for a given type.
Definition: null.hpp:76
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Real aggregateNPV(const vector< ext::shared_ptr< Instrument > > &instruments, const vector< Real > &quant)
utility fuction for weighted sum of NPVs
pair< Real, Real > parallelAnalysis(const vector< Handle< SimpleQuote > > &quotes, const vector< ext::shared_ptr< Instrument > > &instruments, const vector< Real > &quantities, Real shift, SensitivityAnalysis type, Real referenceNpv)
parallel shift PV01 sensitivity analysis for a SimpleQuote vector
std::ostream & operator<<(std::ostream &out, GFunctionFactory::YieldCurveModel type)
pair< Real, Real > bucketAnalysis(const Handle< SimpleQuote > &quote, const vector< ext::shared_ptr< Instrument > > &instruments, const vector< Real > &quantities, Real shift, SensitivityAnalysis type, Real referenceNpv)
(bucket) PV01 sensitivity analysis for a (single) SimpleQuote
SensitivityAnalysis
Finite differences calculation.
null values
Maps shared_ptr to either the boost or std implementation.
Custom types.