QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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
25
26namespace QuantLib {
27
28 namespace {
29
30 Date getValidSofrStart(Month month, Year year, Frequency freq) {
31 return freq == Monthly ?
32 UnitedStates(UnitedStates::GovernmentBond).adjust(Date(1, month, year)) :
33 Date::nthWeekday(3, Wednesday, month, year);
34 }
35
36 Date getValidSofrEnd(Month month, Year year, Frequency freq) {
37 if (freq == Monthly) {
38 Calendar dc = UnitedStates(UnitedStates::GovernmentBond);
39 Date d = dc.endOfMonth(Date(1, month, year));
40 return dc.advance(d, 1*Days);
41 } else {
42 Date d = getValidSofrStart(month, year, freq) + Period(freq);
43 return Date::nthWeekday(3, Wednesday, d.month(), d.year());
44 }
45
46 }
47
48 }
49
51 const Handle<Quote>& price,
52 // first day of reference period
53 const Date& valueDate,
54 // delivery date
55 const Date& maturityDate,
56 const ext::shared_ptr<OvernightIndex>& overnightIndex,
57 const Handle<Quote>& convexityAdjustment,
58 RateAveraging::Type averagingMethod)
59 : RateHelper(price) {
60 ext::shared_ptr<Payoff> payoff;
61 ext::shared_ptr<OvernightIndex> index =
62 ext::dynamic_pointer_cast<OvernightIndex>(overnightIndex->clone(termStructureHandle_));
63 future_ = ext::make_shared<OvernightIndexFuture>(
64 index, valueDate, maturityDate, convexityAdjustment, averagingMethod);
65 earliestDate_ = valueDate;
67 }
68
70 future_->recalculate();
71 return future_->NPV();
72 }
73
75 // do not set the relinkable handle as an observer -
76 // force recalculation when needed
77 bool observer = false;
78
79 ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
80 termStructureHandle_.linkTo(temp, observer);
81
83 }
84
86 auto* v1 = dynamic_cast<Visitor<OvernightIndexFutureRateHelper>*>(&v);
87 if (v1 != nullptr)
88 v1->visit(*this);
89 else
91 }
92
94 return future_->convexityAdjustment();
95 }
96
97
99 const Handle<Quote>& price,
100 Month referenceMonth,
101 Year referenceYear,
102 Frequency referenceFreq,
103 const Handle<Quote>& convexityAdjustment)
105 getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
106 getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
107 ext::make_shared<Sofr>(),
108 convexityAdjustment,
109 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
110 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
111 "only monthly and quarterly SOFR futures accepted");
112 }
113
115 Real price,
116 Month referenceMonth,
117 Year referenceYear,
118 Frequency referenceFreq,
119 Real convexityAdjustment)
121 Handle<Quote>(ext::make_shared<SimpleQuote>(price)),
122 getValidSofrStart(referenceMonth, referenceYear, referenceFreq),
123 getValidSofrEnd(referenceMonth, referenceYear, referenceFreq),
124 ext::make_shared<Sofr>(),
125 Handle<Quote>(ext::make_shared<SimpleQuote>(convexityAdjustment)),
126 referenceFreq == Quarterly ? RateAveraging::Compound : RateAveraging::Simple) {
127 QL_REQUIRE(referenceFreq == Quarterly || referenceFreq == Monthly,
128 "only monthly and quarterly SOFR futures accepted");
129 }
130}
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.
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
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
empty deleter for shared_ptr
Overnight Index Future bootstrap helper.
ext::shared_ptr< BlackVolTermStructure > v
SOFR index
rate averaging method
US calendars.