Coverage Report

Created: 2025-09-04 07:11

/src/quantlib/ql/indexes/equityindex.hpp
Line
Count
Source (jump to first uncovered line)
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 equityindex.hpp
21
    \brief base class for equity indexes
22
*/
23
24
#ifndef quantlib_equityindex_hpp
25
#define quantlib_equityindex_hpp
26
27
#include <ql/index.hpp>
28
#include <ql/time/calendar.hpp>
29
#include <ql/currency.hpp>
30
#include <ql/termstructures/yieldtermstructure.hpp>
31
32
namespace QuantLib {
33
34
    //! Base class for equity indexes
35
    /*! The equity index object allows to retrieve past fixings,
36
        as well as project future fixings using either both
37
        the risk free interest rate term structure and the dividend
38
        term structure, or just the interest rate term structure
39
        in which case one can provide a term structure of equity
40
        forwards implied from, e.g. option prices.
41
        
42
        In case of the first method, the forward is calculated as:
43
        \f[
44
        I(t, T) = I(t, t) \frac{P_{D}(t, T)}{P_{R}(t, T)},
45
        \f]
46
        where \f$ I(t, t) \f$ is today's value of the index,
47
        \f$ P_{D}(t, T) \f$ is a discount factor of the dividend
48
        curve at future time \f$ T \f$, and \f$ P_{R}(t, T) \f$ is
49
        a discount factor of the risk free curve at future time
50
        \f$ T \f$.
51
52
        In case of the latter method, the forward is calculated as:
53
        \f[
54
        I(t, T) = I(t, t) \frac{1}{P_{F}(t, T)},
55
        \f]
56
        where \f$ P_{F}(t, T) \f$ is a discount factor of the equity
57
        forward term structure.
58
59
        To forecast future fixings, the user can either provide a
60
        handle to the current index spot. If spot handle is empty,
61
        today's fixing will be used, instead.
62
    */
63
    class EquityIndex : public Index {
64
      public:
65
        EquityIndex(std::string name,
66
                    Calendar fixingCalendar,
67
                    Currency currency,
68
                    Handle<YieldTermStructure> interest = {},
69
                    Handle<YieldTermStructure> dividend = {},
70
                    Handle<Quote> spot = {});
71
72
        /*! \deprecated Use the constructor taking a currency.
73
                        Deprecated in version 1.36.
74
        */
75
        [[deprecated("Use the constructor taking a currency")]]
76
        EquityIndex(std::string name,
77
                    Calendar fixingCalendar,
78
                    Handle<YieldTermStructure> interest = {},
79
                    Handle<YieldTermStructure> dividend = {},
80
                    Handle<Quote> spot = {});
81
82
        //! \name Index interface
83
        //@{
84
0
        std::string name() const override { return name_; }
85
0
        Calendar fixingCalendar() const override { return fixingCalendar_; }
86
        bool isValidFixingDate(const Date& fixingDate) const override;
87
        Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
88
        //@}
89
        //! \name Inspectors
90
        //@{
91
        //! The index currency
92
0
        Currency currency() const { return currency_; }
93
        //! the rate curve used to forecast fixings
94
0
        Handle<YieldTermStructure> equityInterestRateCurve() const { return interest_; }
95
        //! the dividend curve used to forecast fixings
96
0
        Handle<YieldTermStructure> equityDividendCurve() const { return dividend_; }
97
        //! index spot value
98
0
        Handle<Quote> spot() const { return spot_; }
99
        //@}
100
        //! \name Fixing calculations
101
        //@{
102
        //! It can be overridden to implement particular conventions
103
        virtual Real forecastFixing(const Date& fixingDate) const;
104
        // @}
105
        //! \name Other methods
106
        //@{
107
        //! returns a copy of itself linked to different interest, dividend curves
108
        //! or spot quote
109
        virtual ext::shared_ptr<EquityIndex> clone(const Handle<YieldTermStructure>& interest,
110
                                                   const Handle<YieldTermStructure>& dividend,
111
                                                   const Handle<Quote>& spot) const;
112
        // @}
113
      private:
114
        std::string name_;
115
        Calendar fixingCalendar_;
116
        Currency currency_;
117
        Handle<YieldTermStructure> interest_;
118
        Handle<YieldTermStructure> dividend_;
119
        Handle<Quote> spot_;
120
    };
121
122
0
    inline bool EquityIndex::isValidFixingDate(const Date& d) const {
123
0
        return fixingCalendar().isBusinessDay(d);
124
0
    }
125
}
126
127
#endif