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

Cross Ccy Basis Swap Rate Helper. More...

#include <qle/termstructures/crossccybasisswaphelper.hpp>

+ Inheritance diagram for CrossCcyBasisSwapHelper:
+ Collaboration diagram for CrossCcyBasisSwapHelper:

Public Member Functions

 CrossCcyBasisSwapHelper (const Handle< Quote > &spreadQuote, const Handle< Quote > &spotFX, Natural settlementDays, const Calendar &settlementCalendar, const Period &swapTenor, BusinessDayConvention rollConvention, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &flatIndex, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &spreadIndex, const Handle< YieldTermStructure > &flatDiscountCurve, const Handle< YieldTermStructure > &spreadDiscountCurve, bool eom=false, bool flatIsDomestic=true, boost::optional< QuantLib::Period > flatTenor=boost::none, boost::optional< QuantLib::Period > spreadTenor=boost::none, Real spreadOnFlatLeg=0.0, Real flatGearing=1.0, Real spreadGearing=1.0, const Calendar &flatCalendar=Calendar(), const Calendar &spreadCalendar=Calendar(), const std::vector< Natural > &spotFXSettleDaysVec=std::vector< Natural >(), const std::vector< Calendar > &spotFXSettleCalendar=std::vector< Calendar >(), Size paymentLag=0, Size flatPaymentLag=0, boost::optional< bool > includeSpread=boost::none, boost::optional< Period > lookback=boost::none, boost::optional< Size > fixingDays=boost::none, boost::optional< Size > rateCutoff=boost::none, boost::optional< bool > isAveraged=boost::none, boost::optional< bool > flatIncludeSpread=boost::none, boost::optional< Period > flatLookback=boost::none, boost::optional< Size > flatFixingDays=boost::none, boost::optional< Size > flatRateCutoff=boost::none, boost::optional< bool > flatIsAveraged=boost::none, const bool telescopicValueDates=false)
 
RateHelper interface
Real impliedQuote () const override
 
void setTermStructure (YieldTermStructure *) override
 
inspectors
QuantLib::ext::shared_ptr< CrossCcyBasisSwapswap () const
 

Visitability

Handle< Quote > spotFX_
 
Natural settlementDays_
 
Calendar settlementCalendar_
 
Period swapTenor_
 
BusinessDayConvention rollConvention_
 
QuantLib::ext::shared_ptr< QuantLib::IborIndex > flatIndex_
 
QuantLib::ext::shared_ptr< QuantLib::IborIndex > spreadIndex_
 
Handle< YieldTermStructure > flatDiscountCurve_
 
Handle< YieldTermStructure > spreadDiscountCurve_
 
bool eom_
 
bool flatIsDomestic_
 
QuantLib::Period flatTenor_
 
QuantLib::Period spreadTenor_
 
Real spreadOnFlatLeg_
 
Real flatGearing_
 
Real spreadGearing_
 
Calendar flatCalendar_
 
Calendar spreadCalendar_
 
std::vector< Natural > spotFXSettleDaysVec_
 
std::vector< Calendar > spotFXSettleCalendarVec_
 
Size paymentLag_
 
Size flatPaymentLag_
 
boost::optional< boolincludeSpread_
 
boost::optional< QuantLib::Period > lookback_
 
boost::optional< QuantLib::Size > fixingDays_
 
boost::optional< Size > rateCutoff_
 
boost::optional< boolisAveraged_
 
boost::optional< boolflatIncludeSpread_
 
boost::optional< QuantLib::Period > flatLookback_
 
boost::optional< QuantLib::Size > flatFixingDays_
 
boost::optional< Size > flatRateCutoff_
 
boost::optional< boolflatIsAveraged_
 
Currency flatLegCurrency_
 
Currency spreadLegCurrency_
 
QuantLib::ext::shared_ptr< CrossCcyBasisSwapswap_
 
RelinkableHandle< YieldTermStructure > termStructureHandle_
 
