Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
brlcdiratehelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
19#include <ql/pricingengines/swap/discountingswapengine.hpp>
20#include <ql/utilities/null_deleter.hpp>
23
24using namespace QuantLib;
25
26namespace QuantExt {
27
28BRLCdiRateHelper::BRLCdiRateHelper(const Period& swapTenor, const Handle<Quote>& fixedRate,
29 const QuantLib::ext::shared_ptr<BRLCdi>& brlCdiIndex,
30 const Handle<YieldTermStructure>& discountingCurve, bool telescopicValueDates)
31 : RelativeDateRateHelper(fixedRate), swapTenor_(swapTenor), brlCdiIndex_(brlCdiIndex),
32 telescopicValueDates_(telescopicValueDates), discountHandle_(discountingCurve) {
33
34 bool onIndexHasCurve = !brlCdiIndex_->forwardingTermStructure().empty();
35 bool haveDiscountCurve = !discountHandle_.empty();
36 QL_REQUIRE(!(onIndexHasCurve && haveDiscountCurve), "Have both curves nothing to solve for.");
37
38 if (!onIndexHasCurve) {
39 QuantLib::ext::shared_ptr<IborIndex> clonedIborIndex(brlCdiIndex_->clone(termStructureHandle_));
40 brlCdiIndex_ = QuantLib::ext::dynamic_pointer_cast<BRLCdi>(clonedIborIndex);
41 brlCdiIndex_->unregisterWith(termStructureHandle_);
42 }
43
44 registerWith(brlCdiIndex_);
45 registerWith(discountHandle_);
47}
48
50
51 // Use the overnight index's calendar for all business day adjustments
52 Calendar calendar = brlCdiIndex_->fixingCalendar();
53
54 // Adjust reference date to next good business day if necessary
55 Date referenceDate = Settings::instance().evaluationDate();
56 referenceDate = calendar.adjust(referenceDate);
57
58 // Determine the start date
59 Date startDate = calendar.advance(referenceDate, 2 * Days);
60 startDate = calendar.adjust(startDate, Following);
61
62 // Determine the end date
63 Date endDate = startDate + swapTenor_;
64
65 // Create the BRL CDI swap
66 swap_ = QuantLib::ext::make_shared<BRLCdiSwap>(OvernightIndexedSwap::Payer, 1.0, startDate, endDate, 0.01, brlCdiIndex_,
68
69 // Set the pricing engine
70 swap_->setPricingEngine(QuantLib::ext::make_shared<DiscountingSwapEngine>(discountRelinkableHandle_));
71
72 // Update earliest and latest dates
73 earliestDate_ = swap_->startDate();
74 latestDate_ = swap_->maturityDate();
75}
76
77void BRLCdiRateHelper::setTermStructure(YieldTermStructure* t) {
78
79 bool observer = false;
80 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
81 termStructureHandle_.linkTo(temp, observer);
82
83 if (discountHandle_.empty())
84 discountRelinkableHandle_.linkTo(temp, observer);
85 else
87
88 RelativeDateRateHelper::setTermStructure(t);
89}
90
92 QL_REQUIRE(termStructure_ != 0, "BRLCdiRateHelper's term structure not set");
93 swap_->deepUpdate();
94 return swap_->fairRate();
95}
96
97void BRLCdiRateHelper::accept(AcyclicVisitor& v) {
98 if (Visitor<BRLCdiRateHelper>* v1 = dynamic_cast<Visitor<BRLCdiRateHelper>*>(&v))
99 v1->visit(*this);
100 else
101 RateHelper::accept(v);
102}
103
104DatedBRLCdiRateHelper::DatedBRLCdiRateHelper(const Date& startDate, const Date& endDate, const Handle<Quote>& fixedRate,
105 const QuantLib::ext::shared_ptr<BRLCdi>& brlCdiIndex,
106 const Handle<YieldTermStructure>& discountingCurve,
107 bool telescopicValueDates)
108 : RateHelper(fixedRate), brlCdiIndex_(brlCdiIndex), telescopicValueDates_(telescopicValueDates),
109 discountHandle_(discountingCurve) {
110
111 bool onIndexHasCurve = !brlCdiIndex_->forwardingTermStructure().empty();
112 bool haveDiscountCurve = !discountHandle_.empty();
113 QL_REQUIRE(!(onIndexHasCurve && haveDiscountCurve), "Have both curves nothing to solve for.");
114
115 if (!onIndexHasCurve) {
116 QuantLib::ext::shared_ptr<IborIndex> clonedIborIndex(brlCdiIndex_->clone(termStructureHandle_));
117 brlCdiIndex_ = QuantLib::ext::dynamic_pointer_cast<BRLCdi>(clonedIborIndex);
118 brlCdiIndex_->unregisterWith(termStructureHandle_);
119 }
120
121 registerWith(brlCdiIndex_);
122 registerWith(discountHandle_);
123
124 swap_ = QuantLib::ext::make_shared<BRLCdiSwap>(OvernightIndexedSwap::Payer, 1.0, startDate, endDate, 0.01, brlCdiIndex_,
126
127 // Set the pricing engine
128 swap_->setPricingEngine(QuantLib::ext::make_shared<DiscountingSwapEngine>(discountRelinkableHandle_));
129
130 // Update earliest and latest dates
131 earliestDate_ = swap_->startDate();
132 latestDate_ = swap_->maturityDate();
133}
134
135void DatedBRLCdiRateHelper::setTermStructure(YieldTermStructure* t) {
136
137 bool observer = false;
138 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
139 termStructureHandle_.linkTo(temp, observer);
140
141 if (discountHandle_.empty())
142 discountRelinkableHandle_.linkTo(temp, observer);
143 else
145
146 RateHelper::setTermStructure(t);
147}
148
150 QL_REQUIRE(termStructure_ != 0, "DatedBRLCdiRateHelper's term structure not set");
151 swap_->deepUpdate();
152 return swap_->fairRate();
153}
154
155void DatedBRLCdiRateHelper::accept(AcyclicVisitor& v) {
156 if (Visitor<DatedBRLCdiRateHelper>* v1 = dynamic_cast<Visitor<DatedBRLCdiRateHelper>*>(&v))
157 v1->visit(*this);
158 else
159 RateHelper::accept(v);
160}
161
162} // namespace QuantExt
Rate helper based on standard BRL CDI swap.
Standard BRL CDI swap.
QuantLib::RelinkableHandle< QuantLib::YieldTermStructure > discountRelinkableHandle_
QuantLib::ext::shared_ptr< BRLCdiSwap > swap_
void accept(QuantLib::AcyclicVisitor &) override
QuantLib::RelinkableHandle< QuantLib::YieldTermStructure > termStructureHandle_
QuantLib::ext::shared_ptr< BRLCdi > brlCdiIndex_
BRLCdiRateHelper(const QuantLib::Period &swapTenor, const QuantLib::Handle< QuantLib::Quote > &fixedRate, const QuantLib::ext::shared_ptr< BRLCdi > &brlCdiIndex, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve=QuantLib::Handle< QuantLib::YieldTermStructure >(), bool telescopicValueDates=false)
QuantLib::Real impliedQuote() const override
void setTermStructure(QuantLib::YieldTermStructure *) override
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
QuantLib::RelinkableHandle< QuantLib::YieldTermStructure > discountRelinkableHandle_
QuantLib::ext::shared_ptr< BRLCdiSwap > swap_
void accept(QuantLib::AcyclicVisitor &) override
QuantLib::RelinkableHandle< QuantLib::YieldTermStructure > termStructureHandle_
QuantLib::ext::shared_ptr< BRLCdi > brlCdiIndex_
DatedBRLCdiRateHelper(const QuantLib::Date &startDate, const QuantLib::Date &endDate, const QuantLib::Handle< QuantLib::Quote > &fixedRate, const QuantLib::ext::shared_ptr< BRLCdi > &brlCdiIndex, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve=QuantLib::Handle< QuantLib::YieldTermStructure >(), bool telescopicValueDates=false)
QuantLib::Real impliedQuote() const override
void setTermStructure(QuantLib::YieldTermStructure *) override
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper