Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dividendmanager.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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/dividendmanager.hpp
20 \brief Dividend manager
21*/
22
23#ifndef quantext_divdendmanager_hpp
24#define quantext_divdendmanager_hpp
25
26#include <ql/patterns/singleton.hpp>
27#include <ql/timeseries.hpp>
28#include <ql/utilities/observablevalue.hpp>
29
30namespace QuantExt {
31
32struct Dividend {
33 //! Ex dividend date
34 QuantLib::Date exDate = QuantLib::Date();
35 //! Index name
36 std::string name = std::string();
37 //! Dividend rate
38 QuantLib::Real rate = QuantLib::Null<QuantLib::Real>();
39 //! Dividend Payment date
40 QuantLib::Date payDate = QuantLib::Date();
41
42 //! Constructor
44 Dividend(const QuantLib::Date& ed, const std::string& s, const QuantLib::Real r, const QuantLib::Date& pd)
45 : exDate(ed), name(s), rate(r), payDate(pd) {}
46 bool empty() {
47 return name.empty() && exDate == QuantLib::Date() && rate == QuantLib::Null<QuantLib::Real>() &&
48 payDate == QuantLib::Date();
49 }
50};
51
52//! Compare dividends
53bool operator==(const Dividend& d1, const Dividend& d);
54bool operator<(const Dividend& d1, const Dividend& d2);
55std::ostream& operator<<(std::ostream&, Dividend);
56
57//! Utility to write a set of dividends in the dividend manager's history
58void applyDividends(const std::set<Dividend>& dividends);
59
60//! global repository for past dividends
61/*! \note index names are case insensitive */
62class DividendManager : public QuantLib::Singleton<DividendManager> {
63 friend class QuantLib::Singleton<DividendManager>;
64
65private:
66 DividendManager() = default;
67
68public:
69 //! returns whether historical fixings were stored for the index
70 bool hasHistory(const std::string& name) const;
71 //! returns the (possibly empty) history of the index fixings
72 const std::set<Dividend>& getHistory(const std::string& name);
73 //! stores the historical fixings of the index
74 void setHistory(const std::string& name, const std::set<Dividend>&);
75 //! observer notifying of changes in the index fixings
76 QuantLib::ext::shared_ptr<QuantLib::Observable> notifier(const std::string& name);
77 void clearHistory(const std::string& name);
78 void clearHistories();
79
80private:
81 typedef std::map<std::string, QuantLib::ObservableValue<std::set<Dividend>>> history_map;
83};
84
85} // namespace QuantExt
86
87#endif
global repository for past dividends
void setHistory(const std::string &name, const std::set< Dividend > &)
stores the historical fixings of the index
const std::set< Dividend > & getHistory(const std::string &name)
returns the (possibly empty) history of the index fixings
QuantLib::ext::shared_ptr< QuantLib::Observable > notifier(const std::string &name)
observer notifying of changes in the index fixings
std::map< std::string, QuantLib::ObservableValue< std::set< Dividend > > > history_map
void clearHistory(const std::string &name)
bool hasHistory(const std::string &name) const
returns whether historical fixings were stored for the index
bool operator<(const Dividend &d1, const Dividend &d2)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
bool operator==(const Dividend &d1, const Dividend &d2)
Compare dividends.
void applyDividends(const set< Dividend > &dividends)
Utility to write a set of dividends in the dividend manager's history.
Dividend(const QuantLib::Date &ed, const std::string &s, const QuantLib::Real r, const QuantLib::Date &pd)
QuantLib::Real rate
Dividend rate.
std::string name
Index name.
QuantLib::Date payDate
Dividend Payment date.
QuantLib::Date exDate
Ex dividend date.
Dividend()
Constructor.