RelinkableHandle< YieldTermStructure > flatDiscountRLH_
 
RelinkableHandle< YieldTermStructure > spreadDiscountRLH_
 
bool telescopicValueDates_
 
void accept (AcyclicVisitor &) override
 
void initializeDates () override
 

Detailed Description

Cross Ccy Basis Swap Rate Helper.

Rate helper for bootstrapping over cross currency basis swap spreads

Assumes that you have, at a minimum, either:

The other leg is then solved for i.e. index curve (if no YieldTermStructure is attached to its index) or discount curve (if its Handle is empty) or both.

The currencies are deduced from the ibor indexes. The spotFx to be quoted with either of these currencies, this is determined by the flatIsDomestic flag. The settlement date of the spot is assumed to be equal to the settlement date of the swap itself.

    \ingroup termstructures

Definition at line 51 of file crossccybasisswaphelper.hpp.

Constructor & Destructor Documentation

◆ CrossCcyBasisSwapHelper()

CrossCcyBasisSwapHelper ( const Handle< Quote > &  spreadQuote,
const Handle< Quote > &  spotFX,
Natural  settlementDays,
const Calendar &  settlementCalendar,
const Period &  swapTenor,
BusinessDayConvention  rollConvention,
const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &  flatIndex,
const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &  spreadIndex,
const Handle< YieldTermStructure > &  flatDiscountCurve,
const Handle< YieldTermStructure > &  spreadDiscountCurve,
bool  eom = false,
bool  flatIsDomestic = true,
boost::optional< QuantLib::Period >  flatTenor = boost::none,
boost::optional< QuantLib::Period >  spreadTenor = boost::none,
Real  spreadOnFlatLeg = 0.0,
Real  flatGearing = 1.0,
Real  spreadGearing = 1.0,
const Calendar &  flatCalendar = Calendar(),
const Calendar &  spreadCalendar = Calendar(),
const std::vector< Natural > &  spotFXSettleDaysVec = std::vector<Natural>(),
const std::vector< Calendar > &  spotFXSettleCalendar = std::vector<Calendar>(),
Size  paymentLag = 0,
Size  flatPaymentLag = 0,
boost::optional< bool includeSpread = boost::none,
boost::optional< Period >  lookback = boost::none,
boost::optional< Size >  fixingDays = boost::none,
boost::optional< Size >  rateCutoff = boost::none,
boost::optional< bool isAveraged = boost::none,
boost::optional< bool flatIncludeSpread = boost::none,
boost::optional< Period >  flatLookback = boost::none,
boost::optional< Size >  flatFixingDays = boost::none,
boost::optional< Size >  flatRateCutoff = boost::none,
boost::optional< bool flatIsAveraged = boost::none,
const bool  telescopicValueDates = false 
)

Definition at line 28 of file crossccybasisswaphelper.cpp.

