Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
immfraratehelper.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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/time/imm.hpp>
20#include <ql/utilities/null_deleter.hpp>
22
23using namespace std;
24namespace QuantExt {
25
26Date getImmDate(Date asof, Size i) {
27 Date imm = asof;
28 for (Size j = 0; j < i; j++) {
29 imm = IMM::nextDate(imm, true);
30 }
31 return imm;
32}
33
34ImmFraRateHelper::ImmFraRateHelper(const Handle<Quote>& rate, const Size imm1, const Size imm2,
35 const QuantLib::ext::shared_ptr<IborIndex>& i, Pillar::Choice pillarChoice,
36 Date customPillarDate)
37 : RelativeDateRateHelper(rate), imm1_(imm1), imm2_(imm2), pillarChoice_(pillarChoice) {
38 // take fixing into account
40 // see above
41 iborIndex_->unregisterWith(termStructureHandle_);
42 registerWith(iborIndex_);
43 pillarDate_ = customPillarDate;
45}
46
48 QL_REQUIRE(termStructure_ != 0, "term structure not set");
49 return iborIndex_->fixing(fixingDate_, true);
50}
51
52void ImmFraRateHelper::setTermStructure(YieldTermStructure* t) {
53 // do not set the relinkable handle as an observer -
54 // force recalculation when needed---the index is not lazy
55 bool observer = false;
56
57 QuantLib::ext::shared_ptr<YieldTermStructure> temp(t, null_deleter());
58 termStructureHandle_.linkTo(temp, observer);
59
60 RelativeDateRateHelper::setTermStructure(t);
61}
62
64 // if the evaluation date is not a business day
65 // then move to the next business day
66 Date referenceDate = iborIndex_->fixingCalendar().adjust(evaluationDate_);
67 Date spotDate = iborIndex_->fixingCalendar().advance(referenceDate, iborIndex_->fixingDays() * Days);
68
69 earliestDate_ = iborIndex_->fixingCalendar().adjust(getImmDate(spotDate, imm1_));
70 maturityDate_ = iborIndex_->fixingCalendar().adjust(getImmDate(spotDate, imm2_));
71
72 // latest relevant date is calculated from earliestDate_ instead
73 latestRelevantDate_ = iborIndex_->maturityDate(earliestDate_);
74
75 switch (pillarChoice_) {
76 case Pillar::MaturityDate:
77 pillarDate_ = maturityDate_;
78 break;
79 case Pillar::LastRelevantDate:
80 pillarDate_ = latestRelevantDate_;
81 break;
82 case Pillar::CustomDate:
83 // pillarDate_ already assigned at construction time
84 QL_REQUIRE(pillarDate_ >= earliestDate_, "pillar date (" << pillarDate_
85 << ") must be later "
86 "than or equal to the instrument's earliest date ("
87 << earliestDate_ << ")");
88 QL_REQUIRE(pillarDate_ <= latestRelevantDate_, "pillar date ("
89 << pillarDate_
90 << ") must be before "
91 "or equal to the instrument's latest relevant date ("
92 << latestRelevantDate_ << ")");
93 break;
94 default:
95 QL_FAIL("unknown Pillar::Choice(" << Integer(pillarChoice_) << ")");
96 }
97
98 latestDate_ = pillarDate_; // backward compatibility
99
100 fixingDate_ = iborIndex_->fixingDate(earliestDate_);
101}
102
103void ImmFraRateHelper::accept(AcyclicVisitor& v) {
104 Visitor<ImmFraRateHelper>* v1 = dynamic_cast<Visitor<ImmFraRateHelper>*>(&v);
105 if (v1 != 0)
106 v1->visit(*this);
107 else
108 RateHelper::accept(v);
109}
110
111}; // namespace QuantExt
void setTermStructure(YieldTermStructure *) override
RelinkableHandle< YieldTermStructure > termStructureHandle_
void accept(AcyclicVisitor &) override
Real impliedQuote() const override
ImmFraRateHelper(const Handle< Quote > &rate, const Size imm1, const Size imm2, const QuantLib::ext::shared_ptr< IborIndex > &iborIndex, Pillar::Choice pillar=Pillar::LastRelevantDate, Date customPillarDate=Date())
QuantLib::ext::shared_ptr< IborIndex > iborIndex_
IMM FRA rate helper.
Date getImmDate(Date asof, Size i)
RelativeDateBootstrapHelper< YieldTermStructure > RelativeDateRateHelper