Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
pricetermstructure.hpp
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
19/*! \file qle/termstructures/pricetermstructure.hpp
20 \brief Term structure of prices
21*/
22
23#ifndef quantext_price_term_structure_hpp
24#define quantext_price_term_structure_hpp
25
26#include <ql/currency.hpp>
27#include <ql/math/comparison.hpp>
28#include <ql/quote.hpp>
29#include <ql/termstructure.hpp>
30
31namespace QuantExt {
32
33//! Price term structure
34/*! This abstract class defines the interface of concrete
35 price term structures which will be derived from this one.
36
37 \ingroup termstructures
38*/
39class PriceTermStructure : public QuantLib::TermStructure {
40public:
41 //! \name Constructors
42 //@{
43 PriceTermStructure(const QuantLib::DayCounter& dc = QuantLib::DayCounter());
44 PriceTermStructure(const QuantLib::Date& referenceDate, const QuantLib::Calendar& cal = QuantLib::Calendar(),
45 const QuantLib::DayCounter& dc = QuantLib::DayCounter());
46 PriceTermStructure(QuantLib::Natural settlementDays, const QuantLib::Calendar& cal,
47 const QuantLib::DayCounter& dc = QuantLib::DayCounter());
48 //@}
49
50 //! \name Prices
51 //@{
52 QuantLib::Real price(QuantLib::Time t, bool extrapolate = false) const;
53 QuantLib::Real price(const QuantLib::Date& d, bool extrapolate = false) const;
54 //@}
55
56 //! \name Observer interface
57 //@{
58 void update() override;
59 //@}
60
61 //! The minimum time for which the curve can return values
62 virtual QuantLib::Time minTime() const;
63
64 //! The currency in which prices are expressed
65 virtual const QuantLib::Currency& currency() const = 0;
66
67 //! The pillar dates for the PriceTermStructure
68 virtual std::vector<QuantLib::Date> pillarDates() const = 0;
69
70protected:
71 /*! \name Calculations
72
73 This method must be implemented in derived classes to
74 perform the actual calculations.
75 */
76 //@{
77 //! Price calculation
78 virtual QuantLib::Real priceImpl(QuantLib::Time) const = 0;
79 //@}
80
81 //! Extra time range check for minimum time, then calls TermStructure::checkRange
82 void checkRange(QuantLib::Time t, bool extrapolate) const;
83};
84
85//! Helper class so that the spot price can be pulled from the price curve each time the spot price is requested.
86class DerivedPriceQuote : public QuantLib::Quote, public QuantLib::Observer {
87
88public:
89 DerivedPriceQuote(const QuantLib::Handle<PriceTermStructure>& priceTs);
90
91 //! \name Quote interface
92 //@{
93 QuantLib::Real value() const override;
94 bool isValid() const override;
95 //@}
96
97 //! \name Observer interface
98 //@{
99 void update() override;
100 //@}
101
102private:
103 QuantLib::Handle<PriceTermStructure> priceTs_;
104};
105
106} // namespace QuantExt
107
108#endif
Helper class so that the spot price can be pulled from the price curve each time the spot price is re...
QuantLib::Real value() const override
QuantLib::Handle< PriceTermStructure > priceTs_
bool isValid() const override
QuantLib::Real price(const QuantLib::Date &d, bool extrapolate=false) const
virtual std::vector< QuantLib::Date > pillarDates() const =0
The pillar dates for the PriceTermStructure.
virtual QuantLib::Time minTime() const
The minimum time for which the curve can return values.
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
PriceTermStructure(QuantLib::Natural settlementDays, const QuantLib::Calendar &cal, const QuantLib::DayCounter &dc=QuantLib::DayCounter())
virtual const QuantLib::Currency & currency() const =0
The currency in which prices are expressed.
PriceTermStructure(const QuantLib::Date &referenceDate, const QuantLib::Calendar &cal=QuantLib::Calendar(), const QuantLib::DayCounter &dc=QuantLib::DayCounter())