41 : RelativeDateRateHelper(spreadQuote), spotFX_(spotFX), settlementDays_(settlementDays),
42 settlementCalendar_(settlementCalendar), swapTenor_(swapTenor), rollConvention_(rollConvention),
43 flatIndex_(flatIndex), spreadIndex_(spreadIndex), flatDiscountCurve_(flatDiscountCurve),
44 spreadDiscountCurve_(spreadDiscountCurve), eom_(eom), flatIsDomestic_(flatIsDomestic),
45 flatTenor_(flatTenor ? *flatTenor : flatIndex_->tenor()),
46 spreadTenor_(spreadTenor ? *spreadTenor : spreadIndex_->tenor()), spreadOnFlatLeg_(spreadOnFlatLeg),
47 flatGearing_(flatGearing), spreadGearing_(spreadGearing), flatCalendar_(flatCalendar),
48 spreadCalendar_(spreadCalendar), spotFXSettleDaysVec_(spotFXSettleDaysVec),
49 spotFXSettleCalendarVec_(spotFXSettleCalendarVec), paymentLag_(paymentLag), flatPaymentLag_(flatPaymentLag),
50 includeSpread_(includeSpread), lookback_(lookback), fixingDays_(fixingDays), rateCutoff_(rateCutoff),
51 isAveraged_(isAveraged), flatIncludeSpread_(flatIncludeSpread), flatLookback_(flatLookback),
52 flatFixingDays_(flatFixingDays), flatRateCutoff_(flatRateCutoff), flatIsAveraged_(flatIsAveraged),
53 telescopicValueDates_(telescopicValueDates) {
54
55 flatLegCurrency_ = flatIndex_->currency();
56 spreadLegCurrency_ = spreadIndex_->currency();
57
58 bool flatIndexHasCurve = !flatIndex_->forwardingTermStructure().empty();
59 bool spreadIndexHasCurve = !spreadIndex_->forwardingTermStructure().empty();
60 bool haveFlatDiscountCurve = !flatDiscountCurve_.empty();
61 bool haveSpreadDiscountCurve = !spreadDiscountCurve_.empty();
62
63 QL_REQUIRE(!(flatIndexHasCurve && spreadIndexHasCurve && haveFlatDiscountCurve && haveSpreadDiscountCurve),
64 "Have all curves, "
65 "nothing to solve for.");
66
67 if (flatCalendar_.empty())
68 flatCalendar_ = settlementCalendar;
69 if (spreadCalendar_.empty())
70 spreadCalendar_ = settlementCalendar;
71
72 // check spotFXSettleDaysVec_ and spotFXSettleCalendarVec_
73 Size numSpotFXSettleDays = spotFXSettleDaysVec_.size();
74 QL_REQUIRE(numSpotFXSettleDays == spotFXSettleCalendarVec_.size(),
75 "Array size of spot fx settlement days must equal that of spot fx settlement calendars");
76 if (numSpotFXSettleDays == 0) {
77 spotFXSettleDaysVec_.resize(1, 0);
78 spotFXSettleCalendarVec_.resize(1, settlementCalendar);
79 }
80
81 /* Link the curve being bootstrapped to the index if the index has
82 no projection curve */
83 if (flatIndexHasCurve && haveFlatDiscountCurve) {
84 if (!spreadIndexHasCurve) {
86 spreadIndex_->unregisterWith(termStructureHandle_);
87 }
88 } else if (spreadIndexHasCurve && haveSpreadDiscountCurve) {
89 if (!flatIndexHasCurve) {
91 flatIndex_->unregisterWith(termStructureHandle_);
92 }
93 } else {
94 QL_FAIL("Need one leg of the cross currency basis swap to "
95 "have all of its curves.");
96 }
97
98 registerWith(spotFX_);
99 registerWith(flatIndex_);
100 registerWith(spreadIndex_);
101 registerWith(flatDiscountCurve_);
102 registerWith(spreadDiscountCurve_);
103
105}
RelinkableHandle< YieldTermStructure > termStructureHandle_
boost::optional< QuantLib::Size > fixingDays_
boost::optional< QuantLib::Size > flatFixingDays_
boost::optional< QuantLib::Period > lookback_
QuantLib::ext::shared_ptr< QuantLib::IborIndex > spreadIndex_
Handle< YieldTermStructure > spreadDiscountCurve_
boost::optional< QuantLib::Period > flatLookback_
QuantLib::ext::shared_ptr< QuantLib::IborIndex > flatIndex_
Handle< YieldTermStructure > flatDiscountCurve_
std::vector< Calendar > spotFXSettleCalendarVec_
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper
+ Here is the call graph for this function:

Member Function Documentation

◆ impliedQuote()

Real impliedQuote ( ) const
override

Definition at line 217 of file crossccybasisswaphelper.cpp.

217 {
218 QL_REQUIRE(termStructure_, "Term structure needs to be set");
219 swap_->deepUpdate();
220 return swap_->fairPaySpread();
221}
QuantLib::ext::shared_ptr< CrossCcyBasisSwap > swap_

