QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
cotswapfromfwdcorrelation.cpp
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 François du Vignaud
6 Copyright (C) 2007 Chiara Fornarola
7 Copyright (C) 2007 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#include <ql/models/marketmodels/correlations/cotswapfromfwdcorrelation.hpp>
24#include <ql/models/marketmodels/curvestate.hpp>
25#include <ql/models/marketmodels/swapforwardmappings.hpp>
26#include <ql/math/matrixutilities/getcovariance.hpp>
27
28namespace QuantLib {
29
31 const ext::shared_ptr<PiecewiseConstantCorrelation>& fwdCorr,
32 const CurveState& curveState,
33 Spread displacement)
34 : fwdCorr_(fwdCorr),
35 numberOfRates_(fwdCorr->numberOfRates()),
36 swapCorrMatrices_(fwdCorr->correlations().size())
37 {
38 QL_REQUIRE(numberOfRates_==curveState.numberOfRates(),
39 "mismatch between number of rates in fwdCorr (" <<
40 numberOfRates_ << ") and curveState (" <<
41 curveState.numberOfRates() << ")");
42
44 curveState, displacement);
45 Matrix zedT = transpose(zed);
46 const std::vector<Matrix>& fwdCorrMatrices = fwdCorr->correlations();
47 for (Size k = 0; k<fwdCorrMatrices.size(); ++k) {
49 zed * fwdCorrMatrices[k] * zedT).correlationMatrix();
50 // zero expired rates' correlation coefficients
51 const std::vector<Time>& rateTimes = curveState.rateTimes();
52 const std::vector<Time>& corrTimes = fwdCorr_->times();
53 for (Size i=0; i<numberOfRates_; ++i)
54 for (Size j=0; j<=i; ++j)
55 if (corrTimes[k]>rateTimes[j])
56 swapCorrMatrices_[k][i][j] =
57 swapCorrMatrices_[k][j][i] = 0.0;
58 }
59 }
60
61 const std::vector<Time>& CotSwapFromFwdCorrelation::times() const {
62 return fwdCorr_->times();
63 }
64
65 const std::vector<Time>& CotSwapFromFwdCorrelation::rateTimes() const {
66 return fwdCorr_->rateTimes();
67 }
68
70 return numberOfRates_;
71 }
72
73 const std::vector<Matrix>&
75 return swapCorrMatrices_;
76 }
77
78}
const std::vector< Time > & rateTimes() const override
const std::vector< Time > & times() const override
const std::vector< Matrix > & correlations() const override
ext::shared_ptr< PiecewiseConstantCorrelation > fwdCorr_
CotSwapFromFwdCorrelation(const ext::shared_ptr< PiecewiseConstantCorrelation > &fwdCorr, const CurveState &curveState, Spread displacement)
Covariance decomposition into correlation and variances.
const Matrix & correlationMatrix() const
Curve state for market-model simulations
Definition: curvestate.hpp:41
Size numberOfRates() const
Definition: curvestate.hpp:58
const std::vector< Time > & rateTimes() const
Definition: curvestate.hpp:60
Matrix used in linear algebra.
Definition: matrix.hpp:41
static Matrix coterminalSwapZedMatrix(const CurveState &cs, Spread displacement)
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
Matrix transpose(const Matrix &m)
Definition: matrix.hpp:700