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

Spreaded Default Term Structure, the spread is given in terms of loglinearly interpolated survival probabilities. More...

#include <qle/termstructures/spreadedsurvivalprobabilitytermstructure.hpp>

+ Inheritance diagram for SpreadedSurvivalProbabilityTermStructure:
+ Collaboration diagram for SpreadedSurvivalProbabilityTermStructure:

Public Types

enum class  Extrapolation { flatFwd , flatZero }
 

Public Member Functions

 SpreadedSurvivalProbabilityTermStructure (const Handle< DefaultProbabilityTermStructure > &referenceCurve, const std::vector< Time > &times, const std::vector< Handle< Quote > > &spreads, const Extrapolation extrapolation=Extrapolation::flatFwd)
 times should be consistent with reference ts day counter More...
 

TermStructure interface

Handle< DefaultProbabilityTermStructure > referenceCurve_
 
std::vector< Time > times_
 
std::vector< Handle< Quote > > spreads_
 
std::vector< Real > data_
 
QuantLib::ext::shared_ptr< Interpolation > interpolation_
 
Extrapolation extrapolation_
 
DayCounter dayCounter () const override
 
Date maxDate () const override
 
Time maxTime () const override
 
const Date & referenceDate () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 
std::vector< Time > times ()
 
Handle< DefaultProbabilityTermStructure > referenceCurve () const
 
void performCalculations () const override
 
Probability survivalProbabilityImpl (Time) const override
 
void update () override
 

Detailed Description

Spreaded Default Term Structure, the spread is given in terms of loglinearly interpolated survival probabilities.

Definition at line 35 of file spreadedsurvivalprobabilitytermstructure.hpp.

Member Enumeration Documentation

◆ Extrapolation

enum class Extrapolation
strong

Constructor & Destructor Documentation

◆ SpreadedSurvivalProbabilityTermStructure()

SpreadedSurvivalProbabilityTermStructure ( const Handle< DefaultProbabilityTermStructure > &  referenceCurve,
const std::vector< Time > &  times,
const std::vector< Handle< Quote > > &  spreads,
const Extrapolation  extrapolation = Extrapolation::flatFwd 
)

times should be consistent with reference ts day counter

Definition at line 23 of file spreadedsurvivalprobabilitytermstructure.cpp.

27 spreads_(spreads), data_(times.size(), 1.0), extrapolation_(extrapolation) {
28 QL_REQUIRE(times_.size() > 1, "at least two times required");
29 QL_REQUIRE(times_.size() == spreads_.size(), "size of time and quote vectors do not match");
30 QL_REQUIRE(times_[0] == 0.0, "First time must be 0, got " << times_[0]);
31 for (Size i = 0; i < spreads_.size(); ++i) {
32 registerWith(spreads_[i]);
33 }
34 interpolation_ = QuantLib::ext::make_shared<LogLinearInterpolation>(times_.begin(), times_.end(), data_.begin());
35 interpolation_->enableExtrapolation();
36 registerWith(Settings::instance().evaluationDate());
37 registerWith(referenceCurve_);
38}
Handle< DefaultProbabilityTermStructure > referenceCurve() const

Member Function Documentation

◆ dayCounter()

DayCounter dayCounter ( ) const
override

Definition at line 71 of file spreadedsurvivalprobabilitytermstructure.cpp.

71{ return referenceCurve_->dayCounter(); }

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 73 of file spreadedsurvivalprobabilitytermstructure.cpp.

73{ return referenceCurve_->maxDate(); }

◆ maxTime()

Time maxTime ( ) const
override

Definition at line 75 of file spreadedsurvivalprobabilitytermstructure.cpp.

75{ return referenceCurve_->maxTime(); }

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 77 of file spreadedsurvivalprobabilitytermstructure.cpp.

77{ return referenceCurve_->referenceDate(); }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 79 of file spreadedsurvivalprobabilitytermstructure.cpp.

79{ return referenceCurve_->calendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 81 of file spreadedsurvivalprobabilitytermstructure.cpp.

81{ return referenceCurve_->settlementDays(); }

◆ times()

std::vector< Time > times ( )

Definition at line 83 of file spreadedsurvivalprobabilitytermstructure.cpp.

83{ return times_; }

◆ referenceCurve()

Handle< DefaultProbabilityTermStructure > referenceCurve ( ) const

Definition at line 85 of file spreadedsurvivalprobabilitytermstructure.cpp.

85 {
86 return referenceCurve_;
87}

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 45 of file spreadedsurvivalprobabilitytermstructure.cpp.

45 {
46 for (Size i = 0; i < times_.size(); ++i) {
47 QL_REQUIRE(!spreads_[i].empty(),
48 "SpreadedSurvivalProbabilityTermStructure: quote at index " << i << " is empty");
49 data_[i] = spreads_[i]->value();
50 QL_REQUIRE(data_[i] > 0,
51 "SpreadedSurvivalProbabilityTermStructure: invalid value " << data_[i] << " at index " << i);
52 }
53 interpolation_->update();
54}

◆ survivalProbabilityImpl()

Probability survivalProbabilityImpl ( Time  t) const
overrideprivate

Definition at line 56 of file spreadedsurvivalprobabilitytermstructure.cpp.

56 {
57 calculate();
58 if (t <= this->times_.back())
59 return referenceCurve_->survivalProbability(t) * (*interpolation_)(t, true);
60 // flat fwd extrapolation
61 Real tMax = this->times_.back();
62 Real dMax = this->data_.back();
64 Real instFwdMax = -(*interpolation_).derivative(tMax) / dMax;
65 return referenceCurve_->survivalProbability(t) * dMax * std::exp(-instFwdMax * (t - tMax));
66 } else {
67 return referenceCurve_->survivalProbability(t) * std::pow(dMax, t / tMax);
68 }
69}

◆ update()

void update ( )
overrideprivate

Definition at line 40 of file spreadedsurvivalprobabilitytermstructure.cpp.

40 {
41 LazyObject::update();
42 TermStructure::update();
43}

Member Data Documentation

◆ referenceCurve_

Handle<DefaultProbabilityTermStructure> referenceCurve_
private

Definition at line 59 of file spreadedsurvivalprobabilitytermstructure.hpp.

◆ times_

std::vector<Time> times_
private

Definition at line 60 of file spreadedsurvivalprobabilitytermstructure.hpp.

◆ spreads_

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

Definition at line 61 of file spreadedsurvivalprobabilitytermstructure.hpp.

◆ data_

std::vector<Real> data_
mutableprivate

Definition at line 62 of file spreadedsurvivalprobabilitytermstructure.hpp.

◆ interpolation_

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

Definition at line 63 of file spreadedsurvivalprobabilitytermstructure.hpp.

◆ extrapolation_

Extrapolation extrapolation_
private

Definition at line 64 of file spreadedsurvivalprobabilitytermstructure.hpp.