31 Schedule legSchedule(
const Date& evaluationDate,
33 const Period& frequency,
35 const Calendar& calendar,
39 "XCCY instrument tenor should not be smaller than coupon frequency.");
41 Date referenceDate = calendar.adjust(evaluationDate);
42 Date earliestDate = calendar.advance(referenceDate, fixingDays *
Days, convention);
43 Date maturity = earliestDate + tenor;
48 .withCalendar(calendar)
49 .withConvention(convention)
50 .endOfMonth(endOfMonth)
54 Leg buildIborLeg(
const Date& evaluationDate,
57 const Calendar& calendar,
60 const ext::shared_ptr<IborIndex>& idx) {
61 Schedule sch = legSchedule(evaluationDate, tenor, idx->tenor(), fixingDays, calendar,
62 convention, endOfMonth);
63 return IborLeg(sch, idx).withNotionals(1.0);
66 std::pair<Real, Real> npvbpsConstNotionalLeg(
const Leg& iborLeg,
67 const Handle<YieldTermStructure>& discountCurveHandle) {
68 const Spread basisPoint = 1.0e-4;
69 Date refDt = discountCurveHandle->referenceDate();
70 const YieldTermStructure& discountRef = **discountCurveHandle;
71 bool includeSettleDtFlows =
true;
73 std::tie(npv, bps) =
CashFlows::npvbps(iborLeg, discountRef, includeSettleDtFlows, refDt, refDt);
83 class ResettingLegHelper {
85 explicit ResettingLegHelper(
const YieldTermStructure& discountCurve,
86 const YieldTermStructure& foreignCurve)
91 Real notionalAdjustment(
const Date&
d)
const {
100 class ResettingLegCalculator :
public AcyclicVisitor,
public Visitor<Coupon> {
102 explicit ResettingLegCalculator(
const YieldTermStructure& discountCurve,
103 const YieldTermStructure& foreignCurve)
104 :
helper_(discountCurve, foreignCurve) {}
105 void visit(Coupon& c)
override {
106 Date start = c.accrualStartDate();
107 Date end = c.accrualEndDate();
108 Time accrual = c.accrualPeriod();
109 Real adjustedNotional = c.nominal() *
helper_.notionalAdjustment(start);
118 Real npvRedeemedAmount =
119 adjustedNotional * discountEnd * (1.0 + c.rate() * accrual);
120 Real npvBorrowedAmount = -adjustedNotional * discountStart;
122 npv_ += npvRedeemedAmount + npvBorrowedAmount;
123 bps_ += adjustedNotional * discountEnd * accrual;
134 std::pair<Real, Real> npvbpsResettingLeg(
const Leg& iborLeg,
135 const Handle<YieldTermStructure>& discountCurveHandle,
136 const Handle<YieldTermStructure>& foreignCurveHandle) {
137 const YieldTermStructure& discountCurveRef = **discountCurveHandle;
138 const YieldTermStructure& foreignCurveRef = **foreignCurveHandle;
140 ResettingLegCalculator calc(discountCurveRef, foreignCurveRef);
141 for (
const auto& i : iborLeg) {
145 return { calc.NPV(), calc.BPS() };
156 ext::shared_ptr<IborIndex> baseCurrencyIndex,
157 ext::shared_ptr<IborIndex> quoteCurrencyIndex,
159 bool isFxBaseCurrencyCollateralCurrency,
160 bool isBasisOnFxBaseCurrencyLeg)
162 calendar_(
std::move(calendar)), convention_(convention), endOfMonth_(endOfMonth),
163 baseCcyIdx_(
std::move(baseCurrencyIndex)), quoteCcyIdx_(
std::move(quoteCurrencyIndex)),
164 collateralHandle_(
std::move(collateralCurve)),
165 isFxBaseCurrencyCollateralCurrency_(isFxBaseCurrencyCollateralCurrency),
166 isBasisOnFxBaseCurrencyLeg_(isBasisOnFxBaseCurrencyLeg) {
201 bool observer =
false;
216 const ext::shared_ptr<IborIndex>& baseCurrencyIndex,
217 const ext::shared_ptr<IborIndex>& quoteCurrencyIndex,
219 bool isFxBaseCurrencyCollateralCurrency,
220 bool isBasisOnFxBaseCurrencyLeg)
230 isFxBaseCurrencyCollateralCurrency,
231 isBasisOnFxBaseCurrencyLeg) {}
234 Real npvBaseCcy = 0.0, bpsBaseCcy = 0.0;
236 Real npvQuoteCcy = 0.0, bpsQuoteCcy = 0.0;
239 return -(npvQuoteCcy - npvBaseCcy) / bps;
257 const ext::shared_ptr<IborIndex>& baseCurrencyIndex,
258 const ext::shared_ptr<IborIndex>& quoteCurrencyIndex,
260 bool isFxBaseCurrencyCollateralCurrency,
261 bool isBasisOnFxBaseCurrencyLeg,
262 bool isFxBaseCurrencyLegResettable)
272 isFxBaseCurrencyCollateralCurrency,
273 isBasisOnFxBaseCurrencyLeg),
274 isFxBaseCurrencyLegResettable_(isFxBaseCurrencyLegResettable) {}
277 Real npvBaseCcy = 0.0, bpsBaseCcy = 0.0;
278 Real npvQuoteCcy = 0.0, bpsQuoteCcy = 0.0;
280 std::tie(npvBaseCcy, bpsBaseCcy) =
283 std::tie(npvQuoteCcy, bpsQuoteCcy) =
286 std::tie(npvBaseCcy, bpsBaseCcy) =
288 std::tie(npvQuoteCcy, bpsQuoteCcy) =
295 return -(npvQuoteCcy - npvBaseCcy) / bps;
const YieldTermStructure & discountCurve_
Cash-flow analysis functions.
degenerate base class for the Acyclic Visitor pattern
virtual void accept(AcyclicVisitor &)
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
static Date maturityDate(const Leg &leg)
static Date startDate(const Leg &leg)
static std::pair< Real, Real > npvbps(const Leg &leg, const YieldTermStructure &discountCurve, bool includeSettlementDateFlows, Date settlementDate=Date(), Date npvDate=Date())
NPV and BPS of the cash flows.
ConstNotionalCrossCurrencyBasisSwapRateHelper(const Handle< Quote > &basis, const Period &tenor, Natural fixingDays, const Calendar &calendar, BusinessDayConvention convention, bool endOfMonth, const ext::shared_ptr< IborIndex > &baseCurrencyIndex, const ext::shared_ptr< IborIndex > "eCurrencyIndex, const Handle< YieldTermStructure > &collateralCurve, bool isFxBaseCurrencyCollateralCurrency, bool isBasisOnFxBaseCurrencyLeg)
void accept(AcyclicVisitor &) override
Real impliedQuote() const override
Base class for cross-currency basis swap rate helpers.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
ext::shared_ptr< IborIndex > baseCcyIdx_
const Handle< YieldTermStructure > & baseCcyLegDiscountHandle() const
ext::shared_ptr< IborIndex > quoteCcyIdx_
BusinessDayConvention convention_
Handle< YieldTermStructure > collateralHandle_
void initializeDates() override
const Handle< YieldTermStructure > & quoteCcyLegDiscountHandle() const
bool isFxBaseCurrencyCollateralCurrency_
CrossCurrencyBasisSwapRateHelperBase(const Handle< Quote > &basis, const Period &tenor, Natural fixingDays, Calendar calendar, BusinessDayConvention convention, bool endOfMonth, ext::shared_ptr< IborIndex > baseCurrencyIndex, ext::shared_ptr< IborIndex > quoteCurrencyIndex, Handle< YieldTermStructure > collateralCurve, bool isFxBaseCurrencyCollateralCurrency, bool isBasisOnFxBaseCurrencyLeg)
bool isBasisOnFxBaseCurrencyLeg_
Shared handle to an observable.
bool isFxBaseCurrencyLegResettable_
void accept(AcyclicVisitor &) override
MtMCrossCurrencyBasisSwapRateHelper(const Handle< Quote > &basis, const Period &tenor, Natural fixingDays, const Calendar &calendar, BusinessDayConvention convention, bool endOfMonth, const ext::shared_ptr< IborIndex > &baseCurrencyIndex, const ext::shared_ptr< IborIndex > "eCurrencyIndex, const Handle< YieldTermStructure > &collateralCurve, bool isFxBaseCurrencyCollateralCurrency, bool isBasisOnFxBaseCurrencyLeg, bool isFxBaseCurrencyLegResettable)
Real impliedQuote() const override
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Bootstrap helper with date schedule relative to global evaluation date.
Visitor for a specific class
virtual void visit(T &)=0
Interest-rate term structure.
ResettingLegHelper helper_
const YieldTermStructure & foreignCurve_
FX and cross currency basis swaps rate helpers.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
unsigned QL_INTEGER Natural
positive integer
Real Spread
spreads on interest rates
Coupon paying a Libor-type index.
MarketModelMultiProduct::CashFlow CashFlow
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
empty deleter for shared_ptr
ext::shared_ptr< BlackVolTermStructure > v