Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedpricetermstructure.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
20
22
23using namespace QuantLib;
24
25namespace QuantExt {
26
28 const QuantLib::Handle<PriceTermStructure>& referenceCurve, const std::vector<QuantLib::Real>& times,
29 const std::vector<QuantLib::Handle<QuantLib::Quote>>& priceSpreads)
30 : PriceTermStructure(referenceCurve->dayCounter()), referenceCurve_(referenceCurve), times_(times),
31 priceSpreads_(priceSpreads), data_(times.size()) {
32 QL_REQUIRE(times_.size() > 1, "SpreadedPriceTermStructure: at least two times required");
33 QL_REQUIRE(times_.size() == priceSpreads_.size(),
34 "SpreadedPriceTermStructure: size of time and quote vectors do not match");
35 QL_REQUIRE(times_[0] == 0.0, "SpreadedPriceTermStructure: first time must be 0, got " << times_[0]);
36 for (auto const& q : priceSpreads_)
37 registerWith(q);
38 interpolation_ = QuantLib::ext::make_shared<FlatExtrapolation>(
39 QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin()));
40 interpolation_->enableExtrapolation();
41 registerWith(referenceCurve_);
42}
43
44Date SpreadedPriceTermStructure::maxDate() const { return referenceCurve_->maxDate(); }
45
47 LazyObject::update();
48 TermStructure::update();
49}
50
51const Date& SpreadedPriceTermStructure::referenceDate() const { return referenceCurve_->referenceDate(); }
52
53Calendar SpreadedPriceTermStructure::calendar() const { return referenceCurve_->calendar(); }
54
55Natural SpreadedPriceTermStructure::settlementDays() const { return referenceCurve_->settlementDays(); }
56
57QuantLib::Time SpreadedPriceTermStructure::minTime() const { return referenceCurve_->minTime(); }
58
59const QuantLib::Currency& SpreadedPriceTermStructure::currency() const { return referenceCurve_->currency(); }
60
61std::vector<QuantLib::Date> SpreadedPriceTermStructure::pillarDates() const { return referenceCurve_->pillarDates(); }
62
64 for (Size i = 0; i < times_.size(); ++i) {
65 QL_REQUIRE(!priceSpreads_[i].empty(), "SpreadedPriceTermStructure: quote at index " << i << " is empty");
66 data_[i] = priceSpreads_[i]->value();
67 }
68 interpolation_->update();
69}
70
71QuantLib::Real SpreadedPriceTermStructure::priceImpl(QuantLib::Time t) const {
72 calculate();
73 return referenceCurve_->price(t) + (*interpolation_)(t);
74}
75
76} // namespace QuantExt
QuantLib::ext::shared_ptr< QuantLib::Interpolation > interpolation_
QuantLib::Time minTime() const override
The minimum time for which the curve can return values.
QuantLib::Calendar calendar() const override
const QuantLib::Currency & currency() const override
The currency in which prices are expressed.
std::vector< QuantLib::Handle< QuantLib::Quote > > priceSpreads_
const QuantLib::Date & referenceDate() const override
SpreadedPriceTermStructure(const QuantLib::Handle< PriceTermStructure > &referenceCurve, const std::vector< QuantLib::Real > &times, const std::vector< QuantLib::Handle< QuantLib::Quote > > &priceSpreads)
times should be consistent with reference curve day counter
QuantLib::Natural settlementDays() const override
QuantLib::Handle< PriceTermStructure > referenceCurve_
std::vector< QuantLib::Date > pillarDates() const override
The pillar dates for the PriceTermStructure.
QuantLib::Real priceImpl(QuantLib::Time) const override
Price calculation.
flat interpolation decorator
Spreaded Term structure of prices.