26#include <boost/make_shared.hpp>
31 const Handle<Quote> spotQuote,
const Handle<YieldTermStructure>& rate,
32 const Handle<YieldTermStructure>& dividend)
33 : familyName_(familyName), currency_(currency), rate_(rate), dividend_(dividend), spotQuote_(spotQuote),
34 fixingCalendar_(fixingCalendar) {
40 registerWith(Settings::instance().evaluationDate());
41 registerWith(IndexManager::instance().notifier(
name()));
45 return fixing(fixingDate, forecastTodaysFixing,
false);
51 "Fixing date " << fixingDate <<
" is not valid for equity index '" <<
name_ <<
"'");
53 Date today = Settings::instance().evaluationDate();
55 if (fixingDate > today || (fixingDate == today && forecastTodaysFixing))
58 Real result = Null<Decimal>();
60 if (fixingDate < today || Settings::instance().enforcesTodaysHistoricFixings()) {
64 QL_REQUIRE(result != Null<Real>(),
"Missing equity index fixing " <<
name() <<
" fixing for " << fixingDate);
72 if (result == Null<Real>())
82 QL_REQUIRE(!
rate_.empty(),
"null term structure set to this instance of " <<
name());
89 QL_REQUIRE(!
spotQuote_.empty(),
"null spot quote set to this instance of " <<
name());
90 QL_REQUIRE(!
rate_.empty() && !
dividend_.empty(),
"null term structure set to this instance of " <<
name());
98 forward = price /
rate_->discount(fixingTime);
100 forward = price *
dividend_->discount(fixingTime) /
rate_->discount(fixingTime);
106 std::string tag =
name();
107 std::set<Dividend> divs = DividendManager::instance().getHistory(tag);
108 if (!forceOverwrite) {
109 bool duplicateFixing =
false;
110 for (
const auto& d : divs) {
112 duplicateFixing =
true;
114 QL_REQUIRE(!duplicateFixing,
"At least one duplicated fixing provided: ("
115 << dividend.
name <<
", " << dividend.
exDate <<
", " << dividend.
rate <<
")");
117 divs.insert(dividend);
118 DividendManager::instance().setHistory(tag, divs);
122 const Date& today = Settings::instance().evaluationDate();
125 Real dividends = 0.0;
127 if (!history.empty()) {
128 for (std::set<Dividend>::const_iterator fd = history.begin();
129 fd != history.end() && fd->exDate <= std::min(endDate, today); ++fd) {
130 if (fd->exDate >= startDate)
131 dividends += fd->rate;
137QuantLib::ext::shared_ptr<EquityIndex2>
EquityIndex2::clone(
const Handle<Quote> spotQuote,
const Handle<YieldTermStructure>& rate,
138 const Handle<YieldTermStructure>& dividend)
const {
const Handle< YieldTermStructure > rate_
const Handle< YieldTermStructure > dividend_
virtual const std::set< Dividend > & dividendFixings() const
virtual QuantLib::ext::shared_ptr< EquityIndex2 > clone(const Handle< Quote > spotQuote, const Handle< YieldTermStructure > &rate, const Handle< YieldTermStructure > ÷nd) const
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
const Handle< Quote > spotQuote_
std::string name() const override
EquityIndex2(const std::string &familyName, const Calendar &fixingCalendar, const Currency ¤cy, const Handle< Quote > spotQuote=Handle< Quote >(), const Handle< YieldTermStructure > &rate=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > ÷nd=Handle< YieldTermStructure >())
bool isValidFixingDate(const Date &fixingDate) const override
Currency currency() const
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
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
equity index class for holding equity fixing histories and forwarding.
QuantLib::Real rate
Dividend rate.
std::string name
Index name.
QuantLib::Date exDate
Ex dividend date.