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

Basis Two Swap Helper. More...

#include <qle/termstructures/basistwoswaphelper.hpp>

+ Inheritance diagram for BasisTwoSwapHelper:
+ Collaboration diagram for BasisTwoSwapHelper:

Public Member Functions

 BasisTwoSwapHelper (const Handle< Quote > &spread, const Period &swapTenor, const Calendar &calendar, Frequency longFixedFrequency, BusinessDayConvention longFixedConvention, const DayCounter &longFixedDayCount, const QuantLib::ext::shared_ptr< IborIndex > &longIndex, Frequency shortFixedFrequency, BusinessDayConvention shortFixedConvention, const DayCounter &shortFixedDayCount, const QuantLib::ext::shared_ptr< IborIndex > &shortIndex, bool longMinusShort=true, const Handle< YieldTermStructure > &discountingCurve=Handle< YieldTermStructure >())
 
RateHelper interface
Real impliedQuote () const override
 
void setTermStructure (YieldTermStructure *) override
 
BasisTwoSwapHelper inspectors
QuantLib::ext::shared_ptr< VanillaSwap > longSwap () const
 
QuantLib::ext::shared_ptr< VanillaSwap > shortSwap () const
 

Visitability

Period swapTenor_
 
Calendar calendar_
 
Frequency longFixedFrequency_
 
BusinessDayConvention longFixedConvention_
 
DayCounter longFixedDayCount_
 
QuantLib::ext::shared_ptr< IborIndex > longIndex_
 
Frequency shortFixedFrequency_
 
BusinessDayConvention shortFixedConvention_
 
DayCounter shortFixedDayCount_
 
QuantLib::ext::shared_ptr< IborIndex > shortIndex_
 
bool longMinusShort_
 
QuantLib::ext::shared_ptr< VanillaSwap > longSwap_
 
QuantLib::ext::shared_ptr< VanillaSwap > shortSwap_
 
RelinkableHandle< YieldTermStructure > termStructureHandle_
 
Handle< YieldTermStructure > discountHandle_
 
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
 
void accept (AcyclicVisitor &) override
 
void initializeDates () override
 

Detailed Description

Basis Two Swap Helper.

Rate helper for bootstrapping using Libor tenor basis as the difference between the fixed rate on two swaps

\ingroup termstructures

Definition at line 38 of file basistwoswaphelper.hpp.

Constructor & Destructor Documentation

◆ BasisTwoSwapHelper()

BasisTwoSwapHelper ( const Handle< Quote > &  spread,
const Period &  swapTenor,
const Calendar &  calendar,
Frequency  longFixedFrequency,
BusinessDayConvention  longFixedConvention,
const DayCounter &  longFixedDayCount,
const QuantLib::ext::shared_ptr< IborIndex > &  longIndex,
Frequency  shortFixedFrequency,
BusinessDayConvention  shortFixedConvention,
const DayCounter &  shortFixedDayCount,
const QuantLib::ext::shared_ptr< IborIndex > &  shortIndex,
bool  longMinusShort = true,
const Handle< YieldTermStructure > &  discountingCurve = Handle<YieldTermStructure>() 
)

Definition at line 27 of file basistwoswaphelper.cpp.

