Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
averageoisratehelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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/utilities/null_deleter.hpp>
22
23namespace QuantExt {
24
25AverageOISRateHelper::AverageOISRateHelper(const Handle<Quote>& fixedRate, const Period& spotLagTenor,
26 const Period& swapTenor,
27 // Fixed leg
28 const Period& fixedTenor, const DayCounter& fixedDayCounter,
29 const Calendar& fixedCalendar, BusinessDayConvention fixedConvention,
30 BusinessDayConvention fixedPaymentAdjustment,
31 // ON leg
32 const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex,
33 const Period& onTenor, const Handle<Quote>& onSpread, Natural rateCutoff,
34 // Exogenous discount curve
35 const Handle<YieldTermStructure>& discountCurve,
36 const bool telescopicValueDates)
37 : RelativeDateRateHelper(fixedRate), spotLagTenor_(spotLagTenor), swapTenor_(swapTenor), fixedTenor_(fixedTenor),
38 fixedDayCounter_(fixedDayCounter), fixedCalendar_(fixedCalendar), fixedConvention_(fixedConvention),
39 fixedPaymentAdjustment_(fixedPaymentAdjustment), overnightIndex_(overnightIndex), onTenor_(onTenor),
40 onSpread_(onSpread), rateCutoff_(rateCutoff), discountHandle_(discountCurve),
41 telescopicValueDates_(telescopicValueDates) {
42
43 bool onIndexHasCurve = !overnightIndex_->forwardingTermStructure().empty();
44 bool haveDiscountCurve = !discountHandle_.empty();
45 QL_REQUIRE(!(onIndexHasCurve && haveDiscountCurve), "Have both curves nothing to solve for.");
46
47 if (!onIndexHasCurve) {
48 QuantLib::ext::shared_ptr<IborIndex> clonedIborIndex(overnightIndex_->clone(termStructureHandle_));
49 overnightIndex_ = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(clonedIborIndex);
51 }
52
53 registerWith(overnightIndex_);
54 registerWith(onSpread_);
55 registerWith(discountHandle_);
57}
58
60
70
71 earliestDate_ = averageOIS_->startDate();
72 latestDate_ = averageOIS_->maturityDate();
73}
74
76
77 QL_REQUIRE(termStructure_ != 0, "term structure not set");
78 averageOIS_->deepUpdate();
79
80 // Calculate the fair fixed rate after accounting for the
81 // spread in the spread quote. Recall, the spread quote was
82 // intentionally not added to instrument averageOIS_.
83 static const Spread basisPoint = 1.0e-4;
84 Real onLegNPV = averageOIS_->overnightLegNPV();
85 Spread onSpread = onSpread_.empty() ? 0.0 : onSpread_->value();
86 Real spreadNPV = averageOIS_->overnightLegBPS() * onSpread / basisPoint;
87 Real onLegNPVwithSpread = onLegNPV + spreadNPV;
88 Real result = -onLegNPVwithSpread / (averageOIS_->fixedLegBPS() / basisPoint);
89 return result;
90}
91
92void AverageOISRateHelper::setTermStructure(YieldTermStructure* t) {
93
94 bool observer = false;
95 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
96 termStructureHandle_.linkTo(temp, observer);
97
98 if (discountHandle_.empty())
99 discountRelinkableHandle_.linkTo(temp, observer);
100 else
102
103 RelativeDateRateHelper::setTermStructure(t);
104}
105
106Spread AverageOISRateHelper::onSpread() const { return onSpread_.empty() ? 0.0 : onSpread_->value(); }
107
108QuantLib::ext::shared_ptr<AverageOIS> AverageOISRateHelper::averageOIS() const { return averageOIS_; }
109
110void AverageOISRateHelper::accept(AcyclicVisitor& v) {
111
112 Visitor<AverageOISRateHelper>* v1 = dynamic_cast<Visitor<AverageOISRateHelper>*>(&v);
113 if (v1 != 0)
114 v1->visit(*this);
115 else
116 RateHelper::accept(v);
117}
118} // namespace QuantExt
Rate helpers to facilitate usage of AverageOIS in bootstrapping.
RelinkableHandle< YieldTermStructure > discountRelinkableHandle_
void setTermStructure(YieldTermStructure *) override
BusinessDayConvention fixedConvention_
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
RelinkableHandle< YieldTermStructure > termStructureHandle_
BusinessDayConvention fixedPaymentAdjustment_
QuantLib::ext::shared_ptr< AverageOIS > averageOIS_
Handle< YieldTermStructure > discountHandle_
void accept(AcyclicVisitor &) override
QuantLib::ext::shared_ptr< AverageOIS > averageOIS() const
AverageOISRateHelper(const Handle< Quote > &fixedRate, const Period &spotLagTenor, const Period &swapTenor, const Period &fixedTenor, const DayCounter &fixedDayCounter, const Calendar &fixedCalendar, BusinessDayConvention fixedConvention, BusinessDayConvention fixedPaymentAdjustment, const QuantLib::ext::shared_ptr< OvernightIndex > &overnightIndex, const Period &onTenor, const Handle< Quote > &onSpread, Natural rateCutoff, const Handle< YieldTermStructure > &discountCurve=Handle< YieldTermStructure >(), const bool telescopicValueDates=false)
MakeAverageOIS & withFixedConvention(BusinessDayConvention fixedConvention)
MakeAverageOIS & withTelescopicValueDates(bool telescopicValueDates)
MakeAverageOIS & withRateCutoff(Natural rateCutoff)
MakeAverageOIS & withFixedPaymentAdjustment(BusinessDayConvention fixedPaymentAdjustment)
MakeAverageOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeAverageOIS & withFixedTerminationDateConvention(BusinessDayConvention fixedTerminationDateConvention)
MakeAverageOIS & withFixedCalendar(const Calendar &fixedCalendar)
Helper class to instantiate standard average ON indexed swaps.