QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
indexedcashflow.hpp
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) 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
21/*! \file indexedcashflow.hpp
22 \brief Cash flow dependent on an index ratio (NOT a coupon, i.e. no accruals)
23 */
24
25#ifndef quantlib_indexed_cash_flow_hpp
26#define quantlib_indexed_cash_flow_hpp
27
29#include <ql/cashflow.hpp>
30#include <ql/index.hpp>
31
32namespace QuantLib {
33
34 //! Cash flow dependent on an index ratio.
35
36 /*! This cash flow is not a coupon, i.e., there's no accrual. The
37 amount is either i(T)/i(0) or i(T)/i(0) - 1, depending on the
38 growthOnly parameter.
39
40 We expect this to be used inside an instrument that does all the date
41 adjustment etc., so this takes just dates and does not change them.
42 growthOnly = false means i(T)/i(0), which is a bond-type setting.
43 growthOnly = true means i(T)/i(0) - 1, which is a swap-type setting.
44 */
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);
53 //! \name Event interface
54 //@{
55 Date date() const override { return paymentDate_; }
56 //@}
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_); }
64 //! \name CashFlow interface
65 //@{
66 Real amount() const override; // already virtual
67 //@}
68 //! \name Visitability
69 //@{
70 void accept(AcyclicVisitor&) override;
71 //@}
72 //! \name LazyObject interface
73 //@{
74 void performCalculations() const override;
75 //@}
76 protected:
77 mutable Real amount_;
78 private:
80 ext::shared_ptr<Index> index_;
83 };
84
85
86 // inline definitions
87
89 auto* v1 = dynamic_cast<Visitor<IndexedCashFlow>*>(&v);
90 if (v1 != nullptr)
91 v1->visit(*this);
92 else
93 CashFlow::accept(v);
94 }
95
96}
97
98#endif
Base class for cash flows.
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
virtual base class for indexes
Definition: any.hpp:35
ext::shared_ptr< BlackVolTermStructure > v
degenerate base class for the Acyclic Visitor pattern