38 : RelativeDateRateHelper(spread), swapTenor_(swapTenor), calendar_(calendar),
39 longFixedFrequency_(longFixedFrequency), longFixedConvention_(longFixedConvention),
40 longFixedDayCount_(longFixedDayCount), longIndex_(longIndex), shortFixedFrequency_(shortFixedFrequency),
41 shortFixedConvention_(shortFixedConvention), shortFixedDayCount_(shortFixedDayCount), shortIndex_(shortIndex),
42 longMinusShort_(longMinusShort), discountHandle_(discountingCurve) {
43
44 QL_REQUIRE(longIndex_->tenor() >= shortIndex_->tenor(),
45 "Tenor of longIndex should be at least tenor of shortIndex.");
46
47 bool longIndexHasCurve = !longIndex_->forwardingTermStructure().empty();
48 bool shortIndexHasCurve = !shortIndex_->forwardingTermStructure().empty();
49 bool haveDiscountCurve = !discountHandle_.empty();
50 QL_REQUIRE(!(longIndexHasCurve && shortIndexHasCurve && haveDiscountCurve),
51 "Have all curves nothing to solve for.");
52
53 if (longIndexHasCurve && !shortIndexHasCurve) {
55 shortIndex_->unregisterWith(termStructureHandle_);
56 } else if (!longIndexHasCurve && shortIndexHasCurve) {
58 longIndex_->unregisterWith(termStructureHandle_);
59 } else if (!longIndexHasCurve && !shortIndexHasCurve) {
60 QL_FAIL("Need at least one of the indices to have a valid curve.");
61 }
62
63 registerWith(longIndex_);
64 registerWith(shortIndex_);
65 registerWith(discountHandle_);
67}
RelinkableHandle< YieldTermStructure > termStructureHandle_
BusinessDayConvention longFixedConvention_
Handle< YieldTermStructure > discountHandle_
BusinessDayConvention shortFixedConvention_
QuantLib::ext::shared_ptr< IborIndex > shortIndex_
QuantLib::ext::shared_ptr< IborIndex > longIndex_
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper
+ Here is the call graph for this function:

Member Function Documentation

◆ impliedQuote()

Real impliedQuote ( ) const
override

Definition at line 131 of file basistwoswaphelper.cpp.

131 {
132 QL_REQUIRE(termStructure_ != 0, "Termstructure not set");
133 longSwap_->deepUpdate();
134 shortSwap_->deepUpdate();
135 if (longMinusShort_)
136 return longSwap_->fairRate() - shortSwap_->fairRate();
137 else
138 return shortSwap_->fairRate() - longSwap_->fairRate();
139}
QuantLib::ext::shared_ptr< VanillaSwap > longSwap_
QuantLib::ext::shared_ptr< VanillaSwap > shortSwap_

◆ setTermStructure()

void setTermStructure ( YieldTermStructure *  t)
override

Definition at line 116 of file basistwoswaphelper.cpp.

116 {
117
118 bool observer = false;
119
120 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
121 termStructureHandle_.linkTo(temp, observer);
122
123 if (discountHandle_.empty())
124 discountRelinkableHandle_.linkTo(temp, observer);
125 else
127
128 RelativeDateRateHelper::setTermStructure(t);
129}
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_

◆ longSwap()

QuantLib::ext::shared_ptr< VanillaSwap > longSwap ( ) const

Definition at line 92 of file basistwoswaphelper.hpp.

92{ return longSwap_; }

◆ shortSwap()

QuantLib::ext::shared_ptr< VanillaSwap > shortSwap ( ) const

Definition at line 90 of file basistwoswaphelper.hpp.

90{ return shortSwap_; }

◆ accept()

void accept ( AcyclicVisitor &  v)
override

Definition at line 141 of file basistwoswaphelper.cpp.

141 {
142 Visitor<BasisTwoSwapHelper>* v1 = dynamic_cast<Visitor<BasisTwoSwapHelper>*>(&v);
143 if (v1 != 0)
144 v1->visit(*this);
145 else
146 RateHelper::accept(v);
147}

◆ initializeDates()

void initializeDates ( )
overrideprotected

Definition at line 69 of file basistwoswaphelper.cpp.

