QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cotswaptofwdadapter.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) 2006 Ferdinando Ametrano
5 Copyright (C) 2006 Mark Joshi
6 Copyright (C) 2007 StatPro Italia srl
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
27
28namespace QuantLib {
29
31 const ext::shared_ptr<MarketModel>& ctModel)
32 : coterminalModel_(ctModel),
33 numberOfFactors_(ctModel->numberOfFactors()),
34 numberOfRates_(ctModel->numberOfRates()),
35 numberOfSteps_(ctModel->numberOfSteps()),
36 pseudoRoots_(numberOfSteps_, Matrix(numberOfRates_, numberOfFactors_))
37 {
38
39 const std::vector<Spread>& displacements =
40 coterminalModel_->displacements();
41 for (Size i = 1; i<displacements.size(); ++i) {
43 io::ordinal(i+1) << " displacement (" <<
44 displacements[i] << ") not equal to the previous ones"
45 " (" << displacements[0] << ")");
46 }
47
48 const std::vector<Time>& rateTimes =
49 coterminalModel_->evolution().rateTimes();
50 // we must ensure we step through all rateTimes
51 const std::vector<Time>& evolutionTimes =
52 coterminalModel_->evolution().evolutionTimes();
53 for (Size i = 0;
54 i<rateTimes.size() && rateTimes[i]<=evolutionTimes.back(); ++i) {
55 QL_REQUIRE(std::find(evolutionTimes.begin(), evolutionTimes.end(),
56 rateTimes[i])!=evolutionTimes.end(),
57 "skipping " << io::ordinal(i+1) << " rate time");
58 }
59
60 CoterminalSwapCurveState cs(rateTimes);
61 const std::vector<Rate>& initialCoterminalSwapRates =
62 coterminalModel_->initialRates();
63 cs.setOnCoterminalSwapRates(initialCoterminalSwapRates);
65
67 cs, displacements[0]);
68 Matrix invertedZedMatrix = inverse(zedMatrix);
69
70 const std::vector<Size>& alive =
71 coterminalModel_->evolution().firstAliveRate();
72 for (Size k = 0; k<numberOfSteps_; ++k) {
73 pseudoRoots_[k]=invertedZedMatrix*coterminalModel_->pseudoRoot(k);
74 for (Size i=0; i<alive[k]; ++i)
75 std::fill(pseudoRoots_[k].row_begin(i),
76 pseudoRoots_[k].row_end(i),
77 0.0);
78 }
79 }
80
81
83 const ext::shared_ptr<MarketModelFactory>& coterminalFactory)
84 : coterminalFactory_(coterminalFactory) {
85 registerWith(coterminalFactory);
86 }
87
88 ext::shared_ptr<MarketModel>
90 const EvolutionDescription& evolution,
91 Size numberOfFactors) const {
92 ext::shared_ptr<MarketModel> coterminalModel =
93 coterminalFactory_->create(evolution,numberOfFactors);
94 return ext::shared_ptr<MarketModel>(
95 new CotSwapToFwdAdapter(coterminalModel));
96 }
97
100 }
101
102}
103
CotSwapToFwdAdapterFactory(const ext::shared_ptr< MarketModelFactory > &coterminalFactory)
ext::shared_ptr< MarketModelFactory > coterminalFactory_
ext::shared_ptr< MarketModel > create(const EvolutionDescription &, Size numberOfFactors) const override
const std::vector< Spread > & displacements() const override
CotSwapToFwdAdapter(const ext::shared_ptr< MarketModel > &coterminalModel)
std::vector< Matrix > pseudoRoots_
ext::shared_ptr< MarketModel > coterminalModel_
Curve state for coterminal-swap market models
void setOnCoterminalSwapRates(const std::vector< Rate > &swapRates, Size firstValidIndex=0)
const std::vector< Rate > & forwardRates() const override
Market-model evolution description.
Matrix used in linear algebra.
Definition: matrix.hpp:41
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
static Matrix coterminalSwapZedMatrix(const CurveState &cs, Spread displacement)
output manipulators
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Matrix inverse(const Matrix &m)
Definition: matrix.cpp:44
Utility functions for mapping between swap rate and forward rate.