QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
flatvol.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) 2006, 2007 Ferdinando Ametrano
5 Copyright (C) 2006 Chiara Fornarola
6 Copyright (C) 2006, 2007 StatPro Italia srl
7 Copyright (C) 2006 Katiuscia Manzoni
8
9 This file is part of QuantLib, a free-software/open-source library
10 for financial quantitative analysts and developers - http://quantlib.org/
11
12 QuantLib is free software: you can redistribute it and/or modify it
13 under the terms of the QuantLib license. You should have received a
14 copy of the license along with this program; if not, please email
15 <quantlib-dev@lists.sf.net>. The license is also available online at
16 <http://quantlib.org/license.shtml>.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the license for more details.
21*/
22
23
24#ifndef quantlib_exp_corr_flat_vol_hpp
25#define quantlib_exp_corr_flat_vol_hpp
26
29#include <ql/math/matrix.hpp>
32#include <ql/handle.hpp>
33#include <vector>
34
35namespace QuantLib {
36
37 class PiecewiseConstantCorrelation;
38
39 class FlatVol : public MarketModel {
40 public:
41 FlatVol(
42 const std::vector<Volatility>& volatilities,
43 const ext::shared_ptr<PiecewiseConstantCorrelation>& corr,
46 const std::vector<Rate>& initialRates,
47 const std::vector<Spread>& displacements);
48 //! \name MarketModel interface
49 //@{
50 const std::vector<Rate>& initialRates() const override;
51 const std::vector<Spread>& displacements() const override;
52 const EvolutionDescription& evolution() const override;
53 Size numberOfRates() const override;
54 Size numberOfFactors() const override;
55 Size numberOfSteps() const override;
56 const Matrix& pseudoRoot(Size i) const override;
57 //@}
58 private:
60 std::vector<Rate> initialRates_;
61 std::vector<Spread> displacements_;
63 std::vector<Matrix> pseudoRoots_;
64 };
65
67 public Observer {
68 public:
69 FlatVolFactory(Real longTermCorrelation,
70 Real beta,
71 // this is just to make it work---it
72 // should be replaced with something
73 // else (such as some kind of volatility
74 // structure)
75 std::vector<Time> times,
76 std::vector<Volatility> vols,
77 // this is OK
79 // this might have a structure
80 Spread displacement);
81 ext::shared_ptr<MarketModel> create(const EvolutionDescription&,
82 Size numberOfFactors) const override;
83 void update() override;
84
85 private:
87 // <to be changed>
88 std::vector<Time> times_;
89 std::vector<Volatility> vols_;
91 // </to be changed>
94 };
95
96
97 // inline definitions
98
99 inline const std::vector<Rate>& FlatVol::initialRates() const {
100 return initialRates_;
101 }
102
103 inline const std::vector<Spread>& FlatVol::displacements() const {
104 return displacements_;
105 }
106
108 return evolution_;
109 }
110
112 return initialRates_.size();
113 }
114
116 return numberOfFactors_;
117 }
118
120 return numberOfSteps_;
121 }
122
123 inline const Matrix& FlatVol::pseudoRoot(Size i) const {
125 "the index " << i << " is invalid: it must be less than "
126 "number of steps (" << numberOfSteps_ << ")");
127 return pseudoRoots_[i];
128 }
129}
130
131#endif
Market-model evolution description.
Interpolation volatility_
Definition: flatvol.hpp:90
void update() override
Definition: flatvol.cpp:201
std::vector< Time > times_
Definition: flatvol.hpp:88
std::vector< Volatility > vols_
Definition: flatvol.hpp:89
Handle< YieldTermStructure > yieldCurve_
Definition: flatvol.hpp:92
ext::shared_ptr< MarketModel > create(const EvolutionDescription &, Size numberOfFactors) const override
Definition: flatvol.cpp:165
const std::vector< Spread > & displacements() const override
Definition: flatvol.hpp:103
std::vector< Spread > displacements_
Definition: flatvol.hpp:61
const std::vector< Rate > & initialRates() const override
Definition: flatvol.hpp:99
std::vector< Matrix > pseudoRoots_
Definition: flatvol.hpp:63
const Matrix & pseudoRoot(Size i) const override
Definition: flatvol.hpp:123
std::vector< Rate > initialRates_
Definition: flatvol.hpp:60
const EvolutionDescription & evolution() const override
Definition: flatvol.hpp:107
EvolutionDescription evolution_
Definition: flatvol.hpp:62
Size numberOfFactors_
Definition: flatvol.hpp:59
Size numberOfFactors() const override
Definition: flatvol.hpp:115
Size numberOfRates() const override
Definition: flatvol.hpp:111
Size numberOfSteps() const override
Definition: flatvol.hpp:119
Shared handle to an observable.
Definition: handle.hpp:41
base class for 1-D interpolations.
base class for market-model factories
Definition: marketmodel.hpp:57
base class for market models
Definition: marketmodel.hpp:39
Matrix used in linear algebra.
Definition: matrix.hpp:41
Object that gets notified when a given observable changes.
Definition: observable.hpp:116
#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
Real Spread
spreads on interest rates
Definition: types.hpp:74
std::size_t Size
size of a container
Definition: types.hpp:58
Globally accessible relinkable pointer.
base class for 1-D interpolations
matrix used in linear algebra.
Definition: any.hpp:35
Real beta
Definition: sabr.cpp:200
Interest-rate term structure.