◆ setTermStructure()

void setTermStructure ( YieldTermStructure *  t)
override

Definition at line 197 of file crossccybasisswaphelper.cpp.

197 {
198
199 bool observer = false;
200 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
201
202 termStructureHandle_.linkTo(temp, observer);
203
204 if (flatDiscountCurve_.empty())
205 flatDiscountRLH_.linkTo(temp, observer);
206 else
207 flatDiscountRLH_.linkTo(*flatDiscountCurve_, observer);
208
209 if (spreadDiscountCurve_.empty())
210 spreadDiscountRLH_.linkTo(temp, observer);
211 else
212 spreadDiscountRLH_.linkTo(*spreadDiscountCurve_, observer);
213
214 RelativeDateRateHelper::setTermStructure(t);
215}
RelinkableHandle< YieldTermStructure > spreadDiscountRLH_
RelinkableHandle< YieldTermStructure > flatDiscountRLH_

◆ swap()

QuantLib::ext::shared_ptr< CrossCcyBasisSwap > swap ( ) const

Definition at line 78 of file crossccybasisswaphelper.hpp.

78{ return swap_; }

◆ accept()

void accept ( AcyclicVisitor &  v)
override

Definition at line 223 of file crossccybasisswaphelper.cpp.

223 {
224 Visitor<CrossCcyBasisSwapHelper>* v1 = dynamic_cast<Visitor<CrossCcyBasisSwapHelper>*>(&v);
225 if (v1)
226 v1->visit(*this);
227 else
228 RateHelper::accept(v);
229}

◆ initializeDates()

void initializeDates ( )
overrideprotected

Definition at line 107 of file crossccybasisswaphelper.cpp.

