Coverage Report

Created: 2026-03-11 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/equitycashflow.hpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2023 Marcin Rybacki
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
 <https://www.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
/*! \file equitycashflow.hpp
21
    \brief equity cash flow
22
*/
23
24
#ifndef quantlib_equity_cash_flow_hpp
25
#define quantlib_equity_cash_flow_hpp
26
27
#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
28
#include <ql/termstructures/yield/zeroyieldstructure.hpp>
29
#include <ql/cashflows/indexedcashflow.hpp>
30
#include <ql/patterns/visitor.hpp>
31
32
namespace QuantLib {
33
    
34
    class EquityIndex;
35
    class EquityCashFlowPricer;
36
    
37
    class EquityCashFlow : public IndexedCashFlow {
38
       public:
39
        EquityCashFlow(Real notional,
40
                       ext::shared_ptr<EquityIndex> index,
41
                       const Date& baseDate,
42
                       const Date& fixingDate,
43
                       const Date& paymentDate,
44
                       bool growthOnly = true);
45
        //! \name CashFlow interface
46
        //@{
47
        Real amount() const override;
48
        //@}
49
        //! \name Visitability
50
        //@{
51
        void accept(AcyclicVisitor&) override;
52
        //@}
53
        void setPricer(const ext::shared_ptr<EquityCashFlowPricer>&);
54
0
        const ext::shared_ptr<EquityCashFlowPricer>& pricer() const { return pricer_; };
55
56
      private:
57
        ext::shared_ptr<EquityCashFlowPricer> pricer_;
58
    };
59
60
0
    inline void EquityCashFlow::accept(AcyclicVisitor& v) {
61
0
        auto* v1 = dynamic_cast<Visitor<EquityCashFlow>*>(&v);
62
0
        if (v1 != nullptr)
63
0
            v1->visit(*this);
64
0
        else
65
0
            IndexedCashFlow::accept(v);
66
0
    }
67
68
    void setCouponPricer(const Leg& leg, const ext::shared_ptr<EquityCashFlowPricer>&);
69
70
    class EquityCashFlowPricer : public virtual Observer, public virtual Observable {
71
      public:
72
0
        EquityCashFlowPricer() = default;
73
        //! \name Interface
74
        //@{
75
        virtual Real price() const = 0;
76
        virtual void initialize(const EquityCashFlow&) = 0;
77
        //@}
78
79
        //! \name Observer interface
80
        //@{
81
0
        void update() override { notifyObservers(); }
82
        //@}
83
      protected:
84
        ext::shared_ptr<EquityIndex> index_;
85
        Date baseDate_, fixingDate_;
86
        bool growthOnlyPayoff_;
87
    };
88
89
    class EquityQuantoCashFlowPricer : public EquityCashFlowPricer {
90
      public:
91
        EquityQuantoCashFlowPricer(Handle<YieldTermStructure> quantoCurrencyTermStructure,
92
                                   Handle<BlackVolTermStructure> equityVolatility,
93
                                   Handle<BlackVolTermStructure> fxVolatility,
94
                                   Handle<Quote> correlation);
95
        //! \name Interface
96
        //@{
97
        Real price() const override;
98
        void initialize(const EquityCashFlow&) override;
99
        //@}
100
      private:
101
        Handle<YieldTermStructure> quantoCurrencyTermStructure_, quantoTermStructure;
102
        Handle<BlackVolTermStructure> equityVolatility_, fxVolatility_;
103
        Handle<Quote> correlation_;
104
    };
105
}
106
107
#endif