Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CompositeIndex Class Reference

#include <qle/indexes/compositeindex.hpp>

+ Inheritance diagram for CompositeIndex:
+ Collaboration diagram for CompositeIndex:

Public Member Functions

 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={})
 
std::string name () const override
 Index interface. More...
 
Calendar fixingCalendar () const override
 
bool isValidFixingDate (const Date &fixingDate) const override
 
Real fixing (const Date &fixingDate, bool forecastTodaysFixing=false) const override
 
bool allowsNativeFixings () override
 
void update () override
 Observer interface. More...
 
const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & indices () const
 Inspectors. More...
 
const std::vector< Real > & weights () const
 
const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & fxConversion () const
 
Real dividendsBetweenDates (const Date &startDate, const Date &endDate=Date::maxDate()) const
 
std::vector< std::pair< QuantLib::Date, std::string > > dividendFixingDates (const Date &startDate, const Date &endDate=Date::maxDate())
 

Private Attributes

std::string name_
 
std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > indices_
 
std::vector< Real > weights_
 
std::vector< QuantLib::ext::shared_ptr< FxIndex > > fxConversion_
 
Calendar fixingCalendar_
 

Detailed Description

Definition at line 35 of file compositeindex.hpp.

Constructor & Destructor Documentation

◆ 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.

32 QL_REQUIRE(indices_.size() == weights_.size(), "CompositeIndex: indices size (" << indices_.size()
33 << ") must match weights size ("
34 << weights_.size() << ")");
35 QL_REQUIRE(fxConversion_.empty() || fxConversion_.size() == indices_.size(),
36 "CompositeIndex: fx conversion size (" << fxConversion_.size() << ") must match indices size ("
37 << indices_.size() << ")");
38
39 for (auto const& f : fxConversion) {
40 registerWith(f);
41 }
42
43 std::vector<Calendar> cals;
44 for (auto const& i : indices) {
45 registerWith(i);
46 cals.push_back(i->fixingCalendar());
47 }
48
49 fixingCalendar_ = JointCalendar(cals);
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_
+ Here is the call graph for this function:

Member Function Documentation

◆ name()

std::string name ( ) const
override

Index interface.

Definition at line 52 of file compositeindex.cpp.

52{ return name_; }
+ Here is the caller graph for this function:

◆ fixingCalendar()

Calendar fixingCalendar ( ) const
override

Definition at line 54 of file compositeindex.cpp.

54{ return fixingCalendar_; }
+ Here is the caller graph for this function:

◆ isValidFixingDate()

bool isValidFixingDate ( const Date &  fixingDate) const
override

Definition at line 56 of file compositeindex.cpp.

56 {
57 return fixingCalendar_.isBusinessDay(fixingDate);
58}

◆ 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 // if the fixing date is not a valid fx fixing date, adjust the latter to the preceding valid date
75 result += indexFixing * weights_[i] *
76 (fxConversion_.empty() || fxConversion_[i] == nullptr
77 ? 1.0
78 : fxConversion_[i]->fixing(fxConversion_[i]->fixingCalendar().adjust(fixingDate, Preceding),
79 forecastTodaysFixing));
80 }
81 return result;
82}
Calendar fixingCalendar() const override
+ Here is the call graph for this function:

◆ allowsNativeFixings()

bool allowsNativeFixings ( )
override

Definition at line 48 of file compositeindex.hpp.

48{ return false; }

◆ update()

void update ( )
override

Observer interface.

Definition at line 51 of file compositeindex.hpp.

51{ notifyObservers(); }

◆ indices()

const std::vector< QuantLib::ext::shared_ptr< QuantLib::Index > > & indices ( ) const

Inspectors.

Definition at line 54 of file compositeindex.hpp.

54{ return indices_; }
+ Here is the caller graph for this function:

◆ weights()

const std::vector< Real > & weights ( ) const

Definition at line 55 of file compositeindex.hpp.

55{ return weights_; }

◆ fxConversion()

const std::vector< QuantLib::ext::shared_ptr< FxIndex > > & fxConversion ( ) const

Definition at line 56 of file compositeindex.hpp.

56{ return fxConversion_; }
+ Here is the caller graph for this function:

◆ 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 // if the fixing date is not a valid fx fixing date, adjust the latter to the preceding valid date
92 dividends +=
93 d.rate * weights_[i] *
94 (fxConversion_.empty() || fxConversion_[i] == nullptr
95 ? 1.0
96 : fxConversion_[i]->fixing(fxConversion_[i]->fixingCalendar().adjust(d.exDate, Preceding)));
97 }
98 }
99 }
100 }
101 return dividends;
102}
+ Here is the call graph for this function:

◆ 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) {
110 if (QuantLib::ext::dynamic_pointer_cast<EquityIndex2>(indices_[i]) && !fxConversion_.empty() && fxConversion_[i]) {
111 Date d = fxConversion_[i]->fixingCalendar().adjust(startDate, Preceding);
112 while (d <= eDate) {
113 fixings.push_back(std::make_pair<Date, std::string>(
114 fxConversion_[i]->fixingCalendar().adjust(d, Preceding), fxConversion_[i]->name()));
115 d = fxConversion_[i]->fixingCalendar().advance(d, 1, Days);
116 }
117 }
118 }
119 return fixings;
120 }
+ Here is the call graph for this function:

Member Data Documentation

◆ name_

std::string name_
private

Definition at line 65 of file compositeindex.hpp.

◆ indices_

std::vector<QuantLib::ext::shared_ptr<QuantLib::Index> > indices_
private

Definition at line 66 of file compositeindex.hpp.

◆ weights_

std::vector<Real> weights_
private

Definition at line 67 of file compositeindex.hpp.

◆ fxConversion_

std::vector<QuantLib::ext::shared_ptr<FxIndex> > fxConversion_
private

Definition at line 68 of file compositeindex.hpp.

◆ fixingCalendar_

Calendar fixingCalendar_
private

Definition at line 70 of file compositeindex.hpp.