Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
yoycapfloorhelper.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/cashflows/yoyinflationcoupon.hpp>
22#include <vector>
23
24using QuantLib::BusinessDayConvention;
25using QuantLib::Calendar;
26using QuantLib::DateGeneration;
27using QuantLib::DayCounter;
28using QuantLib::Days;
29using QuantLib::Handle;
30using QuantLib::Leg;
31using QuantLib::Natural;
32using QuantLib::Period;
33using QuantLib::PricingEngine;
34using QuantLib::Quote;
35using QuantLib::Rate;
36using QuantLib::Real;
37using QuantLib::Schedule;
38using QuantLib::Settings;
39using QuantLib::YoYInflationCapFloor;
40using QuantLib::yoyInflationLeg;
41using QuantLib::YoYInflationIndex;
42using std::vector;
43
44namespace QuantExt {
45
46YoYCapFloorHelper::YoYCapFloorHelper(const Handle<Quote>& premium,
47 YoYInflationCapFloor::Type type,
48 Rate strike,
49 Natural settlementDays,
50 const Period& tenor,
51 const QuantLib::ext::shared_ptr<YoYInflationIndex>& yoyIndex,
52 const Period& observationLag,
53 const Calendar& yoyCalendar,
54 BusinessDayConvention yoyConvention,
55 const DayCounter& yoyDayCount,
56 const Calendar& paymentCalendar,
57 BusinessDayConvention paymentConvention,
58 const Period& yoyTenor)
59 : premium_(premium),
60 evaluationDate_(Settings::instance().evaluationDate()),
61 type_(type),
62 strike_(strike),
63 settlementDays_(settlementDays),
64 tenor_(tenor),
65 yoyIndex_(yoyIndex),
66 observationLag_(observationLag),
67 yoyCalendar_(yoyCalendar),
68 yoyConvention_(yoyConvention),
69 yoyDayCount_(yoyDayCount),
70 paymentCalendar_(paymentCalendar),
71 paymentConvention_(paymentConvention),
72 yoyTenor_(yoyTenor) {
73
74 registerWith(premium_);
75 registerWith(Settings::instance().evaluationDate());
76 registerWith(yoyIndex_);
77
79}
80
82 yoyCapFloor_->setPricingEngine(engine_);
83 return premium_->value() - yoyCapFloor_->NPV();
84}
85
87 if (evaluationDate_ != Settings::instance().evaluationDate()) {
88 evaluationDate_ = Settings::instance().evaluationDate();
90 }
91 notifyObservers();
92}
93
94QuantLib::ext::shared_ptr<YoYInflationCapFloor> YoYCapFloorHelper::yoyCapFloor() const {
95 return yoyCapFloor_;
96}
97
98void YoYCapFloorHelper::setPricingEngine(const QuantLib::ext::shared_ptr<PricingEngine>& engine) {
100}
101
102QuantLib::Real YoYCapFloorHelper::marketValue() const {
103 return premium_->value();
104}
105
106QuantLib::Real YoYCapFloorHelper::modelValue() const {
107 yoyCapFloor_->setPricingEngine(engine_);
108 return yoyCapFloor_->NPV();
109}
110
112
113 // YoY cap floor start date and end date.
114 auto start = yoyCalendar_.advance(evaluationDate_, settlementDays_ * Days);
115 auto end = start + tenor_;
116
117 // YoY leg schedule.
118 Schedule yoySchedule(start, end, yoyTenor_, yoyCalendar_, yoyConvention_,
119 yoyConvention_, DateGeneration::Backward, false);
120
121 // YoY leg.
122 Leg yoyLeg = yoyInflationLeg(yoySchedule, paymentCalendar_, yoyIndex_, observationLag_)
123 .withNotionals(1.0)
126
127 // YoY cap floor.
128 vector<Rate> strikes{ strike_ };
129 yoyCapFloor_ = QuantLib::ext::make_shared<YoYInflationCapFloor>(type_, yoyLeg, strikes);
130}
131
132}
QuantLib::Real modelValue() const
Return the model value.
QuantLib::Real marketValue() const
Return the market premium value.
QuantLib::ext::shared_ptr< QuantLib::PricingEngine > engine_
The pricing engine used to value the YoY swap.
QuantLib::BusinessDayConvention paymentConvention_
YoYCapFloorHelper(const QuantLib::Handle< QuantLib::Quote > &premium, QuantLib::YoYInflationCapFloor::Type type, QuantLib::Rate strike, QuantLib::Natural settlementDays, const QuantLib::Period &tenor, const QuantLib::ext::shared_ptr< QuantLib::YoYInflationIndex > &yoyIndex, const QuantLib::Period &observationLag, const QuantLib::Calendar &yoyCalendar, QuantLib::BusinessDayConvention yoyConvention, const QuantLib::DayCounter &yoyDayCount, const QuantLib::Calendar &paymentCalendar, QuantLib::BusinessDayConvention paymentConvention, const QuantLib::Period &yoyTenor=1 *QuantLib::Years)
QuantLib::YoYInflationCapFloor::Type type_
QuantLib::Real calibrationError() override
QuantLib::DayCounter yoyDayCount_
QuantLib::ext::shared_ptr< QuantLib::YoYInflationCapFloor > yoyCapFloor_
The underlying YoY cap floor.
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 cap floor.
QuantLib::Handle< QuantLib::Quote > premium_
The market price quote for the YoY cap floor.
QuantLib::Calendar paymentCalendar_
void createCapFloor()
Create the underlying YoY cap floor.
QuantLib::ext::shared_ptr< QuantLib::YoYInflationCapFloor > yoyCapFloor() const
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
vector< Real > strikes
Year on year inflation cap floor calibration helper.