Skip to content

Commit

Permalink
Pass interpolation to year-on-year coupons
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Sep 19, 2024
1 parent 6061700 commit 322aa3a
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 55 deletions.
1 change: 1 addition & 0 deletions ql/cashflows/capflooredinflationcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace QuantLib {
underlying->fixingDays(),
underlying->yoyIndex(),
underlying->observationLag(),
underlying->interpolation(),
underlying->dayCounter(),
underlying->gearing(),
underlying->spread(),
Expand Down
29 changes: 27 additions & 2 deletions ql/cashflows/capflooredinflationcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace QuantLib {
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
const CPI::InterpolationType interpolation,
const DayCounter& dayCounter,
Real gearing = 1.0,
Spread spread = 0.0,
Expand All @@ -87,12 +88,36 @@ namespace QuantLib {
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date())
: YoYInflationCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, index, observationLag, dayCounter,
gearing, spread, refPeriodStart, refPeriodEnd),
fixingDays, index, observationLag, interpolation,
dayCounter, gearing, spread,
refPeriodStart, refPeriodEnd),
isFloored_(false), isCapped_(false) {
setCommon(cap, floor);
}

/*! \deprecated Use the overload that passes an interpolation type instead.
Deprecated in version 1.36.
*/
[[deprecated("Use the overload that passes an interpolation type instead")]]
CappedFlooredYoYInflationCoupon(const Date& paymentDate,
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
const DayCounter& dayCounter,
Real gearing = 1.0,
Spread spread = 0.0,
const Rate cap = Null<Rate>(),
const Rate floor = Null<Rate>(),
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date())
: CappedFlooredYoYInflationCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, index, observationLag, CPI::AsIndex,
dayCounter, gearing, spread, cap, floor,
refPeriodStart, refPeriodEnd) {}

//! \name augmented Coupon interface
//@{
//! swap(let) rate
Expand Down
61 changes: 44 additions & 17 deletions ql/cashflows/yoyinflationcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,39 @@ namespace QuantLib {

YoYInflationCoupon::
YoYInflationCoupon(const Date& paymentDate,
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
const Period& observationLag,
const DayCounter& dayCounter,
Real gearing,
Spread spread,
const Date& refPeriodStart,
const Date& refPeriodEnd)
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
const Period& observationLag,
CPI::InterpolationType interpolation,
const DayCounter& dayCounter,
Real gearing,
Spread spread,
const Date& refPeriodStart,
const Date& refPeriodEnd)
: InflationCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, yoyIndex, observationLag,
dayCounter, refPeriodStart, refPeriodEnd),
yoyIndex_(yoyIndex), gearing_(gearing), spread_(spread) {}
fixingDays, yoyIndex, observationLag,
dayCounter, refPeriodStart, refPeriodEnd),
yoyIndex_(yoyIndex), interpolation_(interpolation), gearing_(gearing), spread_(spread) {}

YoYInflationCoupon::
YoYInflationCoupon(const Date& paymentDate,
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
const Period& observationLag,
const DayCounter& dayCounter,
Real gearing,
Spread spread,
const Date& refPeriodStart,
const Date& refPeriodEnd)
: YoYInflationCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, yoyIndex, observationLag, CPI::AsIndex,
dayCounter, gearing, spread, refPeriodStart, refPeriodEnd) {}


void YoYInflationCoupon::accept(AcyclicVisitor& v) {
Expand All @@ -60,16 +78,23 @@ namespace QuantLib {
}

Rate YoYInflationCoupon::indexFixing() const {
return CPI::laggedYoYRate(yoyIndex(), accrualEndDate(), observationLag(), CPI::AsIndex);
return CPI::laggedYoYRate(yoyIndex(), accrualEndDate(), observationLag(), interpolation_);
}


yoyInflationLeg::yoyInflationLeg(Schedule schedule,
Calendar paymentCalendar,
ext::shared_ptr<YoYInflationIndex> index,
const Period& observationLag)
const Period& observationLag,
CPI::InterpolationType interpolation)
: schedule_(std::move(schedule)), index_(std::move(index)), observationLag_(observationLag),
paymentCalendar_(std::move(paymentCalendar)) {}
interpolation_(interpolation), paymentCalendar_(std::move(paymentCalendar)) {}

yoyInflationLeg::yoyInflationLeg(Schedule schedule,
Calendar paymentCalendar,
ext::shared_ptr<YoYInflationIndex> index,
const Period& observationLag)
: yoyInflationLeg(schedule, paymentCalendar, index, observationLag, CPI::AsIndex) {}


