Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
dividendmanager.cpp
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
21#include <ql/time/calendars/nullcalendar.hpp>
22#include <boost/algorithm/string/case_conv.hpp>
23
24using namespace::std;
25using namespace::QuantLib;
26using boost::algorithm::to_upper_copy;
27
28namespace QuantExt {
29
30void applyDividends(const set<Dividend>& dividends) {
31 map<string, QuantLib::ext::shared_ptr<EquityIndex2>> cache;
32 QuantLib::ext::shared_ptr<EquityIndex2> index;
33 std::string lastIndexName;
34 for (auto& d: dividends) {
35 try {
36 if (lastIndexName != d.name) {
37 index = QuantLib::ext::make_shared<EquityIndex2>(d.name, NullCalendar(), Currency());
38 lastIndexName = d.name;
39 }
40 index->addDividend(d, true);
41 } catch (...) {}
42 }
43}
44
45bool operator<(const Dividend& d1, const Dividend& d2) {
46 if (d1.name != d2.name)
47 return d1.name < d2.name;
48 return d1.exDate < d2.exDate;
49}
50
51bool operator==(const Dividend& d1, const Dividend& d2) {
52 return d1.exDate == d2.exDate && d1.name == d2.name;
53}
54
55std::ostream& operator<<(std::ostream& out, Dividend dividend) {
56 return out << dividend.name << "," << dividend.exDate;
57}
58
59bool DividendManager::hasHistory(const string& name) const { return data_.find(to_upper_copy(name)) != data_.end(); }
60
61const set<Dividend>& DividendManager::getHistory(const string& name) {
62 return data_[to_upper_copy(name)].value();
63}
64
65void DividendManager::setHistory(const string& name, const std::set<Dividend>& history) {
66 data_[to_upper_copy(name)] = history;
67}
68
69QuantLib::ext::shared_ptr<Observable> DividendManager::notifier(const string& name) { return data_[to_upper_copy(name)]; }
70
71void DividendManager::clearHistory(const std::string& name) { data_.erase(name); }
72
74
75}
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
void clearHistory(const std::string &name)
bool hasHistory(const std::string &name) const
returns whether historical fixings were stored for the index
Dividend manager.
equity index class for holding equity fixing histories and forwarding.
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.
std::string name
Index name.
QuantLib::Date exDate
Ex dividend date.