69 {
70
71 /* Important to use a fixed rate of 0.0 here to avoid the calculation
72 of the atm swap rate in MakeVanillaSwap operator ...(). If it is
73 Null, you get an exception because the discountRelinkableHandle_
74 is initially empty. */
75 longSwap_ = MakeVanillaSwap(swapTenor_, longIndex_, 0.0)
76 .withDiscountingTermStructure(discountRelinkableHandle_)
77 .withFixedLegDayCount(longFixedDayCount_)
78 .withFixedLegTenor(Period(longFixedFrequency_))
79 .withFixedLegConvention(longFixedConvention_)
80 .withFixedLegTerminationDateConvention(longFixedConvention_)
81 .withFixedLegCalendar(calendar_)
82 .withFloatingLegCalendar(calendar_);
83
84 shortSwap_ = MakeVanillaSwap(swapTenor_, shortIndex_, 0.0)
85 .withDiscountingTermStructure(discountRelinkableHandle_)
86 .withFixedLegDayCount(shortFixedDayCount_)
87 .withFixedLegTenor(Period(shortFixedFrequency_))
88 .withFixedLegConvention(shortFixedConvention_)
89 .withFixedLegTerminationDateConvention(shortFixedConvention_)
90 .withFixedLegCalendar(calendar_)
91 .withFloatingLegCalendar(calendar_);
92
93 earliestDate_ = std::min(longSwap_->startDate(), shortSwap_->startDate());
94 latestDate_ = std::max(longSwap_->maturityDate(), shortSwap_->maturityDate());
95
96/* May need to adjust latestDate_ if you are projecting libor based
97 on tenor length rather than from accrual date to accrual date. */
98 if (!IborCoupon::Settings::instance().usingAtParCoupons()) {
99 if (termStructureHandle_ == shortIndex_->forwardingTermStructure()) {
100 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
101 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(shortSwap_->floatingLeg().back());
102 Date fixingValueDate = shortIndex_->valueDate(lastFloating->fixingDate());
103 Date endValueDate = shortIndex_->maturityDate(fixingValueDate);
104 latestDate_ = std::max(latestDate_, endValueDate);
105 }
106 if (termStructureHandle_ == longIndex_->forwardingTermStructure()) {
107 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
108 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(longSwap_->floatingLeg().back());
109 Date fixingValueDate = longIndex_->valueDate(lastFloating->fixingDate());
110 Date endValueDate = longIndex_->maturityDate(fixingValueDate);
111 latestDate_ = std::max(latestDate_, endValueDate);
112 }
113 }
114}
+ Here is the caller graph for this function:

Member Data Documentation

◆ swapTenor_

Period swapTenor_
protected

Definition at line 68 of file basistwoswaphelper.hpp.

◆ calendar_

Calendar calendar_
protected

Definition at line 69 of file basistwoswaphelper.hpp.

◆ longFixedFrequency_

Frequency longFixedFrequency_
protected

Definition at line 71 of file basistwoswaphelper.hpp.

◆ longFixedConvention_

BusinessDayConvention longFixedConvention_
protected

Definition at line 72 of file basistwoswaphelper.hpp.

◆ longFixedDayCount_

DayCounter longFixedDayCount_
protected

Definition at line 73 of file basistwoswaphelper.hpp.

◆ longIndex_

QuantLib::ext::shared_ptr<IborIndex> longIndex_
protected

Definition at line 74 of file basistwoswaphelper.hpp.

◆ shortFixedFrequency_

Frequency shortFixedFrequency_
protected

Definition at line 76 of file basistwoswaphelper.hpp.

◆ shortFixedConvention_

BusinessDayConvention shortFixedConvention_
protected

Definition at line 77 of file basistwoswaphelper.hpp.

◆ shortFixedDayCount_

DayCounter shortFixedDayCount_
protected

Definition at line 78 of file basistwoswaphelper.hpp.

◆ shortIndex_

QuantLib::ext::shared_ptr<IborIndex> shortIndex_
protected

Definition at line 79 of file basistwoswaphelper.hpp.

◆ longMinusShort_

bool longMinusShort_
protected

Definition at line 80 of file basistwoswaphelper.hpp.

◆ longSwap_

QuantLib::ext::shared_ptr<VanillaSwap> longSwap_
protected

Definition at line 82 of file basistwoswaphelper.hpp.

◆ shortSwap_

QuantLib::ext::shared_ptr<VanillaSwap> shortSwap_
protected

Definition at line 83 of file basistwoswaphelper.hpp.

◆ termStructureHandle_

RelinkableHandle<YieldTermStructure> termStructureHandle_
protected

Definition at line 85 of file basistwoswaphelper.hpp.

◆ discountHandle_

Handle<YieldTermStructure> discountHandle_
protected

Definition at line 86 of file basistwoswaphelper.hpp.

◆ discountRelinkableHandle_

RelinkableHandle<YieldTermStructure> discountRelinkableHandle_
protected

Definition at line 87 of file basistwoswaphelper.hpp.