QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
zeroinflationcashflow.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2021 Ralf Konrad Eckel
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
20#include <ql/cashflows/zeroinflationcashflow.hpp>
21#include <ql/indexes/inflationindex.hpp>
22#include <ql/termstructures/inflationtermstructure.hpp>
23#include <ql/time/calendars/nullcalendar.hpp>
24
25namespace QuantLib {
26
28 const ext::shared_ptr<ZeroInflationIndex>& index,
29 CPI::InterpolationType observationInterpolation,
30 const Date& startDate,
31 const Date& endDate,
32 const Period& observationLag,
33 const Date& paymentDate,
34 bool growthOnly)
35 : IndexedCashFlow(notional, index,
36 startDate - observationLag, endDate - observationLag,
37 paymentDate, growthOnly),
38 zeroInflationIndex_(index), observationInterpolation_(observationInterpolation),
39 startDate_(startDate), endDate_(endDate), observationLag_(observationLag) {}
40
42
43 Real I0, I1;
44
46 I0 = zeroInflationIndex_->fixing(baseDate());
47 I1 = zeroInflationIndex_->fixing(fixingDate());
48 } else {
51 }
52
53 if (growthOnly())
54 return notional() * (I1 / I0 - 1.0);
55 else
56 return notional() * (I1 / I0);
57 }
58
60 auto* v1 = dynamic_cast<Visitor<ZeroInflationCashFlow>*>(&v);
61 if (v1 != nullptr)
62 v1->visit(*this);
63 else
65 }
66
67}
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Concrete date class.
Definition: date.hpp:125
Cash flow dependent on an index ratio.
virtual Date fixingDate() const
virtual Real notional() const
void accept(AcyclicVisitor &) override
virtual Date baseDate() const
virtual bool growthOnly() const
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
ext::shared_ptr< ZeroInflationIndex > zeroInflationIndex_
Real amount() const override
returns the amount of the cash flow
void accept(AcyclicVisitor &) override
CPI::InterpolationType observationInterpolation_
ZeroInflationCashFlow(Real notional, const ext::shared_ptr< ZeroInflationIndex > &index, CPI::InterpolationType observationInterpolation, const Date &startDate, const Date &endDate, const Period &observationLag, const Date &paymentDate, bool growthOnly=false)
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
static Real laggedFixing(const ext::shared_ptr< ZeroInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated inflation fixing
InterpolationType
when you observe an index, how do you interpolate between fixings?
@ AsIndex
same interpolation as index