Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | List of all members
SpreadedDiscountCurve Class Reference

#include <qle/termstructures/spreadeddiscountcurve.hpp>

+ Inheritance diagram for SpreadedDiscountCurve:
+ Collaboration diagram for SpreadedDiscountCurve:

Public Types

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

Public Member Functions

 SpreadedDiscountCurve (const Handle< YieldTermStructure > &referenceCurve, const std::vector< Time > &times, const std::vector< Handle< Quote > > &quotes, const Interpolation interpolation=Interpolation::logLinear, const Extrapolation extrapolation=Extrapolation::flatFwd)
 times should be consistent with reference ts day counter More...
 
Date maxDate () const override
 
void update () override
 
const Date & referenceDate () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 

Protected Member Functions

void performCalculations () const override
 
DiscountFactor discountImpl (Time t) const override
 

Private Attributes

Handle< YieldTermStructure > referenceCurve_
 
std::vector< Time > times_
 
std::vector< Handle< Quote > > quotes_
 
Interpolation interpolation_
 
Extrapolation extrapolation_
 
std::vector< Real > data_
 
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_
 

Detailed Description

Curve taking a reference curve and discount factor quotes, that are used to overlay the reference curve with a spread. The quotes are interpolated loglinearly. The spread curve is given in terms of times relative to the reference date, which means that the spread will float with a changing reference date in the reference curve.

Definition at line 39 of file spreadeddiscountcurve.hpp.

Member Enumeration Documentation

◆ Interpolation

enum class Interpolation
strong

◆ Extrapolation

enum class Extrapolation
strong

Constructor & Destructor Documentation

◆ SpreadedDiscountCurve()

SpreadedDiscountCurve ( const Handle< YieldTermStructure > &  referenceCurve,
const std::vector< Time > &  times,
const std::vector< Handle< Quote > > &  quotes,
const Interpolation  interpolation = Interpolation::logLinear,
const Extrapolation  extrapolation = Extrapolation::flatFwd 
)

times should be consistent with reference ts day counter

Definition at line 25 of file spreadeddiscountcurve.cpp.

28 : YieldTermStructure(referenceCurve->dayCounter()), referenceCurve_(referenceCurve), times_(times), quotes_(quotes),
29 interpolation_(interpolation), extrapolation_(extrapolation), data_(times_.size(), 1.0) {
30 QL_REQUIRE(times_.size() > 1, "SpreadedDiscountCurve: at least two times required");
31 QL_REQUIRE(times_.size() == quotes.size(), "SpreadedDiscountCurve: size of time and quote vectors do not match");
32 QL_REQUIRE(times_[0] == 0.0, "SpreadedDiscountCurve: first time must be 0, got " << times_[0]);
33 for (Size i = 0; i < quotes.size(); ++i) {
34 registerWith(quotes_[i]);
35 }
37 dataInterpolation_ = QuantLib::ext::make_shared<LogLinearInterpolation>(times_.begin(), times_.end(), data_.begin());
38 } else {
39 dataInterpolation_ = QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin());
40 }
41 dataInterpolation_->enableExtrapolation();
42 registerWith(referenceCurve_);
43}
Handle< YieldTermStructure > referenceCurve_
std::vector< Handle< Quote > > quotes_
QuantLib::ext::shared_ptr< QuantLib::Interpolation > dataInterpolation_

Member Function Documentation

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 45 of file spreadeddiscountcurve.cpp.

45{ return referenceCurve_->maxDate(); }

◆ update()

void update ( )
override

Definition at line 47 of file spreadeddiscountcurve.cpp.

47 {
48 LazyObject::update();
49 TermStructure::update();
50}

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 52 of file spreadeddiscountcurve.cpp.

52{ return referenceCurve_->referenceDate(); }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 54 of file spreadeddiscountcurve.cpp.

54{ return referenceCurve_->calendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 56 of file spreadeddiscountcurve.cpp.

56{ return referenceCurve_->settlementDays(); }

◆ performCalculations()

void performCalculations ( ) const
overrideprotected

Definition at line 58 of file spreadeddiscountcurve.cpp.

58 {
59 for (Size i = 0; i < times_.size(); ++i) {
60 QL_REQUIRE(!quotes_[i].empty(), "SpreadedDiscountCurve: quote at index " << i << " is empty");
61 data_[i] = quotes_[i]->value();
62 QL_REQUIRE(data_[i] > 0, "SpreadedDiscountCurve: invalid value " << data_[i] << " at index " << i);
63 }
65 for (Size i = 0; i < times_.size(); ++i) {
66 data_[i] = -std::log(data_[std::max<Size>(i, 1)]) / times_[std::max<Size>(i, 1)];
67 }
68 }
69 dataInterpolation_->update();
70}

◆ discountImpl()

DiscountFactor discountImpl ( Time  t) const
overrideprotected

Definition at line 72 of file spreadeddiscountcurve.cpp.

72 {
73 calculate();
74 Time tMax = this->times_.back();
75 DiscountFactor dMax =
76 interpolation_ == Interpolation::logLinear ? this->data_.back() : std::exp(-this->data_.back() * tMax);
77 if (t <= this->times_.back()) {
78 Real tmp = (*dataInterpolation_)(t, true);
80 return referenceCurve_->discount(t) * tmp;
81 else
82 return referenceCurve_->discount(t) * std::exp(-tmp * t);
83 }
85 Rate instFwdMax = -(*dataInterpolation_).derivative(tMax) / dMax;
86 return referenceCurve_->discount(t) * dMax * std::exp(-instFwdMax * (t - tMax));
87 } else {
88 return referenceCurve_->discount(t) * std::pow(dMax, t / tMax);
89 }
90}

Member Data Documentation

◆ referenceCurve_

Handle<YieldTermStructure> referenceCurve_
private

Definition at line 61 of file spreadeddiscountcurve.hpp.

◆ times_

std::vector<Time> times_
private

Definition at line 62 of file spreadeddiscountcurve.hpp.

◆ quotes_

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

Definition at line 63 of file spreadeddiscountcurve.hpp.

◆ interpolation_

Interpolation interpolation_
private

Definition at line 64 of file spreadeddiscountcurve.hpp.

◆ extrapolation_

Extrapolation extrapolation_
private

Definition at line 65 of file spreadeddiscountcurve.hpp.

◆ data_

std::vector<Real> data_
mutableprivate

Definition at line 66 of file spreadeddiscountcurve.hpp.

◆ dataInterpolation_

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

Definition at line 67 of file spreadeddiscountcurve.hpp.