QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
overnightindexfutureratehelper.cpp
Go to the documentation of this file.
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
24
25namespace QuantLib {
26
27 namespace {
28
29 Date getSofrStart(Month month, Year year, Frequency freq) {
30 return freq == Monthly ? Date(1, month, year) :
31 Date::nthWeekday(3, Wednesday, month, year);
32 }
33
34 Date getSofrEnd(Month month, Year year, Frequency freq) {
35 if (freq == Monthly) {
36 return Date::endOfMonth(Date(1, month, year)) + 1;
37 } else {
38 Date d = getSofrStart(month, year, freq) + Period(freq);
39 return Date::nthWeekday(3, Wednesday, d.month(), d.year());
40 }
41
42 }
43
44 }
45
47 const Handle<Quote>& price,
48 // first day of reference period
49 const Date& valueDate,
50 // delivery date
51 const Date& maturityDate,
52 const ext::shared_ptr<OvernightIndex>& overnightIndex,
53 const Handle<Quote>& convexityAdjustment,
54 RateAveraging::Type averagingMethod)
55 : RateHelper(price) {
56 ext::shared_ptr<OvernightIndex> index =
57 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
58 future_ = ext::make_shared<OvernightIndexFuture>(
59 index, valueDate, maturityDate, convexityAdjustment, averagingMethod);
61 earliestDate_ = valueDate;
63 }
64
66 future_->recalculate();
67 return future_->NPV();
68 }
69
71 // do not set the relinkable handle as an observer -
72 // force recalculation when needed
73 bool observer = false;
74
75 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
76 termStructureHandle_.linkTo(temp, observer);
77
79 }
80
82 auto* v1 = dynamic_cast<Visitor<OvernightIndexFutureRateHelper>*>(&v);
83 if (v1 != nullptr)
84 v1->visit(*this);
85 else
87 }
88
90 return future_->convexityAdjustment();
91 }
92
93
95 const Handle<Quote>& price,
96 Month referenceMonth,
97 Year referenceYear,
98 Frequency referenceFreq,
99 const Handle<Quote>& convexityAdjustment)
101 getSofrStart(referenceMonth, referenceYear, referenceFreq),
102 getSofrEnd(referenceMonth, referenceYear, referenceFreq),
103 ext::make_shared<Sofr>(),
104 convexityAdjustment,
105 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
106 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
107 "only monthly and quarterly SOFR futures accepted");
108 }
109
111 Real price,
112 Month referenceMonth,
113 Year referenceYear,
114 Frequency referenceFreq,
115 Real convexityAdjustment)
117 Handle<Quote>(ext::make_shared<SimpleQuote>(price)),
118 getSofrStart(referenceMonth, referenceYear, referenceFreq),
119 getSofrEnd(referenceMonth, referenceYear, referenceFreq),
120 ext::make_shared<Sofr>(),
121 Handle<Quote>(ext::make_shared<SimpleQuote>(convexityAdjustment)),
122 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
123 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
124 "only monthly and quarterly SOFR futures accepted");
125 }
126}
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:424
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
void registerWithObservables(const ext::shared_ptr< Observer > &)
Definition: observable.hpp:235
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:38
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
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
Interest-rate term structure.
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
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:37
empty deleter for shared_ptr
Overnight Index Future bootstrap helper.
ext::shared_ptr< BlackVolTermStructure > v
SOFR index
rate averaging method