Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
compoequityindex.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
22#include <ql/quotes/compositequote.hpp>
23#include <ql/time/calendars/jointcalendar.hpp>
24
25namespace QuantExt {
26
27CompoEquityIndex::CompoEquityIndex(const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& source,
28 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex, const Date& dividendCutoffDate)
29 : QuantExt::EquityIndex2(source->familyName() + "_compo_" + fxIndex->targetCurrency().code(),
30 JointCalendar(source->fixingCalendar(), fxIndex->fixingCalendar()), fxIndex->targetCurrency(),
31 Handle<Quote>(QuantLib::ext::make_shared<CompositeQuote<std::function<Real(Real, Real)>>>(
32 source->equitySpot(), fxIndex->fxQuote(),
33 std::function<Real(Real, Real)>([](Real x, Real y) { return x * y; }))),
34 Handle<YieldTermStructure>(QuantLib::ext::make_shared<DiscountRatioModifiedCurve>(
35 source->equityForecastCurve(), fxIndex->targetCurve(), fxIndex->sourceCurve())),
36 source->equityDividendCurve()),
37 source_(source), fxIndex_(fxIndex), dividendCutoffDate_(dividendCutoffDate) {
38 LazyObject::registerWith(source_);
39 LazyObject::registerWith(fxIndex_);
40}
41
42QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> CompoEquityIndex::source() const { return source_; }
43
44void CompoEquityIndex::addDividend(const Dividend& dividend, bool forceOverwrite) {
45 if (dividendCutoffDate_ == Date() || dividend.exDate >= dividendCutoffDate_) {
46 Dividend newDiv(dividend.exDate, dividend.name, dividend.rate / fxIndex_->fixing(dividend.exDate),
47 dividend.payDate);
48 source_->addDividend(newDiv, forceOverwrite);
49 LazyObject::update();
50 }
51}
52
54 dividendFixings_ = std::set<Dividend>();
55 auto const& ts = source_->dividendFixings();
56 for (auto const& d : ts) {
57 if (dividendCutoffDate_ == Date() || d.exDate >= dividendCutoffDate_) {
58 Dividend div(d.exDate, d.name, d.rate * fxIndex_->fixing(fxIndex_->fixingCalendar().adjust(d.exDate, Preceding)), d.payDate);
59 dividendFixings_.insert(div);
60 }
61 }
62}
63
64const std::set<Dividend>& CompoEquityIndex::dividendFixings() const {
65 calculate();
66 return dividendFixings_;
67}
68
69Real CompoEquityIndex::pastFixing(const Date& fixingDate) const {
70 return source_->fixing(fixingDate) * fxIndex_->fixing(fixingDate);
71}
72
73QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> CompoEquityIndex::clone(const Handle<Quote> spotQuote,
74 const Handle<YieldTermStructure>& rate,
75 const Handle<YieldTermStructure>& dividend) const {
76 return QuantLib::ext::make_shared<CompoEquityIndex>(source_->clone(spotQuote, rate, dividend), fxIndex_);
77}
78
79} // namespace QuantExt
void performCalculations() const override
const std::set< Dividend > & dividendFixings() const override
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > clone(const Handle< Quote > spotQuote, const Handle< YieldTermStructure > &rate, const Handle< YieldTermStructure > &dividend) const override
std::set< Dividend > dividendFixings_
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > source() const
void addDividend(const Dividend &dividend, bool forceOverwrite=false) override
stores the historical dividend at the given date
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > source_
Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
CompoEquityIndex(const QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > &source, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex, const Date &dividendCutoffDate=Date())
equity index converting the original equity currency to another currency
discount curve modified by the ratio of two other discount curves
QuantLib::Real rate
Dividend rate.
std::string name
Index name.
QuantLib::Date payDate
Dividend Payment date.
QuantLib::Date exDate
Ex dividend date.