QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
timehomogeneousforwardcorrelation.cpp
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 François du Vignaud
5 Copyright (C) 2007 Chiara Fornarola
6 Copyright (C) 2007 Katiuscia Manzoni
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
25
26namespace QuantLib {
27
29 const Matrix& fwdCorrelation,
30 const std::vector<Time>& rateTimes)
31 : numberOfRates_(rateTimes.empty() ? 0 : rateTimes.size()-1),
32 fwdCorrelation_(fwdCorrelation),
33 rateTimes_(rateTimes),
34 times_(numberOfRates_) {
35
38 "Rate times must contain at least two values");
39 QL_REQUIRE(numberOfRates_==fwdCorrelation.rows(),
40 "mismatch between number of rates (" << numberOfRates_ <<
41 ") and fwdCorrelation rows (" << fwdCorrelation.rows() << ")");
42 QL_REQUIRE(numberOfRates_==fwdCorrelation.columns(),
43 "mismatch between number of rates (" << numberOfRates_ <<
44 ") and fwdCorrelation columns (" << fwdCorrelation.columns() << ")");
45
46 std::copy(rateTimes.begin(), rateTimes.end()-1, times_.begin());
48 }
49
51 const Matrix& fwdCorrelation) {
52 Size numberOfRates = fwdCorrelation.rows();
55 0.0));
56 for (Size k=0; k<correlations.size(); ++k) {
57 // proper diagonal values
58 for (Size i=k; i<numberOfRates; ++i)
59 correlations[k][i][i] = 1.0;
60 // copy only time homogeneous values
61 for (Size i=k; i<numberOfRates; ++i) {
62 for (Size j=k; j<i; ++j) {
63 correlations[k][i][j] = correlations[k][j][i] =
64 fwdCorrelation[i-k][j-k];
65 }
66 }
67 }
68 return correlations;
69 }
70
71 const std::vector<Time>&
73 return times_;
74 }
75
76 const std::vector<Time>&
78 return rateTimes_;
79 }
80
81 const std::vector<Matrix>&
83 return correlations_;
84 }
85
87 return numberOfRates_;
88 }
89
90}
Matrix used in linear algebra.
Definition: matrix.hpp:41
Size rows() const
Definition: matrix.hpp:504
Size columns() const
Definition: matrix.hpp:508
const std::vector< Time > & rateTimes() const override
TimeHomogeneousForwardCorrelation(const Matrix &fwdCorrelation, const std::vector< Time > &rateTimes)
const std::vector< Time > & times() const override
static std::vector< Matrix > evolvedMatrices(const Matrix &fwdCorrelation)
const std::vector< Matrix > & correlations() const override
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
void checkIncreasingTimes(const std::vector< Time > &times)
check for strictly increasing times, first time greater than zero
Definition: utilities.cpp:92
pseudo square root of a real symmetric matrix