QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fwdtocotswapadapter.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>& fwdModel)
32 : fwdModel_(fwdModel),
33 numberOfFactors_(fwdModel->numberOfFactors()),
34 numberOfRates_(fwdModel->numberOfRates()),
35 numberOfSteps_(fwdModel->numberOfSteps()),
36 pseudoRoots_(numberOfSteps_, Matrix(numberOfRates_, numberOfFactors_))
37 {
38
39 const std::vector<Spread>& displacements =
40 fwdModel_->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 fwdModel_->evolution().rateTimes();
50 // we must ensure we step through all rateTimes
51 const std::vector<Time>& evolutionTimes =
52 fwdModel_->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 LMMCurveState cs(rateTimes);
61 const std::vector<Rate>& initialFwdRates =
62 fwdModel_->initialRates();
63 cs.setOnForwardRates(initialFwdRates);
65
67 cs, displacements[0]);
68
69
70 const std::vector<Size>& alive =
71 fwdModel_->evolution().firstAliveRate();
72 for (Size k = 0; k<numberOfSteps_; ++k) {
73 pseudoRoots_[k]=zedMatrix*fwdModel_->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>& forwardFactory)
84 : forwardFactory_(forwardFactory) {
85 registerWith(forwardFactory);
86 }
87
88 ext::shared_ptr<MarketModel>
90 const EvolutionDescription& evolution,
91 Size numberOfFactors) const {
92 ext::shared_ptr<MarketModel> forwardModel =
93 forwardFactory_->create(evolution,numberOfFactors);
94 return ext::shared_ptr<MarketModel>(
95 new FwdToCotSwapAdapter(forwardModel));
96 }
97
100 }
101
102}
103
Market-model evolution description.
FwdToCotSwapAdapterFactory(const ext::shared_ptr< MarketModelFactory > &forwardFactory)
ext::shared_ptr< MarketModelFactory > forwardFactory_
ext::shared_ptr< MarketModel > create(const EvolutionDescription &, Size numberOfFactors) const override
const std::vector< Spread > & displacements() const override
std::vector< Matrix > pseudoRoots_
ext::shared_ptr< MarketModel > fwdModel_
FwdToCotSwapAdapter(const ext::shared_ptr< MarketModel > &forwardModel)
Curve state for Libor market models
void setOnForwardRates(const std::vector< Rate > &fwdRates, Size firstValidIndex=0)
const std::vector< Rate > & coterminalSwapRates() const override
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
Utility functions for mapping between swap rate and forward rate.