Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
yoyswaphelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
20#include <ql/indexes/inflationindex.hpp>
21#include <ql/time/calendars/jointcalendar.hpp>
22#include <ql/cashflows/inflationcouponpricer.hpp>
23
24using QuantLib::BusinessDayConvention;
25using QuantLib::Calendar;
26using QuantLib::DateGeneration;
27using QuantLib::DayCounter;
28using QuantLib::Days;
29using QuantLib::Handle;
30using QuantLib::JointCalendar;
31using QuantLib::Natural;
32using QuantLib::Period;
33using QuantLib::PricingEngine;
34using QuantLib::Quote;
35using QuantLib::Real;
36using QuantLib::Schedule;
37using QuantLib::Settings;
38using QuantLib::YearOnYearInflationSwap;
39using QuantLib::YieldTermStructure;
40using QuantLib::YoYInflationIndex;
41
42namespace QuantExt {
43
44YoYSwapHelper::YoYSwapHelper(const Handle<Quote>& rate,
45 Natural settlementDays,
46 const Period& tenor,
47 const QuantLib::ext::shared_ptr<YoYInflationIndex>& yoyIndex,
48 const Handle<YieldTermStructure>& rateCurve,
49 const Period& observationLag,
50 const Calendar& yoyCalendar,
51 BusinessDayConvention yoyConvention,
52 const DayCounter& yoyDayCount,
53 const Calendar& fixedCalendar,
54 BusinessDayConvention fixedConvention,
55 const DayCounter& fixedDayCount,
56 const Calendar& paymentCalendar,
57 BusinessDayConvention paymentConvention,
58 const Period& fixedTenor,
59 const Period& yoyTenor)
60 : rate_(rate),
61 evaluationDate_(Settings::instance().evaluationDate()),
62 settlementDays_(settlementDays),
63 tenor_(tenor),
64 yoyIndex_(yoyIndex),
65 rateCurve_(rateCurve),
66 observationLag_(observationLag),
67 yoyCalendar_(yoyCalendar),
68 yoyConvention_(yoyConvention),
69 yoyDayCount_(yoyDayCount),
70 fixedCalendar_(fixedCalendar),
71 fixedConvention_(fixedConvention),
72 fixedDayCount_(fixedDayCount),
73 paymentCalendar_(paymentCalendar),
74 paymentConvention_(paymentConvention),
75 fixedTenor_(fixedTenor),
76 yoyTenor_(yoyTenor) {
77
78 registerWith(rate_);
79 registerWith(Settings::instance().evaluationDate());
80 registerWith(yoyIndex_);
81
82 createSwap();
83}
84
86 yoySwap_->setPricingEngine(engine_);
87 return rate_->value() - yoySwap_->fairRate();
88}
89
91 if (evaluationDate_ != Settings::instance().evaluationDate()) {
92 evaluationDate_ = Settings::instance().evaluationDate();
93 createSwap();
94 }
95 notifyObservers();
96}
97
98QuantLib::ext::shared_ptr<YearOnYearInflationSwap> YoYSwapHelper::yoySwap() const {
99 return yoySwap_;
100}
101
102void YoYSwapHelper::setPricingEngine(const QuantLib::ext::shared_ptr<PricingEngine>& engine) {
103 engine_ = engine;
104}
105
107 return rate_->value();
108}
109
111 yoySwap_->setPricingEngine(engine_);
112 return yoySwap_->fairRate();
113}
114
116
117 // YoY swap start date and end date.
118 JointCalendar jc(yoyCalendar_, fixedCalendar_);
119 auto start = jc.advance(evaluationDate_, settlementDays_ * Days);
120 auto end = start + tenor_;
121
122 // YoY fixed leg schedule.
123 Schedule fixedSchedule(start, end, fixedTenor_, fixedCalendar_, fixedConvention_,
124 fixedConvention_, DateGeneration::Backward, false);
125
126 // YoY leg schedule.
127 Schedule yoySchedule(start, end, yoyTenor_, yoyCalendar_, yoyConvention_,
128 yoyConvention_, DateGeneration::Backward, false);
129
130 // YoY swap
131 yoySwap_ = QuantLib::ext::make_shared<YearOnYearInflationSwap>(YearOnYearInflationSwap::Payer, 1.0,
132 fixedSchedule, 0.01, fixedDayCount_, yoySchedule, yoyIndex_, observationLag_, 0.0, yoyDayCount_,
134
135 // set coupon pricer
136 auto pricer = QuantLib::ext::make_shared<QuantLib::YoYInflationCouponPricer>(rateCurve_);
137 for (auto& c : yoySwap_->yoyLeg()) {
138 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<QuantLib::YoYInflationCoupon>(c))
139 cpn->setPricer(pricer);
140 }
141}
142
143} // namespace QuantExt
QuantLib::DayCounter fixedDayCount_
QuantLib::Period observationLag_
QuantLib::Real modelRate() const
Return the model implied fair year on year rate.
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engine_
The pricing engine used to value the YoY swap.
QuantLib::BusinessDayConvention paymentConvention_
QuantLib::Period yoyTenor_
QuantLib::Period fixedTenor_
void update() override
QuantLib::Real marketRate() const
Return the market fair year on year rate.
QuantLib::ext::shared_ptr< QuantLib::YearOnYearInflationSwap > yoySwap() const
QuantLib::Date evaluationDate_
QuantLib::ext::shared_ptr< QuantLib::YearOnYearInflationSwap > yoySwap_
The underlying YoY swap.
void createSwap()
Create the underlying YoY swap.
QuantLib::Real calibrationError() override
QuantLib::DayCounter yoyDayCount_
QuantLib::Natural settlementDays_
QuantLib::ext::shared_ptr< QuantLib::YoYInflationIndex > yoyIndex_
QuantLib::BusinessDayConvention yoyConvention_
void setPricingEngine(const QuantLib::ext::shared_ptr< QuantLib::PricingEngine > &engine)
Set the pricing engine to be used by the underlying YoY swap.
QuantLib::Calendar paymentCalendar_
QuantLib::BusinessDayConvention fixedConvention_
QuantLib::Handle< QuantLib::YieldTermStructure > rateCurve_
QuantLib::Calendar yoyCalendar_
QuantLib::Handle< QuantLib::Quote > rate_
The YoY market swap quote.
QuantLib::Calendar fixedCalendar_
YoYSwapHelper(const QuantLib::Handle< QuantLib::Quote > &rate, QuantLib::Natural settlementDays, const QuantLib::Period &tenor, const QuantLib::ext::shared_ptr< QuantLib::YoYInflationIndex > &yoyIndex, const QuantLib::Handle< QuantLib::YieldTermStructure > &rateCurve, const QuantLib::Period &observationLag, const QuantLib::Calendar &yoyCalendar, QuantLib::BusinessDayConvention yoyConvention, const QuantLib::DayCounter &yoyDayCount, const QuantLib::Calendar &fixedCalendar, QuantLib::BusinessDayConvention fixedConvention, const QuantLib::DayCounter &fixedDayCount, const QuantLib::Calendar &paymentCalendar, QuantLib::BusinessDayConvention paymentConvention, const QuantLib::Period &fixedTenor=1 *QuantLib::Years, const QuantLib::Period &yoyTenor=1 *QuantLib::Years)
Year on year helper constructor.
QuantLib::Period tenor_
Year on year inflation swap calibration helper.