yoyInflationLeg& yoyInflationLeg::withNotionals(Real notional) {
Expand Down Expand Up @@ -199,6 +224,7 @@ namespace QuantLib {
detail::get(fixingDays_, i, 0),
index_,
observationLag_,
interpolation_,
paymentDayCounter_,
detail::get(gearings_, i, 1.0),
detail::get(spreads_, i, 0.0),
Expand All @@ -211,6 +237,7 @@ namespace QuantLib {
detail::get(fixingDays_, i, 0),
index_,
observationLag_,
interpolation_,
paymentDayCounter_,
detail::get(gearings_, i, 1.0),
detail::get(spreads_, i, 0.0),
Expand Down
65 changes: 48 additions & 17 deletions ql/cashflows/yoyinflationcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,37 @@ namespace QuantLib {

//! %Coupon paying a YoY-inflation type index
class YoYInflationCoupon : public InflationCoupon {
public:
public:
YoYInflationCoupon(const Date& paymentDate,
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
CPI::InterpolationType interpolation,
const DayCounter& dayCounter,
Real gearing = 1.0,
Spread spread = 0.0,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date());

/*! \deprecated Use the overload that passes an interpolation type instead.
Deprecated in version 1.36.
*/
[[deprecated("Use the overload that passes an interpolation type instead")]]
YoYInflationCoupon(const Date& paymentDate,
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
const DayCounter& dayCounter,
Real gearing = 1.0,
Spread spread = 0.0,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date()
);
Real nominal,
const Date& startDate,
const Date& endDate,
Natural fixingDays,
const ext::shared_ptr<YoYInflationIndex>& index,
const Period& observationLag,
const DayCounter& dayCounter,
Real gearing = 1.0,
Spread spread = 0.0,
const Date& refPeriodStart = Date(),
const Date& refPeriodEnd = Date());

//! \name Inspectors
//@{
Expand All @@ -60,17 +77,18 @@ namespace QuantLib {
Rate adjustedFixing() const;

const ext::shared_ptr<YoYInflationIndex>& yoyIndex() const;
CPI::InterpolationType interpolation() const;
//@}

//! \name Visitability
//@{
void accept(AcyclicVisitor&) override;
//@}

private:
private:
ext::shared_ptr<YoYInflationIndex> yoyIndex_;
protected:

CPI::InterpolationType interpolation_;
protected:
Real gearing_;
Spread spread_;
bool checkPricerImpl(const ext::shared_ptr<InflationCouponPricer>&) const override;
Expand All @@ -81,6 +99,10 @@ namespace QuantLib {
return yoyIndex_;
}

inline CPI::InterpolationType YoYInflationCoupon::interpolation() const {
return interpolation_;
}

inline Rate YoYInflationCoupon::adjustedFixing() const {
return (rate()-spread())/gearing();
}
Expand All @@ -89,9 +111,17 @@ namespace QuantLib {


//! Helper class building a sequence of capped/floored yoy inflation coupons
//! payoff is: spread + gearing x index
class yoyInflationLeg {
public:
yoyInflationLeg(Schedule schedule,
Calendar cal,
ext::shared_ptr<YoYInflationIndex> index,
const Period& observationLag,
CPI::InterpolationType interpolation);
/*! \deprecated Use the overload that passes an interpolation type instead.
Deprecated in version 1.36.
*/
[[deprecated("Use the overload that passes an interpolation type instead")]]
yoyInflationLeg(Schedule schedule,
Calendar cal,
ext::shared_ptr<YoYInflationIndex> index,
Expand All @@ -115,6 +145,7 @@ namespace QuantLib {
Schedule schedule_;
ext::shared_ptr<YoYInflationIndex> index_;
Period observationLag_;
CPI::InterpolationType interpolation_;
std::vector<Real> notionals_;
DayCounter paymentDayCounter_;
BusinessDayConvention paymentAdjustment_ = ModifiedFollowing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ namespace QuantLib {
//@}

protected:
mutable std::vector<ext::shared_ptr<YoYOptionletVolatilitySurface> >
volCurves_;
mutable std::vector<ext::shared_ptr<YoYOptionletVolatilitySurface> > volCurves_;

// used to set up the first point on each vol curve
// using assumptions on unobserved vols at start
Expand Down Expand Up @@ -114,7 +113,7 @@ namespace QuantLib {
capfloor_ =
MakeYoYInflationCapFloor(type, anIndex,
(Size)std::floor(0.5+surf->timeFromReference(surf->minMaturity())),
surf->calendar(), lag)
surf->calendar(), lag, CPI::AsIndex)
.withNominal(10000.0)
.withStrike(K);

Expand Down Expand Up @@ -238,7 +237,8 @@ namespace QuantLib {
lag_,
dc, cal,
fixingDays_,
anIndex, K, nT, p_)));
anIndex, CPI::Flat,
K, nT, p_)));

ext::shared_ptr<ConstantYoYOptionletVolatility> yoyVolBLACK(
new ConstantYoYOptionletVolatility(found, settlementDays,
Expand Down
17 changes: 16 additions & 1 deletion ql/experimental/inflation/yoyoptionlethelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace QuantLib {
Calendar paymentCalendar,
Natural fixingDays,
ext::shared_ptr<YoYInflationIndex> index,
CPI::InterpolationType interpolation,
Rate strike,
Size n,
ext::shared_ptr<YoYInflationCapFloorEngine> pricer)
Expand All @@ -43,7 +44,7 @@ namespace QuantLib {
// build the instrument to reprice (only need do this once)
yoyCapFloor_ =
MakeYoYInflationCapFloor(capFloorType_, index_,
n_, calendar_, lag_)
n_, calendar_, lag_, interpolation)
.withNominal(notional)
.withFixingDays(fixingDays_)
.withPaymentDayCounter(yoyDayCounter_)
Expand All @@ -63,6 +64,20 @@ namespace QuantLib {
// haven't yet set the vol (term structure = surface)
}

YoYOptionletHelper::YoYOptionletHelper(const Handle<Quote>& price,
Real notional,
YoYInflationCapFloor::Type capFloorType,
Period& lag,
DayCounter yoyDayCounter,
Calendar paymentCalendar,
Natural fixingDays,
ext::shared_ptr<YoYInflationIndex> index,
Rate strike,
Size n,
ext::shared_ptr<YoYInflationCapFloorEngine> pricer)
: YoYOptionletHelper(price, notional, capFloorType, lag, yoyDayCounter, paymentCalendar,
fixingDays, index, CPI::AsIndex, strike, n, pricer) {}


Real YoYOptionletHelper::impliedQuote() const {
yoyCapFloor_->deepUpdate();
Expand Down
22 changes: 18 additions & 4 deletions ql/experimental/inflation/yoyoptionlethelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ namespace QuantLib {
: public BootstrapHelper<YoYOptionletVolatilitySurface> {
public:
YoYOptionletHelper(const Handle<Quote>& price,
Real notional, // get the price level right
// (e.g. bps = 10,000)
Real notional, // get the price level right, e.g., bps = 10,000
YoYInflationCapFloor::Type capFloorType,
Period& lag,
DayCounter yoyDayCounter,
Calendar paymentCalendar,
Natural fixingDays,
ext::shared_ptr<YoYInflationIndex> index,
CPI::InterpolationType interpolation,
Rate strike,
Size n,
ext::shared_ptr<YoYInflationCapFloorEngine> pricer);
/*! \deprecated Use the overload that passes an interpolation type instead.
Deprecated in version 1.36.
*/
[[deprecated("Use the overload that passes an interpolation type instead")]]
YoYOptionletHelper(const Handle<Quote>& price,
Real notional,
YoYInflationCapFloor::Type capFloorType,
Period& lag,
DayCounter yoyDayCounter,
Expand All @@ -55,8 +70,7 @@ namespace QuantLib {
YoYInflationCapFloor::Type capFloorType_;
Period lag_;
Natural fixingDays_;
ext::shared_ptr<YoYInflationIndex> index_; // VERY important - has
// nominal & yoy curves
ext::shared_ptr<YoYInflationIndex> index_;
Rate strike_;
Size n_; // how many payments
DayCounter yoyDayCounter_;
Expand Down
15 changes: 12 additions & 3 deletions ql/instruments/makeyoyinflationcapfloor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ namespace QuantLib {
ext::shared_ptr<YoYInflationIndex> index,
const Size& length,
Calendar cal,
const Period& observationLag)
const Period& observationLag,
CPI::InterpolationType interpolation)
: capFloorType_(capFloorType), length_(length), calendar_(std::move(cal)),
index_(std::move(index)), observationLag_(observationLag), strike_(Null<Rate>()),
index_(std::move(index)), observationLag_(observationLag),
interpolation_(interpolation), strike_(Null<Rate>()),

dayCounter_(Thirty360(Thirty360::BondBasis)) {}

MakeYoYInflationCapFloor::MakeYoYInflationCapFloor(YoYInflationCapFloor::Type capFloorType,
ext::shared_ptr<YoYInflationIndex> index,
const Size& length,
Calendar cal,
const Period& observationLag)
: MakeYoYInflationCapFloor(capFloorType, index, length, cal, observationLag, CPI::AsIndex) {}

MakeYoYInflationCapFloor::operator YoYInflationCapFloor() const {
ext::shared_ptr<YoYInflationCapFloor> capfloor = *this;
return *capfloor;
Expand All @@ -58,7 +67,7 @@ namespace QuantLib {
Unadjusted, Unadjusted, // ref periods & acc periods
DateGeneration::Forward, false);
Leg leg = yoyInflationLeg(schedule, calendar_, index_,
observationLag_)
observationLag_, interpolation_)
.withPaymentAdjustment(roll_)
.withPaymentDayCounter(dayCounter_)
.withNotionals(nominal_)
Expand Down
Loading

0 comments on commit 322aa3a

Please sign in to comment.