#include <qle/indexes/compositeindex.hpp>
Definition at line 35 of file compositeindex.hpp.
◆ CompositeIndex()
CompositeIndex |
( |
const std::string & |
name, |
|
|
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & |
indices, |
|
|
const std::vector< Real > & |
weights, |
|
|
const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & |
fxConversion = {} |
|
) |
| |
fxConversion can be an empty vector or its length should match indices. For components that do not require a conversion, a nullptr should be given, otherwise a FxIndex with domestic ccy equal to the target currency of the index
Definition at line 28 of file compositeindex.cpp.
33 << ") must match weights size ("
36 "CompositeIndex: fx conversion size (" <<
fxConversion_.size() <<
") must match indices size ("
38
40 registerWith(f);
41 }
42
43 std::vector<Calendar> cals;
45 registerWith(i);
46 cals.push_back(i->fixingCalendar());
47 }
48
50}
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & indices() const
Inspectors.
std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > indices_
std::vector< QuantLib::ext::shared_ptr< FxIndex > > fxConversion_
const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & fxConversion() const
const std::vector< Real > & weights() const
std::string name() const override
Index interface.
std::vector< Real > weights_
◆ name()
std::string name |
( |
| ) |
const |
|
override |
◆ fixingCalendar()
Calendar fixingCalendar |
( |
| ) |
const |
|
override |
◆ isValidFixingDate()
bool isValidFixingDate |
( |
const Date & |
fixingDate | ) |
const |
|
override |
◆ fixing()
Real fixing |
( |
const Date & |
fixingDate, |
|
|
bool |
forecastTodaysFixing = false |
|
) |
| const |
|
override |
Definition at line 60 of file compositeindex.cpp.
60 {
61 Real result = 0.0;
62 for (Size i = 0; i <
indices_.size(); ++i) {
63 Real indexFixing;
64 try {
65 indexFixing =
indices_[i]->fixing(fixingDate, forecastTodaysFixing);
66 } catch (const std::exception&) {
67 auto gi = QuantLib::ext::dynamic_pointer_cast<QuantExt::GenericIndex>(
indices_[i]);
68 if (gi && gi->expiry() != Date() && fixingDate >= gi->expiry())
69 indexFixing = 0.0;
70 else
71 throw;
72 }
73
74
75 result += indexFixing *
weights_[i] *
77 ? 1.0
79 forecastTodaysFixing));
80 }
81 return result;
82}
Calendar fixingCalendar() const override
◆ allowsNativeFixings()
bool allowsNativeFixings |
( |
| ) |
|
|
override |
◆ update()
◆ indices()
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & indices |
( |
| ) |
const |
◆ weights()
const std::vector< Real > & weights |
( |
| ) |
const |
◆ fxConversion()
const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & fxConversion |
( |
| ) |
const |
◆ dividendsBetweenDates()
Real dividendsBetweenDates |
( |
const Date & |
startDate, |
|
|
const Date & |
endDate = Date::maxDate() |
|
) |
| const |
Collect dividends from equity underlying indices, apply weighting, fx conversion (if any) and return the sum. Notice that the endDate is capped at today, as in EquityIndex::dividendsBetweenDates. This only applies to underlying equity indices, for other index types zero dividends are returned
Definition at line 84 of file compositeindex.cpp.
84 {
85 const Date& today = Settings::instance().evaluationDate();
86 Real dividends = 0.0;
87 for (Size i = 0; i <
indices_.size(); ++i) {
88 if (
auto ei = QuantLib::ext::dynamic_pointer_cast<EquityIndex2>(
indices_[i])) {
89 for (auto const& d : ei->dividendFixings()) {
90 if (d.exDate >= startDate && d.exDate <= std::min(endDate, today)) {
91
92 dividends +=
95 ? 1.0
97 }
98 }
99 }
100 }
101 return dividends;
102}
◆ dividendFixingDates()
std::vector< std::pair< QuantLib::Date, std::string > > dividendFixingDates |
( |
const Date & |
startDate, |
|
|
const Date & |
endDate = Date::maxDate() |
|
) |
| |
Definition at line 104 of file compositeindex.cpp.
105 {
106
107 std::vector<std::pair<QuantLib::Date, std::string>> fixings;
108 const Date& eDate = endDate == Date() ? Settings::instance().evaluationDate() : endDate;
109 for (Size i = 0; i <
indices_.size(); ++i) {
111 Date d =
fxConversion_[i]->fixingCalendar().adjust(startDate, Preceding);
112 while (d <= eDate) {
113 fixings.push_back(std::make_pair<Date, std::string>(
116 }
117 }
118 }
119 return fixings;
120 }
◆ name_
◆ indices_
std::vector<QuantLib::ext::shared_ptr<QuantLib::Index> > indices_ |
|
private |
◆ weights_
std::vector<Real> weights_ |
|
private |
◆ fxConversion_
std::vector<QuantLib::ext::shared_ptr<FxIndex> > fxConversion_ |
|
private |
◆ fixingCalendar_