QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
overnightindexfutureratehelper.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2018 Roy Zywina
5 Copyright (C) 2019, 2020 Eisuke Tani
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21#include <ql/termstructures/yield/overnightindexfutureratehelper.hpp>
22#include <ql/indexes/ibor/sofr.hpp>
23#include <ql/utilities/null_deleter.hpp>
24
25namespace QuantLib {
26
27 namespace {
28
29 Date getValidSofrStart(Month month, Year year, Frequency freq) {
30 return freq == Monthly ?
31 UnitedStates(UnitedStates::GovernmentBond).adjust(Date(1, month, year)) :
32 Date::nthWeekday(3, Wednesday, month, year);
33 }
34
35 Date getValidSofrEnd(Month month, Year year, Frequency freq) {
36 if (freq == Monthly) {
37 Calendar dc = UnitedStates(UnitedStates::GovernmentBond);
38 Date d = dc.endOfMonth(Date(1, month, year));
39 return dc.advance(d, 1*Days);
40 } else {
41 Date d = getValidSofrStart(month, year, freq) + Period(freq);
42 return Date::nthWeekday(3, Wednesday, d.month(), d.year());
43 }
44
45 }
46
47 }
48
50 const Handle<Quote>& price,
51 // first day of reference period
52 const Date& valueDate,
53 // delivery date
54 const Date& maturityDate,
55 const ext::shared_ptr<OvernightIndex>& overnightIndex,
56 const Handle<Quote>& convexityAdjustment,
57 RateAveraging::Type averagingMethod)
58 : RateHelper(price) {
59 ext::shared_ptr<Payoff> payoff;
60 ext::shared_ptr<OvernightIndex> index =
61 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
62 future_ = ext::make_shared<OvernightIndexFuture>(
63 index, valueDate, maturityDate, convexityAdjustment, averagingMethod);
64 earliestDate_ = valueDate;
66 }
67
69 future_->recalculate();
70 return future_->NPV();
71 }
72
74 // do not set the relinkable handle as an observer -
75 // force recalculation when needed
76 bool observer = false;
77
78 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
79 termStructureHandle_.linkTo(temp, observer);
80
82 }
83
85 auto* v1 = dynamic_cast<Visitor<OvernightIndexFutureRateHelper>*>(&v);
86 if (v1 != nullptr)
87 v1->visit(*this);
88 else
90 }
91
93 return future_->convexityAdjustment();
94 }
95
96
98 const Handle<Quote>& price,
99 Month referenceMonth,
100 Year referenceYear,
101 Frequency referenceFreq,
102 const Handle<Quote>& convexityAdjustment)
104 getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
105 getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
106 ext::make_shared<Sofr>(),
107 convexityAdjustment,
108 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
109 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
110 "only monthly and quarterly SOFR futures accepted");
111 }
112
114 Real price,
115 Month referenceMonth,
116 Year referenceYear,
117 Frequency referenceFreq,
118 Real convexityAdjustment)
120 Handle<Quote>(ext::make_shared<SimpleQuote>(price)),
121 getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
122 getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
123 ext::make_shared<Sofr>(),
124 Handle<Quote>(ext::make_shared<SimpleQuote>(convexityAdjustment)),
125 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
126 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
127 "only monthly and quarterly SOFR futures accepted");
128 }
129}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Base helper class for bootstrapping.
virtual void accept(AcyclicVisitor &)
virtual Date maturityDate() const
instrument's maturity date
virtual void setTermStructure(TS *)
sets the term structure to be used for pricing
Concrete date class.
Definition: date.hpp:125
Month month() const
Definition: date.cpp:82
Year year() const
Definition: date.cpp:93
static Date endOfMonth(const Date &d)
last day of the month to which the given date belongs
Definition: date.hpp:428
static Date advance(const Date &d, Integer units, TimeUnit)
Definition: date.cpp:139
static Date nthWeekday(Size n, Weekday w, Month m, Year y)
n-th given weekday in the given month and year
Definition: date.cpp:802
Shared handle to an observable.
Definition: handle.hpp:41
RateHelper for bootstrapping over overnight compounding futures.
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
OvernightIndexFutureRateHelper(const Handle< Quote > &price, const Date &valueDate, const Date &maturityDate, const ext::shared_ptr< OvernightIndex > &overnightIndex, const Handle< Quote > &convexityAdjustment={}, RateAveraging::Type averagingMethod=RateAveraging::Compound)
ext::shared_ptr< OvernightIndexFuture > future_
purely virtual base class for market observables
Definition: quote.hpp:37
market element returning a stored value
Definition: simplequote.hpp:33
SofrFutureRateHelper(const Handle< Quote > &price, Month referenceMonth, Year referenceYear, Frequency referenceFreq, const Handle< Quote > &convexityAdjustment={})
Sofr (Secured Overnight Financing Rate) index.
Definition: sofr.hpp:32
@ GovernmentBond
government-bond calendar
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Interest-rate term structure.
Frequency
Frequency of events.
Definition: frequency.hpp:37
Integer Year
Year number.
Definition: date.hpp:87
Month
Month names.
Definition: date.hpp:57
@ Monthly
once a month
Definition: frequency.hpp:44
@ Quarterly
every third month
Definition: frequency.hpp:42
@ Wednesday
Definition: weekday.hpp:44
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
rate averaging method