Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
PriceTermStructureAdapter Class Reference

Adapter class for turning a PriceTermStructure in to a YieldTermStructure. More...

#include <qle/termstructures/pricetermstructureadapter.hpp>

+ Inheritance diagram for PriceTermStructureAdapter:
+ Collaboration diagram for PriceTermStructureAdapter:

Public Member Functions

 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())
 
 PriceTermStructureAdapter (const QuantLib::ext::shared_ptr< PriceTermStructure > &priceCurve, const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > &discount, const QuantLib::Handle< QuantLib::Quote > &spotQuote)
 
TermStructure interface
QuantLib::Date maxDate () const override
 
const QuantLib::Date & referenceDate () const override
 
QuantLib::DayCounter dayCounter () const override
 
Inspectors
const QuantLib::ext::shared_ptr< PriceTermStructure > & priceCurve () const
 
const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > & discount () const
 
QuantLib::Natural spotDays () const
 
const QuantLib::Calendar & spotCalendar () const
 

YieldTermStructure interface

QuantLib::ext::shared_ptr< PriceTermStructurepriceCurve_
 
QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > discount_
 
QuantLib::Natural spotDays_
 
QuantLib::Calendar spotCalendar_
 
QuantLib::Handle< QuantLib::Quote > spotQuote_
 
QuantLib::DiscountFactor discountImpl (QuantLib::Time t) const override
 

Detailed Description

Adapter class for turning a PriceTermStructure in to a YieldTermStructure.

This class takes a price term structure and an input yield curve and constructs a yield curve such that the discount factor \( P_p(0, t) \) at time \( t \) is given by:

\[ P_p(0, t) = \exp(-s(t) t) \]

where \( s(t) \) is defined by:

\[ \Pi(0, t) = S(0) \exp((z(t) - s(t)) t) \]

Here, \( \Pi(0, t) \) is the forward price of the underlying from the input price curve, \( S(0) \) is its spot price and \( z(t) \) is the continuously compounded zero rate from the input yield curve. The spot price is determined from the price curve at time 0 by default. There are optional parameters that allow using a price at a time other than 0 for the spot price.

Definition at line 52 of file pricetermstructureadapter.hpp.

Constructor & Destructor Documentation

◆ PriceTermStructureAdapter() [1/2]

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() 
)

◆ PriceTermStructureAdapter() [2/2]

PriceTermStructureAdapter ( const QuantLib::ext::shared_ptr< PriceTermStructure > &  priceCurve,
const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > &  discount,
const QuantLib::Handle< QuantLib::Quote > &  spotQuote 
)

Member Function Documentation

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 53 of file pricetermstructureadapter.cpp.

53 {
54 // Take the min of the two underlying curves' max date
55 // Extrapolation will be determined by each underlying curve individually
56 return min(priceCurve_->maxDate(), discount_->maxDate());
57}
QuantLib::ext::shared_ptr< PriceTermStructure > priceCurve_
QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > discount_
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
+ Here is the call graph for this function:

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 59 of file pricetermstructureadapter.cpp.

59 {
60 QL_REQUIRE(
61 priceCurve_->referenceDate() == discount_->referenceDate(),
62 "PriceTermStructureAdapter: The reference date of the discount curve and price curve should be the same");
63 return priceCurve_->referenceDate();
64}

◆ dayCounter()

DayCounter dayCounter ( ) const
override

Definition at line 66 of file pricetermstructureadapter.cpp.

66{ return priceCurve_->dayCounter(); }

◆ priceCurve()

const QuantLib::ext::shared_ptr< PriceTermStructure > & priceCurve ( ) const

Definition at line 68 of file pricetermstructureadapter.cpp.

68{ return priceCurve_; }

◆ discount()

const QuantLib::ext::shared_ptr< YieldTermStructure > & discount ( ) const

Definition at line 70 of file pricetermstructureadapter.cpp.

70{ return discount_; }

◆ spotDays()

Natural spotDays ( ) const

Definition at line 72 of file pricetermstructureadapter.cpp.

◆ spotCalendar()

const Calendar & spotCalendar ( ) const

Definition at line 74 of file pricetermstructureadapter.cpp.

◆ discountImpl()

DiscountFactor discountImpl ( QuantLib::Time  t) const
overrideprotected

Definition at line 76 of file pricetermstructureadapter.cpp.

76 {
77 if (t == 0.0)
78 return 1.0;
79 // Returns discount factor exp(-s(t) * t) where s(t) is defined such that
80 // FP(0, t) = S(0) exp([z(t) - s(t)] t)
81 Real spotPrice;
82 if (spotQuote_.empty()) {
83 Time spotTime = timeFromReference(spotCalendar_.advance(referenceDate(), spotDays_ * Days));
84 spotPrice = priceCurve_->price(spotTime, true);
85 } else {
86 spotPrice = spotQuote_->value();
87 }
88 Real forwardPrice = priceCurve_->price(t, true);
89 DiscountFactor discount = discount_->discount(t, true);
90 return discount * forwardPrice / spotPrice;
91}
const QuantLib::ext::shared_ptr< QuantLib::YieldTermStructure > & discount() const
const QuantLib::Date & referenceDate() const override
QuantLib::Handle< QuantLib::Quote > spotQuote_

Member Data Documentation

◆ priceCurve_

QuantLib::ext::shared_ptr<PriceTermStructure> priceCurve_
private

Definition at line 87 of file pricetermstructureadapter.hpp.

◆ discount_

QuantLib::ext::shared_ptr<QuantLib::YieldTermStructure> discount_
private

Definition at line 88 of file pricetermstructureadapter.hpp.

◆ spotDays_

QuantLib::Natural spotDays_
private

Definition at line 89 of file pricetermstructureadapter.hpp.

◆ spotCalendar_

QuantLib::Calendar spotCalendar_
private

Definition at line 90 of file pricetermstructureadapter.hpp.

◆ spotQuote_

QuantLib::Handle<QuantLib::Quote> spotQuote_
private

Definition at line 91 of file pricetermstructureadapter.hpp.