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

InterpolatedDiscountCurve2 as in QuantLib, but with floating discount quotes and floating reference date. More...

#include <qle/termstructures/interpolateddiscountcurve2.hpp>

+ Inheritance diagram for InterpolatedDiscountCurve2:
+ Collaboration diagram for InterpolatedDiscountCurve2:

Public Types

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

Constructors

std::vector< Time > times_
 
std::vector< Handle< Quote > > quotes_
 
Interpolation interpolation_
 
Extrapolation extrapolation_
 
std::vector< Real > data_
 
Date today_
 
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_
 
 InterpolatedDiscountCurve2 (const std::vector< Time > &times, const std::vector< Handle< Quote > > &quotes, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
 times based constructor, note that times should be consistent with day counter dc passed More...
 
 InterpolatedDiscountCurve2 (const std::vector< Date > &dates, const std::vector< Handle< Quote > > &quotes, const DayCounter &dc, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
 date based constructor More...
 
Date maxDate () const override
 
void update () override
 
const Date & referenceDate () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 
void performCalculations () const override
 
DiscountFactor discountImpl (Time t) const override
 

Detailed Description

InterpolatedDiscountCurve2 as in QuantLib, but with floating discount quotes and floating reference date.

InterpolatedDiscountCurve2 as in QuantLib, but with floating discount quotes and floating reference date, reference date is always the global evaluation date, i.e. settlement days are zero and calendar is NullCalendar()

\ingroup termstructures

Definition at line 44 of file interpolateddiscountcurve2.hpp.

Member Enumeration Documentation

◆ Interpolation

enum class Interpolation
strong

◆ Extrapolation

enum class Extrapolation
strong

Constructor & Destructor Documentation

◆ InterpolatedDiscountCurve2() [1/2]

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

times based constructor, note that times should be consistent with day counter dc passed

Definition at line 51 of file interpolateddiscountcurve2.hpp.

54 : YieldTermStructure(dc), times_(times), quotes_(quotes), interpolation_(interpolation),
55 extrapolation_(extrapolation), data_(times_.size(), 1.0), today_(Settings::instance().evaluationDate()) {
56 for (Size i = 0; i < quotes.size(); ++i) {
57 QL_REQUIRE(times_.size() > 1, "at least two times required");
58 QL_REQUIRE(times_.size() == quotes.size(), "size of time and quote vectors do not match");
59 QL_REQUIRE(times_[0] == 0.0, "First time must be 0, got " << times_[0]);
60 QL_REQUIRE(!quotes[i].empty(), "quote at index " << i << " is empty");
61 registerWith(quotes_[i]);
62 }
65 QuantLib::ext::make_shared<LogLinearInterpolation>(times_.begin(), times_.end(), data_.begin());
66 } else {
67 dataInterpolation_ = QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin());
68 }
69 registerWith(Settings::instance().evaluationDate());
70 }
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_

◆ InterpolatedDiscountCurve2() [2/2]

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

date based constructor

Definition at line 72 of file interpolateddiscountcurve2.hpp.

75 : YieldTermStructure(dc), times_(dates.size(), 0.0), quotes_(quotes), interpolation_(interpolation),
76 extrapolation_(extrapolation), data_(dates.size(), 1.0), today_(Settings::instance().evaluationDate()) {
77 for (Size i = 0; i < dates.size(); ++i)
78 times_[i] = dc.yearFraction(today_, dates[i]);
79 for (Size i = 0; i < quotes.size(); ++i) {
80 QL_REQUIRE(times_.size() > 1, "at least two times required");
81 QL_REQUIRE(times_.size() == quotes.size(), "size of time and quote vectors do not match");
82 QL_REQUIRE(times_[0] == 0.0, "First time must be 0, got " << times_[0]);
83 QL_REQUIRE(!quotes[i].empty(), "quote at index " << i << " is empty");
84 registerWith(quotes_[i]);
85 }
88 QuantLib::ext::make_shared<LogLinearInterpolation>(times_.begin(), times_.end(), data_.begin());
89 } else {
90 dataInterpolation_ = QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin());
91 }
92 registerWith(Settings::instance().evaluationDate());
93 }

Member Function Documentation

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 96 of file interpolateddiscountcurve2.hpp.

96{ return Date::maxDate(); }

◆ update()

void update ( )
override

Definition at line 97 of file interpolateddiscountcurve2.hpp.

97 {
98 LazyObject::update();
99 TermStructure::update();
100 }

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 101 of file interpolateddiscountcurve2.hpp.

101 {
102 calculate();
103 return today_;
104 }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 106 of file interpolateddiscountcurve2.hpp.

106{ return NullCalendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 107 of file interpolateddiscountcurve2.hpp.

107{ return 0; }

◆ performCalculations()

void performCalculations ( ) const
overrideprotected

Definition at line 110 of file interpolateddiscountcurve2.hpp.

110 {
111 today_ = Settings::instance().evaluationDate();
112 for (Size i = 0; i < times_.size(); ++i) {
113 data_[i] = quotes_[i]->value();
114 QL_REQUIRE(data_[i] > 0, "InterpolatedDiscountCurve2: invalid value " << data_[i] << " at index " << i);
115 }
117 for (Size i = 0; i < times_.size(); ++i) {
118 data_[i] = -std::log(data_[std::max<Size>(i, 1)]) / times_[std::max<Size>(i, 1)];
119 }
120 }
121 dataInterpolation_->update();
122 }

◆ discountImpl()

DiscountFactor discountImpl ( Time  t) const
overrideprotected

Definition at line 124 of file interpolateddiscountcurve2.hpp.

124 {
125 calculate();
126 if (t <= this->times_.back()) {
127 Real tmp = (*dataInterpolation_)(t, true);
129 return tmp;
130 else
131 return std::exp(-tmp * t);
132 }
133 Time tMax = this->times_.back();
134 DiscountFactor dMax =
135 interpolation_ == Interpolation::logLinear ? this->data_.back() : std::exp(-this->data_.back() * tMax);
137 Rate instFwdMax = -(*dataInterpolation_).derivative(tMax) / dMax;
138 return dMax * std::exp(-instFwdMax * (t - tMax));
139 } else {
140 return std::pow(dMax, t / tMax);
141 }
142 }

Member Data Documentation

◆ times_

std::vector<Time> times_
private

Definition at line 145 of file interpolateddiscountcurve2.hpp.

◆ quotes_

std::vector<Handle<Quote> > quotes_
private

Definition at line 146 of file interpolateddiscountcurve2.hpp.

◆ interpolation_

Interpolation interpolation_
private

Definition at line 147 of file interpolateddiscountcurve2.hpp.

◆ extrapolation_

Extrapolation extrapolation_
private

Definition at line 148 of file interpolateddiscountcurve2.hpp.

◆ data_

std::vector<Real> data_
mutableprivate

Definition at line 149 of file interpolateddiscountcurve2.hpp.

◆ today_

Date today_
mutableprivate

Definition at line 150 of file interpolateddiscountcurve2.hpp.

◆ dataInterpolation_

QuantLib::ext::shared_ptr<QuantLib::Interpolation> dataInterpolation_
private

Definition at line 151 of file interpolateddiscountcurve2.hpp.