QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
indexedcashflow.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2009 Chris Kenyon
5 Copyright (C) 2022 Quaternion Risk Management Ltd
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#ifndef quantlib_indexed_cash_flow_hpp
26#define quantlib_indexed_cash_flow_hpp
27
28#include <ql/patterns/visitor.hpp>
29#include <ql/cashflow.hpp>
30#include <ql/index.hpp>
31
32namespace QuantLib {
33
35
45 class IndexedCashFlow : public CashFlow {
46 public:
48 ext::shared_ptr<Index> index,
49 const Date& baseDate,
50 const Date& fixingDate,
51 const Date& paymentDate,
52 bool growthOnly = false);
54
55 Date date() const override { return paymentDate_; }
57 virtual Real notional() const { return notional_; }
58 virtual Date baseDate() const { return baseDate_; }
59 virtual Date fixingDate() const { return fixingDate_; }
60 virtual ext::shared_ptr<Index> index() const { return index_; }
61 virtual bool growthOnly() const { return growthOnly_; }
62 virtual Real baseFixing() const { return index_->fixing(baseDate()); }
63 virtual Real indexFixing() const { return index_->fixing(fixingDate_); }
65
66 Real amount() const override; // already virtual
68
70 void accept(AcyclicVisitor&) override;
72
74 void performCalculations() const override;
76 private:
78 ext::shared_ptr<Index> index_;
81 mutable Real amount_;
82 };
83
84
85 // inline definitions
86
88 auto* v1 = dynamic_cast<Visitor<IndexedCashFlow>*>(&v);
89 if (v1 != nullptr)
90 v1->visit(*this);
91 else
92 CashFlow::accept(v);
93 }
94
95}
96
97#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Base class for cash flows.
Definition: cashflow.hpp:40
Concrete date class.
Definition: date.hpp:125
Cash flow dependent on an index ratio.
ext::shared_ptr< Index > index_
void performCalculations() const override
virtual Date fixingDate() const
virtual Real indexFixing() const
virtual Real notional() const
Real amount() const override
returns the amount of the cash flow
void accept(AcyclicVisitor &) override
virtual Real baseFixing() const
virtual Date baseDate() const
Date date() const override
virtual bool growthOnly() const
virtual ext::shared_ptr< Index > index() const
Visitor for a specific class
Definition: visitor.hpp:40
virtual void visit(T &)=0
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35