107 {
108
109 Date refDate = evaluationDate_;
110 // if the evaluation date is not a business day
111 // then move to the next business day
112 refDate = settlementCalendar_.adjust(refDate);
113
114 Date settlementDate = settlementCalendar_.advance(refDate, settlementDays_, Days);
115 Date maturityDate = settlementDate + swapTenor_;
116
117 // calc spotFXSettleDate
118 Date spotFXSettleDate = refDate;
119 Size numSpotFXSettleDays = spotFXSettleDaysVec_.size(); // guaranteed to be at least 1
120 for (Size i = 0; i < numSpotFXSettleDays; i++) {
121 // Guaranteed here that spotFXSettleDaysVec_ and spotFXSettleCalendarVec_ have the same size
122 spotFXSettleDate = spotFXSettleCalendarVec_[i].advance(spotFXSettleDate, spotFXSettleDaysVec_[i], Days);
123 }
124
125 Schedule flatLegSchedule = MakeSchedule()
126 .from(settlementDate)
127 .to(maturityDate)
128 .withTenor(flatTenor_)
129 .withCalendar(flatCalendar_)
130 .withConvention(rollConvention_)
131 .endOfMonth(eom_);
132
133 Schedule spreadLegSchedule = MakeSchedule()
134 .from(settlementDate)
135 .to(maturityDate)
136 .withTenor(spreadTenor_)
137 .withCalendar(spreadCalendar_)
138 .withConvention(rollConvention_)
139 .endOfMonth(eom_);
140
141 Real flatLegNominal = 1.0;
142 Real spreadLegNominal = 1.0;
143 if (flatIsDomestic_) {
144 flatLegNominal = spotFX_->value();
145 } else {
146 spreadLegNominal = spotFX_->value();
147 }
148
149 /* Arbitrarily set the spread leg as the pay leg */
150 swap_ = QuantLib::ext::make_shared<CrossCcyBasisSwap>(
151 spreadLegNominal, spreadLegCurrency_, spreadLegSchedule, spreadIndex_, 0.0, spreadGearing_, flatLegNominal,
155
156 QuantLib::ext::shared_ptr<PricingEngine> engine;
157 if (flatIsDomestic_) {
158 engine = QuantLib::ext::make_shared<CrossCcySwapEngine>(flatLegCurrency_, flatDiscountRLH_, spreadLegCurrency_,
159 spreadDiscountRLH_, spotFX_, boost::none, Date(), Date(),
160 spotFXSettleDate);
161 } else {
162 engine = QuantLib::ext::make_shared<CrossCcySwapEngine>(spreadLegCurrency_, spreadDiscountRLH_, flatLegCurrency_,
163 flatDiscountRLH_, spotFX_, boost::none, Date(), Date(),
164 spotFXSettleDate);
165 }
166 swap_->setPricingEngine(engine);
167
168 earliestDate_ = swap_->startDate();
169 latestDate_ = swap_->maturityDate();
170
171/* May need to adjust latestDate_ if you are projecting libor based
172 on tenor length rather than from accrual date to accrual date. */
173 if (!IborCoupon::Settings::instance().usingAtParCoupons()) {
174 if (termStructureHandle_ == spreadIndex_->forwardingTermStructure()) {
175 Size numCashflows = swap_->leg(0).size();
176 if (numCashflows > 2) {
177 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
178 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(swap_->leg(0)[numCashflows - 2]);
179 Date fixingValueDate = spreadIndex_->valueDate(lastFloating->fixingDate());
180 Date endValueDate = spreadIndex_->maturityDate(fixingValueDate);
181 latestDate_ = std::max(latestDate_, endValueDate);
182 }
183 }
184 if (termStructureHandle_ == flatIndex_->forwardingTermStructure()) {
185 Size numCashflows = swap_->leg(1).size();
186 if (numCashflows > 2) {
187 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
188 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(swap_->leg(1)[numCashflows - 2]);
189 Date fixingValueDate = flatIndex_->valueDate(lastFloating->fixingDate());
190 Date endValueDate = flatIndex_->maturityDate(fixingValueDate);
191 latestDate_ = std::max(latestDate_, endValueDate);
192 }
193 }
194 }
195}
+ Here is the caller graph for this function:

Member Data Documentation

◆ spotFX_

Handle<Quote> spotFX_
protected

Definition at line 88 of file crossccybasisswaphelper.hpp.

◆ settlementDays_

Natural settlementDays_
protected

Definition at line 89 of file crossccybasisswaphelper.hpp.

◆ settlementCalendar_

Calendar settlementCalendar_
protected

Definition at line 90 of file crossccybasisswaphelper.hpp.

◆ swapTenor_

Period swapTenor_
protected

Definition at line 91 of file crossccybasisswaphelper.hpp.

◆ rollConvention_

BusinessDayConvention rollConvention_
protected

Definition at line 92 of file crossccybasisswaphelper.hpp.

◆ flatIndex_

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

Definition at line 93 of file crossccybasisswaphelper.hpp.

◆ spreadIndex_

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

Definition at line 94 of file crossccybasisswaphelper.hpp.

◆ flatDiscountCurve_

Handle<YieldTermStructure> flatDiscountCurve_
protected

Definition at line 95 of file crossccybasisswaphelper.hpp.

◆ spreadDiscountCurve_

Handle<YieldTermStructure> spreadDiscountCurve_
protected

Definition at line 96 of file crossccybasisswaphelper.hpp.

◆ eom_

bool eom_
protected

Definition at line 97 of file crossccybasisswaphelper.hpp.

◆ flatIsDomestic_

bool flatIsDomestic_
protected

Definition at line 98 of file crossccybasisswaphelper.hpp.

◆ flatTenor_

QuantLib::Period flatTenor_
protected

Definition at line 99 of file crossccybasisswaphelper.hpp.

◆ spreadTenor_

QuantLib::Period spreadTenor_
protected

Definition at line 100 of file crossccybasisswaphelper.hpp.

◆ spreadOnFlatLeg_

Real spreadOnFlatLeg_
protected

Definition at line 101 of file crossccybasisswaphelper.hpp.

◆ flatGearing_

Real flatGearing_
protected

Definition at line 102 of file crossccybasisswaphelper.hpp.

◆ spreadGearing_

Real spreadGearing_
protected

Definition at line 103 of file crossccybasisswaphelper.hpp.

◆ flatCalendar_

Calendar flatCalendar_
protected

Definition at line 104 of file crossccybasisswaphelper.hpp.

◆ spreadCalendar_

Calendar spreadCalendar_
protected

Definition at line 105 of file crossccybasisswaphelper.hpp.

◆ spotFXSettleDaysVec_

std::vector<Natural> spotFXSettleDaysVec_
protected

Definition at line 106 of file crossccybasisswaphelper.hpp.

◆ spotFXSettleCalendarVec_

std::vector<Calendar> spotFXSettleCalendarVec_
protected

Definition at line 107 of file crossccybasisswaphelper.hpp.

◆ paymentLag_

Size paymentLag_
protected

Definition at line 109 of file crossccybasisswaphelper.hpp.

◆ flatPaymentLag_

Size flatPaymentLag_
protected

Definition at line 110 of file crossccybasisswaphelper.hpp.

◆ includeSpread_

boost::optional<bool> includeSpread_
protected

Definition at line 112 of file crossccybasisswaphelper.hpp.

◆ lookback_

boost::optional<QuantLib::Period> lookback_
protected

Definition at line 113 of file crossccybasisswaphelper.hpp.

◆ fixingDays_

boost::optional<QuantLib::Size> fixingDays_
protected

Definition at line 114 of file crossccybasisswaphelper.hpp.

◆ rateCutoff_

boost::optional<Size> rateCutoff_
protected

Definition at line 115 of file crossccybasisswaphelper.hpp.

◆ isAveraged_

boost::optional<bool> isAveraged_
protected

Definition at line 116 of file crossccybasisswaphelper.hpp.

◆ flatIncludeSpread_

boost::optional<bool> flatIncludeSpread_
protected

Definition at line 117 of file crossccybasisswaphelper.hpp.

◆ flatLookback_

boost::optional<QuantLib::Period> flatLookback_
protected

Definition at line 118 of file crossccybasisswaphelper.hpp.

◆ flatFixingDays_

boost::optional<QuantLib::Size> flatFixingDays_
protected

Definition at line 119 of file crossccybasisswaphelper.hpp.

◆ flatRateCutoff_

boost::optional<Size> flatRateCutoff_
protected

Definition at line 120 of file crossccybasisswaphelper.hpp.

◆ flatIsAveraged_

boost::optional<bool> flatIsAveraged_
protected

Definition at line 121 of file crossccybasisswaphelper.hpp.

◆ flatLegCurrency_

Currency flatLegCurrency_
protected

Definition at line 123 of file crossccybasisswaphelper.hpp.

◆ spreadLegCurrency_

Currency spreadLegCurrency_
protected

Definition at line 124 of file crossccybasisswaphelper.hpp.

◆ swap_

QuantLib::ext::shared_ptr<CrossCcyBasisSwap> swap_
protected

Definition at line 125 of file crossccybasisswaphelper.hpp.

◆ termStructureHandle_

RelinkableHandle<YieldTermStructure> termStructureHandle_
protected

Definition at line 127 of file crossccybasisswaphelper.hpp.

◆ flatDiscountRLH_

RelinkableHandle<YieldTermStructure> flatDiscountRLH_
protected

Definition at line 128 of file crossccybasisswaphelper.hpp.

◆ spreadDiscountRLH_

RelinkableHandle<YieldTermStructure> spreadDiscountRLH_
protected

Definition at line 129 of file crossccybasisswaphelper.hpp.

◆ telescopicValueDates_

bool telescopicValueDates_
protected

Definition at line 131 of file crossccybasisswaphelper.hpp.