Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
equityindex.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/indexes/equityindex.hpp
20 \brief equity index class for holding equity fixing histories and forwarding.
21 \ingroup indexes
22*/
23
24#ifndef quantext_equityindex_hpp
25#define quantext_equityindex_hpp
26
27#include <ql/currency.hpp>
28#include <ql/handle.hpp>
29#include <ql/termstructures/yieldtermstructure.hpp>
30#include <ql/time/calendar.hpp>
31#include <ql/currency.hpp>
34
35namespace QuantExt {
36using namespace QuantLib;
37
38//! Equity Index
39/*! \ingroup indexes
40 Renamed to EquityIndex2, because Quantlib has introduced an EquityIndex class in v1.30
41 which causes name conflicts in the compilation of the joint SWIG wrapper across
42 QuantLib and QuantExt.
43*/
45public:
46 /*! spot quote is interpreted as of today */
47 EquityIndex2(const std::string& familyName, const Calendar& fixingCalendar, const Currency& currency,
48 const Handle<Quote> spotQuote = Handle<Quote>(),
49 const Handle<YieldTermStructure>& rate = Handle<YieldTermStructure>(),
50 const Handle<YieldTermStructure>& dividend = Handle<YieldTermStructure>());
51 //! \name Index interface
52 //@{
53 std::string name() const override;
54 Currency currency() const { return currency_; }
55 Calendar fixingCalendar() const override;
56 bool isValidFixingDate(const Date& fixingDate) const override;
57 // Equity fixing price - can be either fixed historical or forecasted.
58 // Forecasted price can include dividend returns by setting incDividend = true
59 Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const override;
60 Real fixing(const Date& fixingDate, bool forecastTodaysFixing, bool incDividend) const;
61 // Dividends
62 //! stores the historical dividend at the given date
63 /*! the date passed as arguments must be the actual calendar
64 date of the dividend.
65 */
66 virtual void addDividend(const Dividend& fixing, bool forceOverwrite = false);
67 virtual const std::set<Dividend>& dividendFixings() const { return DividendManager::instance().getHistory(name()); }
68 Real dividendsBetweenDates(const Date& startDate, const Date& endDate) const;
69 //@}
70 //! \name Observer interface
71 //@{
72 void update() override;
73 //@}
74 //! \name Inspectors
75 //@{
76 std::string familyName() const { return familyName_; }
77 const Handle<Quote>& equitySpot() const { return spotQuote_; }
78 const Handle<YieldTermStructure>& equityForecastCurve() const { return rate_; }
79 const Handle<YieldTermStructure>& equityDividendCurve() const { return dividend_; }
80 //@}
81 //! \name Fixing calculations
82 //@{
83 virtual Real forecastFixing(const Date& fixingDate) const;
84 virtual Real forecastFixing(const Time& fixingTime) const override;
85 virtual Real forecastFixing(const Date& fixingDate, bool incDividend) const;
86 virtual Real forecastFixing(const Time& fixingTime, bool incDividend) const;
87 virtual Real pastFixing(const Date& fixingDate) const override;
88 // @}
89 //! \name Additional methods
90 //@{
91 virtual QuantLib::ext::shared_ptr<EquityIndex2> clone(const Handle<Quote> spotQuote, const Handle<YieldTermStructure>& rate,
92 const Handle<YieldTermStructure>& dividend) const;
93 // @}
94protected:
95 std::string familyName_;
96 Currency currency_;
97 const Handle<YieldTermStructure> rate_, dividend_;
98 std::string name_;
99 const Handle<Quote> spotQuote_;
100
101private:
103};
104
105// inline definitions
106
107inline std::string EquityIndex2::name() const { return name_; }
108
109inline Calendar EquityIndex2::fixingCalendar() const { return fixingCalendar_; }
110
111inline bool EquityIndex2::isValidFixingDate(const Date& d) const { return fixingCalendar().isBusinessDay(d); }
112
113inline void EquityIndex2::update() { notifyObservers(); }
114
115inline Real EquityIndex2::pastFixing(const Date& fixingDate) const {
116 QL_REQUIRE(isValidFixingDate(fixingDate), fixingDate << " is not a valid fixing date");
117 return timeSeries()[fixingDate];
118}
119} // namespace QuantExt
120
121#endif
const Handle< YieldTermStructure > rate_
Definition: equityindex.hpp:97
const Handle< Quote > & equitySpot() const
Definition: equityindex.hpp:77
const Handle< YieldTermStructure > dividend_
Definition: equityindex.hpp:97
virtual const std::set< Dividend > & dividendFixings() const
Definition: equityindex.hpp:67
virtual QuantLib::ext::shared_ptr< EquityIndex2 > clone(const Handle< Quote > spotQuote, const Handle< YieldTermStructure > &rate, const Handle< YieldTermStructure > &dividend) const
void update() override
Calendar fixingCalendar() const override
virtual void addDividend(const Dividend &fixing, bool forceOverwrite=false)
stores the historical dividend at the given date
virtual Real forecastFixing(const Date &fixingDate) const
Definition: equityindex.cpp:79
const Handle< Quote > spotQuote_
Definition: equityindex.hpp:99
std::string name() const override
const Handle< YieldTermStructure > & equityDividendCurve() const
Definition: equityindex.hpp:79
bool isValidFixingDate(const Date &fixingDate) const override
Currency currency() const
Definition: equityindex.hpp:54
const Handle< YieldTermStructure > & equityForecastCurve() const
Definition: equityindex.hpp:78
virtual Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
Real dividendsBetweenDates(const Date &startDate, const Date &endDate) const
std::string familyName() const
Definition: equityindex.hpp:76
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
Definition: equityindex.cpp:44
Dividend manager.
A common base class for the FX and Equity Indices. Provides a forecast fixing method for time so the ...