QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
pseudorootfacade.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 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
24#include <utility>
25
26namespace QuantLib {
27
28 PseudoRootFacade::PseudoRootFacade(const ext::shared_ptr<CTSMMCapletCalibration>& c)
29 : numberOfFactors_(c->swapPseudoRoots().front().columns()),
30 numberOfRates_(c->swapPseudoRoots().front().rows()),
31 numberOfSteps_(c->swapPseudoRoots().size()),
32 initialRates_(c->curveState()->coterminalSwapRates()), displacements_(c->displacements()),
33 evolution_(c->curveState()->rateTimes()), covariancePseudoRoots_(c->swapPseudoRoots()) {}
34
35
36 PseudoRootFacade::PseudoRootFacade(const std::vector<Matrix>& covariancePseudoRoots,
37 const std::vector<Rate>& rateTimes,
38 std::vector<Rate> initialRates,
39 const std::vector<Spread>& displacements)
40 : numberOfFactors_(covariancePseudoRoots.front().columns()),
41 numberOfRates_(covariancePseudoRoots.front().rows()),
42 numberOfSteps_(covariancePseudoRoots.size()), initialRates_(std::move(initialRates)),
43 displacements_(displacements), evolution_(rateTimes),
44 covariancePseudoRoots_(covariancePseudoRoots) {
45 checkIncreasingTimes(rateTimes);
46 QL_REQUIRE(rateTimes.size()>1,
47 "Rate times must contain at least two values");
48 QL_REQUIRE(numberOfRates_==rateTimes.size()-1,
49 "mismatch between number of rates (" << numberOfRates_ <<
50 ") and rate times");
52 "mismatch between number of rates (" << numberOfRates_ <<
53 ") and displacements (" << displacements.size() << ")");
55 "number of rates (" << numberOfRates_ <<
56 ") greater than number of factors (" << numberOfFactors_
57 << ") times number of steps (" << numberOfSteps_ << ")");
58
59 // evolutionTimes are not given for the time being
60 QL_REQUIRE(numberOfRates_==covariancePseudoRoots.size(),
61 "number of rates (" << numberOfRates_ <<
62 ") must be equal to covariancePseudoRoots.size() (" <<
63 covariancePseudoRoots.size() << ")");
64
65 for (Size k=0; k<numberOfSteps_; ++k) {
67 "step " << k
68 << ": pseudoRoot has wrong number of rows: "
69 << covariancePseudoRoots_[k].rows()
70 << " instead of " << numberOfRates_);
71 // not really mandatory
73 "step " << k
74 << ": pseudoRoot has wrong number of columns: "
75 << covariancePseudoRoots_[k].columns()
76 << " instead of " << numberOfFactors_);
77 }
78 }
79}
const std::vector< Spread > & displacements() const override
PseudoRootFacade(const ext::shared_ptr< CTSMMCapletCalibration > &calibrator)
std::vector< Matrix > covariancePseudoRoots_
#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
STL namespace.
pseudo square root of a real symmetric matrix