Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
pricetermstructureadapter.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/pricetermstructureadapter.hpp
20 \brief PriceTermStructure adapter
21*/
22
23#ifndef quantext_price_term_structure_adapter_hpp
24#define quantext_price_term_structure_adapter_hpp
25
26#include <ql/patterns/lazyobject.hpp>
27#include <ql/quote.hpp>
28#include <ql/termstructures/yieldtermstructure.hpp>
29#include <ql/time/calendars/nullcalendar.hpp>
30
32
33namespace QuantExt {
34
35//! Adapter class for turning a PriceTermStructure in to a YieldTermStructure
36/*! This class takes a price term structure and an input yield curve and constructs
37 a yield curve such that the discount factor
38 \f$ P_p(0, t) \f$ at time \f$ t \f$ is given by:
39 \f[
40 P_p(0, t) = \exp(-s(t) t)
41 \f]
42 where \f$ s(t) \f$ is defined by:
43 \f[
44 \Pi(0, t) = S(0) \exp((z(t) - s(t)) t)
45 \f]
46 Here, \f$ \Pi(0, t) \f$ is the forward price of the underlying from the
47 input price curve, \f$ S(0) \f$ is its spot price and \f$ z(t) \f$ is the
48 continuously compounded zero rate from the input yield curve. The spot price is
49 determined from the price curve at time 0 by default. There are optional
50 parameters that allow using a price at a time other than 0 for the spot price.
51*/
52class PriceTermStructureAdapter : public QuantLib::YieldTermStructure {
53
54public:
55 PriceTermStructureAdapter(const QuantLib::ext::shared_ptr<PriceTermStructure>& priceCurve,
56 const QuantLib::ext::shared_ptr<QuantLib::YieldTermStructure>& discount,
57 QuantLib::Natural spotDays = 0,
58 const QuantLib::Calendar& spotCalendar = QuantLib::NullCalendar());
59
60 // Alternative ctor where the spot quote handle is explicitly set
61 PriceTermStructureAdapter(const QuantLib::ext::shared_ptr<PriceTermStructure>& priceCurve,
62 const QuantLib::ext::shared_ptr<QuantLib::YieldTermStructure>& discount,
63 const QuantLib::Handle<QuantLib::Quote>& spotQuote);
64
65 //! \name TermStructure interface
66 //@{
67 QuantLib::Date maxDate() const override;
68 const QuantLib::Date& referenceDate() const override;
69 QuantLib::DayCounter dayCounter() const override;
70 //@}
71
72 //! \name Inspectors
73 //@{
74 const QuantLib::ext::shared_ptr<PriceTermStructure>& priceCurve() const;
75 const QuantLib::ext::shared_ptr<QuantLib::YieldTermStructure>& discount() const;
76 QuantLib::Natural spotDays() const;
77 const QuantLib::Calendar& spotCalendar() const;
78 //@}
79
80protected:
81 //! \name YieldTermStructure interface
82 //@{
83 QuantLib::DiscountFactor discountImpl(QuantLib::Time t) const override;
84 //@}
85
86private:
87 QuantLib::ext::shared_ptr<PriceTermStructure> priceCurve_;
88 QuantLib::ext::shared_ptr<QuantLib::YieldTermStructure> discount_;
89 QuantLib::Natural spotDays_;
90 QuantLib::Calendar spotCalendar_;
91 QuantLib::Handle<QuantLib::Quote> spotQuote_;
92};
93
94} // namespace QuantExt
95
96#endif
Adapter class for turning a PriceTermStructure in to a YieldTermStructure.
const QuantLib::Calendar & spotCalendar() const
QuantLib::ext::shared_ptr< PriceTermStructure > priceCurve_
PriceTermStructureAdapter(const QuantLib::ext::shared_ptr< PriceTermStructure > &priceCurve, const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > &discount, QuantLib::Natural spotDays=0, const QuantLib::Calendar &spotCalendar=QuantLib::NullCalendar())
QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > discount_
const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > & discount() const
const QuantLib::Date & referenceDate() const override
QuantLib::DayCounter dayCounter() const override
const QuantLib::ext::shared_ptr< PriceTermStructure > & priceCurve() const
QuantLib::Date maxDate() const override
PriceTermStructureAdapter(const QuantLib::ext::shared_ptr< PriceTermStructure > &priceCurve, const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > &discount, const QuantLib::Handle< QuantLib::Quote > &spotQuote)
QuantLib::DiscountFactor discountImpl(QuantLib::Time t) const override
QuantLib::Handle< QuantLib::Quote > spotQuote_
Term structure of prices.