18#include <ql/cashflows/iborcoupon.hpp>
19#include <ql/utilities/null_deleter.hpp>
24#include <boost/make_shared.hpp>
29 const Handle<Quote>& spreadQuote,
const Handle<Quote>& spotFX, Natural settlementDays,
30 const Calendar& settlementCalendar,
const Period& swapTenor, BusinessDayConvention rollConvention,
31 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& foreignCcyIndex,
32 const QuantLib::ext::shared_ptr<QuantLib::IborIndex>& domesticCcyIndex,
33 const Handle<YieldTermStructure>& foreignCcyDiscountCurve,
34 const Handle<YieldTermStructure>& domesticCcyDiscountCurve,
35 const Handle<YieldTermStructure>& foreignCcyFxFwdRateCurve,
36 const Handle<YieldTermStructure>& domesticCcyFxFwdRateCurve,
bool eom,
bool spreadOnForeignCcy,
37 boost::optional<Period> foreignTenor, boost::optional<Period> domesticTenor, Size foreignPaymentLag,
38 Size domesticPaymentLag, boost::optional<bool> foreignIncludeSpread, boost::optional<Period> foreignLookback,
39 boost::optional<Size> foreignFixingDays, boost::optional<Size> foreignRateCutoff,
40 boost::optional<bool> foreignIsAveraged, boost::optional<bool> domesticIncludeSpread,
41 boost::optional<Period> domesticLookback, boost::optional<Size> domesticFixingDays,
42 boost::optional<Size> domesticRateCutoff, boost::optional<bool> domesticIsAveraged,
const bool telescopicValueDates)
44 settlementCalendar_(settlementCalendar), swapTenor_(swapTenor), rollConvention_(rollConvention),
45 foreignCcyIndex_(foreignCcyIndex), domesticCcyIndex_(domesticCcyIndex),
46 foreignCcyDiscountCurve_(foreignCcyDiscountCurve), domesticCcyDiscountCurve_(domesticCcyDiscountCurve),
47 foreignCcyFxFwdRateCurve_(foreignCcyFxFwdRateCurve), domesticCcyFxFwdRateCurve_(domesticCcyFxFwdRateCurve),
48 eom_(eom), spreadOnForeignCcy_(spreadOnForeignCcy),
49 foreignTenor_(foreignTenor ? *foreignTenor : foreignCcyIndex_->tenor()),
50 domesticTenor_(domesticTenor ? *domesticTenor : domesticCcyIndex_->tenor()),
51 foreignPaymentLag_(foreignPaymentLag), domesticPaymentLag_(domesticPaymentLag),
52 foreignIncludeSpread_(foreignIncludeSpread), foreignLookback_(foreignLookback),
53 foreignFixingDays_(foreignFixingDays), foreignRateCutoff_(foreignRateCutoff),
54 foreignIsAveraged_(foreignIsAveraged), domesticIncludeSpread_(domesticIncludeSpread),
55 domesticLookback_(domesticLookback), domesticFixingDays_(domesticFixingDays),
56 domesticRateCutoff_(domesticRateCutoff), domesticIsAveraged_(domesticIsAveraged),
57 telescopicValueDates_(telescopicValueDates) {
62 "matching currencies not allowed on CrossCcyBasisMtMResetSwapHelper");
64 bool foreignIndexHasCurve = !
foreignCcyIndex_->forwardingTermStructure().empty();
65 bool domesticIndexHasCurve = !
domesticCcyIndex_->forwardingTermStructure().empty();
70 !(foreignIndexHasCurve && domesticIndexHasCurve && haveForeignDiscountCurve && haveDomesticDiscountCurve),
71 "CrossCcyBasisMtMResetSwapHelper - Have all curves, nothing to solve for.");
75 if (foreignIndexHasCurve && haveForeignDiscountCurve) {
76 if (!domesticIndexHasCurve) {
85 }
else if (domesticIndexHasCurve && haveDomesticDiscountCurve) {
86 if (!foreignIndexHasCurve) {
96 QL_FAIL(
"Need one leg of the cross currency basis swap to "
97 "have all of its curves.");
113 Date refDate = evaluationDate_;
119 Date maturityDate = settlementDate +
swapTenor_;
121 Schedule foreignLegSchedule = MakeSchedule()
122 .from(settlementDate)
129 Schedule domesticLegSchedule = MakeSchedule()
130 .from(settlementDate)
137 Real foreignNominal = 1.0;
140 QuantLib::ext::shared_ptr<FxIndex> fxIdx =
144 swap_ = QuantLib::ext::make_shared<CrossCcyBasisMtMResetSwap>(
151 QuantLib::ext::shared_ptr<PricingEngine> engine = QuantLib::ext::make_shared<CrossCcySwapEngine>(
153 swap_->setPricingEngine(engine);
155 earliestDate_ =
swap_->startDate();
156 latestDate_ =
swap_->maturityDate();
160 if (!IborCoupon::Settings::instance().usingAtParCoupons()) {
162 Size numCashflows =
swap_->leg(0).size();
163 Date endDate = latestDate_;
164 if (numCashflows > 0) {
165 for (Size i = numCashflows - 1; i >= 0; i--) {
166 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
167 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(
swap_->leg(0)[i]);
171 Date fixingValueDate =
foreignCcyIndex_->valueDate(lastFloating->fixingDate());
174 latestDate_ = std::max(latestDate_, endValueDate);
181 Size numCashflows =
swap_->leg(1).size();
182 Date endDate = latestDate_;
183 if (numCashflows > 0) {
184 for (Size i = numCashflows - 1; i >= 0; i--) {
185 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastFloating =
186 QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(
swap_->leg(1)[i]);
193 latestDate_ = std::max(latestDate_, endValueDate);
204 bool observer =
false;
205 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
230 RelativeDateRateHelper::setTermStructure(t);
234 QL_REQUIRE(termStructure_,
"Term structure needs to be set");
237 return swap_->fairForeignSpread();
239 return swap_->fairDomesticSpread();
243 Visitor<CrossCcyBasisMtMResetSwapHelper>* v1 =
dynamic_cast<Visitor<CrossCcyBasisMtMResetSwapHelper>*
>(&v);
247 RateHelper::accept(v);
CrossCcyBasisMtMResetSwapHelper(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 > &foreignCcyIndex, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &domesticCcyIndex, const Handle< YieldTermStructure > &foreignCcyDiscountCurve, const Handle< YieldTermStructure > &domesticCcyDiscountCurve, const Handle< YieldTermStructure > &foreignCcyFxFwdRateCurve=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &domesticCcyFxFwdRateCurve=Handle< YieldTermStructure >(), bool eom=false, bool spreadOnForeignCcy=true, boost::optional< QuantLib::Period > foreignTenor=boost::none, boost::optional< QuantLib::Period > domesticTenor=boost::none, Size foreignPaymentLag=0, Size domesticPaymentLag=0, boost::optional< bool > foreignIncludeSpread=boost::none, boost::optional< Period > foreignLookback=boost::none, boost::optional< Size > foreignFixingDays=boost::none, boost::optional< Size > foreignRateCutoff=boost::none, boost::optional< bool > foreignIsAveraged=boost::none, boost::optional< bool > domesticIncludeSpread=boost::none, boost::optional< Period > domesticLookback=boost::none, boost::optional< Size > domesticFixingDays=boost::none, boost::optional< Size > domesticRateCutoff=boost::none, boost::optional< bool > domesticIsAveraged=boost::none, const bool telescopicValueDates=false)
void setTermStructure(YieldTermStructure *) override
boost::optional< QuantLib::Period > foreignLookback_
bool telescopicValueDates_
RelinkableHandle< YieldTermStructure > foreignCcyFxFwdRateCurveRLH_
RelinkableHandle< YieldTermStructure > termStructureHandle_
RelinkableHandle< YieldTermStructure > domesticDiscountRLH_
QuantLib::ext::shared_ptr< QuantLib::IborIndex > domesticCcyIndex_
Handle< YieldTermStructure > domesticCcyDiscountCurve_
Currency domesticCurrency_
Currency foreignCurrency_
Handle< YieldTermStructure > domesticCcyFxFwdRateCurve_
boost::optional< QuantLib::Period > domesticLookback_
RelinkableHandle< YieldTermStructure > foreignDiscountRLH_
QuantLib::Period foreignTenor_
void accept(AcyclicVisitor &) override
boost::optional< bool > foreignIsAveraged_
QuantLib::ext::shared_ptr< CrossCcyBasisMtMResetSwap > swap_
Calendar settlementCalendar_
QuantLib::ext::shared_ptr< QuantLib::IborIndex > foreignCcyIndex_
RelinkableHandle< YieldTermStructure > domesticCcyFxFwdRateCurveRLH_
boost::optional< bool > domesticIncludeSpread_
QuantLib::Period domesticTenor_
void initializeDates() override
boost::optional< QuantLib::Size > domesticFixingDays_
Handle< YieldTermStructure > foreignCcyFxFwdRateCurve_
Real impliedQuote() const override
BusinessDayConvention rollConvention_
boost::optional< bool > foreignIncludeSpread_
boost::optional< bool > domesticIsAveraged_
boost::optional< QuantLib::Size > foreignFixingDays_
Handle< YieldTermStructure > foreignCcyDiscountCurve_
boost::optional< Size > foreignRateCutoff_
boost::optional< Size > domesticRateCutoff_
Cross currency basis swap helper with MTM reset.
Cross currency swap engine.