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

InterpolatedDiscountCurve based on loglinear interpolation of DiscountFactors. More...

#include <qle/termstructures/interpolateddiscountcurve.hpp>

+ Inheritance diagram for InterpolatedDiscountCurve:
+ Collaboration diagram for InterpolatedDiscountCurve:

Public Types

enum class  Interpolation { logLinear , linearZero }
 
enum class  Extrapolation { flatFwd , flatZero }
 

TermStructure interface

std::vector< Time > times_
 
std::vector< Time > timeDiffs_
 
std::vector< QuantLib::ext::shared_ptr< Quote > > quotes_
 
Interpolation interpolation_
 
Extrapolation extrapolation_
 
Date maxDate () const override
 
DiscountFactor discountImpl (Time t) const override
 

Constructors

 InterpolatedDiscountCurve (const std::vector< Time > &times, const std::vector< Handle< Quote > > &quotes, const Natural settlementDays, const Calendar &cal, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
 default constructor More...
 
 InterpolatedDiscountCurve (const std::vector< Date > &dates, const std::vector< Handle< Quote > > &quotes, const Natural settlementDays, const Calendar &cal, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
 constructor that takes a vector of dates More...
 
void initalise (const std::vector< Handle< Quote > > &quotes)
 

Detailed Description

InterpolatedDiscountCurve based on loglinear interpolation of DiscountFactors.

InterpolatedDiscountCurve based on loglinear interpolation of DiscountFactors, flat fwd extrapolation is always enabled, the term structure has always a floating reference date

\ingroup termstructures

Definition at line 41 of file interpolateddiscountcurve.hpp.

Member Enumeration Documentation

◆ Interpolation

enum class Interpolation
strong

◆ Extrapolation

enum class Extrapolation
strong

Constructor & Destructor Documentation

◆ InterpolatedDiscountCurve() [1/2]

InterpolatedDiscountCurve ( const std::vector< Time > &  times,
const std::vector< Handle< Quote > > &  quotes,
const Natural  settlementDays,
const Calendar &  cal,
const DayCounter &  dc,
const Interpolation  interpolation = Interpolation::logLinear,
const Extrapolation  extrapolation = Extrapolation::flatFwd 
)

default constructor

Definition at line 48 of file interpolateddiscountcurve.hpp.

52 : YieldTermStructure(settlementDays, cal, dc), times_(times), interpolation_(interpolation),
53 extrapolation_(extrapolation) {
54 initalise(quotes);
55 }
void initalise(const std::vector< Handle< Quote > > &quotes)
+ Here is the call graph for this function:

◆ InterpolatedDiscountCurve() [2/2]

InterpolatedDiscountCurve ( const std::vector< Date > &  dates,
const std::vector< Handle< Quote > > &  quotes,
const Natural  settlementDays,
const Calendar &  cal,
const DayCounter &  dc,
const Interpolation  interpolation = Interpolation::logLinear,
const Extrapolation  extrapolation = Extrapolation::flatFwd 
)

constructor that takes a vector of dates

Definition at line 58 of file interpolateddiscountcurve.hpp.

62 : YieldTermStructure(settlementDays, cal, dc), times_(dates.size()), interpolation_(interpolation),
63 extrapolation_(extrapolation) {
64 for (Size i = 0; i < dates.size(); ++i)
65 times_[i] = timeFromReference(dates[i]);
66 initalise(quotes);
67 }
+ Here is the call graph for this function:

Member Function Documentation

◆ initalise()

void initalise ( const std::vector< Handle< Quote > > &  quotes)
private

Definition at line 71 of file interpolateddiscountcurve.hpp.

71 {
72 QL_REQUIRE(times_.size() > 1, "at least two times required");
73 QL_REQUIRE(times_[0] == 0.0, "First time must be 0, got " << times_[0]); // or date=asof
74 QL_REQUIRE(times_.size() == quotes.size(), "size of time and quote vectors do not match");
75 for (Size i = 0; i < quotes.size(); ++i) {
76 quotes_.push_back(QuantLib::ext::make_shared<LogQuote>(quotes[i]));
77 }
78 for (Size i = 0; i < times_.size() - 1; ++i)
79 timeDiffs_.push_back(times_[i + 1] - times_[i]);
80 }
std::vector< QuantLib::ext::shared_ptr< Quote > > quotes_
+ Here is the caller graph for this function:

◆ maxDate()

Date maxDate ( ) const
overrideprivate

Definition at line 84 of file interpolateddiscountcurve.hpp.

84{ return Date::maxDate(); } // flat fwd extrapolation

◆ discountImpl()

DiscountFactor discountImpl ( Time  t) const
overrideprotected

Definition at line 88 of file interpolateddiscountcurve.hpp.

88 {
89 if (t > this->times_.back() && extrapolation_ == Extrapolation::flatZero) {
90 Real tMax = this->times_.back();
91 Real dMax = std::exp(quotes_.back()->value());
92 return std::pow(dMax, t / tMax);
93 }
94 std::vector<Time>::const_iterator it = std::upper_bound(times_.begin(), times_.end(), t);
95 Size i = std::min<Size>(it - times_.begin(), times_.size() - 1);
96 Real weight = (times_[i] - t) / timeDiffs_[i - 1];
97 if (interpolation_ == Interpolation::logLinear || t > this->times_.back()) {
98 // this handles flat fwd extrapolation (t > times.back()) as well
99 Real value = (1.0 - weight) * quotes_[i]->value() + weight * quotes_[i - 1]->value();
100 return ::exp(value);
101 } else {
102 Real value =
103 (1.0 - weight) * quotes_[i]->value() / times_[i] + weight * quotes_[i - 1]->value() / times_[i - 1];
104 return ::exp(t * value);
105 }
106 }

Member Data Documentation

◆ times_

std::vector<Time> times_
private

Definition at line 109 of file interpolateddiscountcurve.hpp.

◆ timeDiffs_

std::vector<Time> timeDiffs_
private

Definition at line 110 of file interpolateddiscountcurve.hpp.

◆ quotes_

std::vector<QuantLib::ext::shared_ptr<Quote> > quotes_
private

Definition at line 111 of file interpolateddiscountcurve.hpp.

◆ interpolation_

Interpolation interpolation_
private

Definition at line 112 of file interpolateddiscountcurve.hpp.

◆ extrapolation_

Extrapolation extrapolation_
private

Definition at line 113 of file interpolateddiscountcurve.hpp.