Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
pricetermstructure.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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
21using namespace QuantLib;
22
23namespace QuantExt {
24
25PriceTermStructure::PriceTermStructure(const DayCounter& dc) : TermStructure(dc) {}
26
27PriceTermStructure::PriceTermStructure(const Date& referenceDate, const Calendar& cal, const DayCounter& dc)
28 : TermStructure(referenceDate, cal, dc) {}
29
30PriceTermStructure::PriceTermStructure(Natural settlementDays, const Calendar& cal, const DayCounter& dc)
31 : TermStructure(settlementDays, cal, dc) {}
32
33Real PriceTermStructure::price(Time t, bool extrapolate) const {
34 checkRange(t, extrapolate);
35 return priceImpl(t);
36}
37
38Real PriceTermStructure::price(const Date& d, bool extrapolate) const {
39 return price(timeFromReference(d), extrapolate);
40}
41
42void PriceTermStructure::update() { TermStructure::update(); }
43
45 // Default implementation
46 return 0.0;
47}
48
49void PriceTermStructure::checkRange(Time t, bool extrapolate) const {
50 QL_REQUIRE(extrapolate || allowsExtrapolation() || t >= minTime() || close_enough(t, minTime()),
51 "time (" << t << ") is before min curve time (" << minTime() << ")");
52
53 // Now, do the usual TermStructure checks
54 TermStructure::checkRange(t, extrapolate);
55}
56
57DerivedPriceQuote::DerivedPriceQuote(const QuantLib::Handle<PriceTermStructure>& priceTs) : priceTs_(priceTs) {
58 registerWith(priceTs_);
59}
60
62 QL_REQUIRE(isValid(), "Invalid DerivedPriceQuote");
63 return priceTs_->price(0, true);
64}
65
66bool DerivedPriceQuote::isValid() const { return !priceTs_.empty(); }
67
68void DerivedPriceQuote::update() { notifyObservers(); }
69
70} // namespace QuantExt
DerivedPriceQuote(const QuantLib::Handle< PriceTermStructure > &priceTs)
QuantLib::Real value() const override
QuantLib::Handle< PriceTermStructure > priceTs_
bool isValid() const override
virtual QuantLib::Time minTime() const
The minimum time for which the curve can return values.
PriceTermStructure(const QuantLib::DayCounter &dc=QuantLib::DayCounter())
void checkRange(QuantLib::Time t, bool extrapolate) const
Extra time range check for minimum time, then calls TermStructure::checkRange.
virtual QuantLib::Real priceImpl(QuantLib::Time) const =0
Price calculation.
QuantLib::Real price(QuantLib::Time t, bool extrapolate=false) const
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
Term structure of prices.