Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedinflationcurve.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
21
22namespace QuantExt {
23
24SpreadedZeroInflationCurve::SpreadedZeroInflationCurve(const Handle<ZeroInflationTermStructure>& referenceCurve,
25 const std::vector<Time>& times,
26 const std::vector<Handle<Quote>>& quotes)
27 : ZeroInflationTermStructure(referenceCurve->dayCounter(), referenceCurve->baseRate(),
28 referenceCurve->observationLag(), referenceCurve->frequency(),
29 referenceCurve->seasonality()),
30 referenceCurve_(referenceCurve), times_(times), quotes_(quotes), data_(times_.size(), 1.0) {
31 QL_REQUIRE(times_.size() > 1, "SpreadedZeroInflationCurve: at least two times required");
32 QL_REQUIRE(times_.size() == quotes.size(),
33 "SpreadedZeroInflationCurve: size of time and quote vectors do not match");
34 for (Size i = 0; i < quotes.size(); ++i) {
35 registerWith(quotes_[i]);
36 }
37 interpolation_ = QuantLib::ext::make_shared<FlatExtrapolation>(
38 QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin()));
39 interpolation_->enableExtrapolation();
40 registerWith(referenceCurve_);
41}
42
43Date SpreadedZeroInflationCurve::baseDate() const { return referenceCurve_->baseDate(); }
44
45Date SpreadedZeroInflationCurve::maxDate() const { return referenceCurve_->maxDate(); }
46
48 LazyObject::update();
49 TermStructure::update();
50}
51
52const Date& SpreadedZeroInflationCurve::referenceDate() const { return referenceCurve_->referenceDate(); }
53
54Calendar SpreadedZeroInflationCurve::calendar() const { return referenceCurve_->calendar(); }
55
56Natural SpreadedZeroInflationCurve::settlementDays() const { return referenceCurve_->settlementDays(); }
57
59 for (Size i = 0; i < times_.size(); ++i) {
60 QL_REQUIRE(!quotes_[i].empty(), "SpreadedZeroInflationCurve: quote at index " << i << " is empty");
61 data_[i] = quotes_[i]->value();
62 }
63 interpolation_->update();
64}
65
67 calculate();
68 return referenceCurve_->zeroRate(t) + (*interpolation_)(t);
69}
70
71SpreadedYoYInflationCurve::SpreadedYoYInflationCurve(const Handle<YoYInflationTermStructure>& referenceCurve,
72 const std::vector<Time>& times,
73 const std::vector<Handle<Quote>>& quotes)
74 : YoYInflationTermStructure(referenceCurve->dayCounter(), referenceCurve->baseRate(),
75 referenceCurve->observationLag(), referenceCurve->frequency(),
76 referenceCurve->indexIsInterpolated(), referenceCurve->seasonality()),
77 referenceCurve_(referenceCurve), times_(times), quotes_(quotes), data_(times_.size(), 1.0) {
78 QL_REQUIRE(times_.size() > 1, "SpreadedZeroInflationCurve: at least two times required");
79 QL_REQUIRE(times_.size() == quotes.size(),
80 "SpreadedZeroInflationCurve: size of time and quote vectors do not match");
81 for (Size i = 0; i < quotes.size(); ++i) {
82 registerWith(quotes_[i]);
83 }
84 interpolation_ = QuantLib::ext::make_shared<FlatExtrapolation>(
85 QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin()));
86 interpolation_->enableExtrapolation();
87 registerWith(referenceCurve_);
88}
89
90Date SpreadedYoYInflationCurve::baseDate() const { return referenceCurve_->baseDate(); }
91
92Date SpreadedYoYInflationCurve::maxDate() const { return referenceCurve_->maxDate(); }
93
95 LazyObject::update();
96 TermStructure::update();
97}
98
99const Date& SpreadedYoYInflationCurve::referenceDate() const { return referenceCurve_->referenceDate(); }
100
101Calendar SpreadedYoYInflationCurve::calendar() const { return referenceCurve_->calendar(); }
102
103Natural SpreadedYoYInflationCurve::settlementDays() const { return referenceCurve_->settlementDays(); }
104
106 for (Size i = 0; i < times_.size(); ++i) {
107 QL_REQUIRE(!quotes_[i].empty(), "SpreadedYoYInflationCurve: quote at index " << i << " is empty");
108 data_[i] = quotes_[i]->value();
109 }
110 interpolation_->update();
111}
112
114 calculate();
115 return referenceCurve_->yoyRate(t) + (*interpolation_)(t);
116}
117
118} // namespace QuantExt
const Date & referenceDate() const override
Handle< YoYInflationTermStructure > referenceCurve_
SpreadedYoYInflationCurve(const Handle< YoYInflationTermStructure > &referenceCurve, const std::vector< Time > &times, const std::vector< Handle< Quote > > &quotes)
times should be consistent with reference ts day counter
std::vector< Handle< Quote > > quotes_
QuantLib::ext::shared_ptr< Interpolation > interpolation_
SpreadedZeroInflationCurve(const Handle< ZeroInflationTermStructure > &referenceCurve, const std::vector< Time > &times, const std::vector< Handle< Quote > > &quotes)
times should be consistent with reference ts day counter
const Date & referenceDate() const override
std::vector< Handle< Quote > > quotes_
Handle< ZeroInflationTermStructure > referenceCurve_
QuantLib::ext::shared_ptr< Interpolation > interpolation_
flat interpolation decorator
spreaded inflation term structure