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

Equity Index. More...

#include <qle/indexes/equityindex.hpp>

+ Inheritance diagram for EquityIndex2:
+ Collaboration diagram for EquityIndex2:

Public Member Functions

 EquityIndex2 (const std::string &familyName, const Calendar &fixingCalendar, const Currency &currency, const Handle< Quote > spotQuote=Handle< Quote >(), const Handle< YieldTermStructure > &rate=Handle< YieldTermStructure >(), const Handle< YieldTermStructure > &dividend=Handle< YieldTermStructure >())
 
Index interface
std::string name () const override
 
Currency currency () const
 
Calendar fixingCalendar () const override
 
bool isValidFixingDate (const Date &fixingDate) const override
 
Real fixing (const Date &fixingDate, bool forecastTodaysFixing=false) const override
 
Real fixing (const Date &fixingDate, bool forecastTodaysFixing, bool incDividend) const
 
virtual void addDividend (const Dividend &fixing, bool forceOverwrite=false)
 stores the historical dividend at the given date More...
 
virtual const std::set< Dividend > & dividendFixings () const
 
Real dividendsBetweenDates (const Date &startDate, const Date &endDate) const
 
Observer interface
void update () override
 
Inspectors
std::string familyName () const
 
const Handle< Quote > & equitySpot () const
 
const Handle< YieldTermStructure > & equityForecastCurve () const
 
const Handle< YieldTermStructure > & equityDividendCurve () const
 
Fixing calculations
virtual Real forecastFixing (const Date &fixingDate) const
 
virtual Real forecastFixing (const Time &fixingTime) const override
 returns the fixing at the given time More...
 
virtual Real forecastFixing (const Date &fixingDate, bool incDividend) const
 
virtual Real forecastFixing (const Time &fixingTime, bool incDividend) const
 
virtual Real pastFixing (const Date &fixingDate) const override
 returns a past fixing at the given date More...
 
- Public Member Functions inherited from EqFxIndexBase
virtual ~EqFxIndexBase ()
 
virtual Real forecastFixing (const Time &fixingTime) const =0
 returns the fixing at the given time More...
 
virtual Real pastFixing (const Date &fixingDate) const =0
 returns a past fixing at the given date More...
 

Additional methods

std::string familyName_
 
Currency currency_
 
const Handle< YieldTermStructure > rate_
 
const Handle< YieldTermStructure > dividend_
 
std::string name_
 
const Handle< Quote > spotQuote_
 
Calendar fixingCalendar_
 
virtual QuantLib::ext::shared_ptr< EquityIndex2clone (const Handle< Quote > spotQuote, const Handle< YieldTermStructure > &rate, const Handle< YieldTermStructure > &dividend) const
 

Detailed Description

Equity Index.

Renamed to EquityIndex2, because Quantlib has introduced an EquityIndex class in v1.30 which causes name conflicts in the compilation of the joint SWIG wrapper across QuantLib and QuantExt.

Definition at line 44 of file equityindex.hpp.

Constructor & Destructor Documentation

◆ EquityIndex2()

EquityIndex2 ( const std::string &  familyName,
const Calendar &  fixingCalendar,
const Currency &  currency,
const Handle< Quote >  spotQuote = Handle<Quote>(),
const Handle< YieldTermStructure > &  rate = Handle<YieldTermStructure>(),
const Handle< YieldTermStructure > &  dividend = Handle<YieldTermStructure>() 
)

spot quote is interpreted as of today

Definition at line 30 of file equityindex.cpp.

33 : familyName_(familyName), currency_(currency), rate_(rate), dividend_(dividend), spotQuote_(spotQuote),
35
37 registerWith(spotQuote_);
38 registerWith(rate_);
39 registerWith(dividend_);
40 registerWith(Settings::instance().evaluationDate());
41 registerWith(IndexManager::instance().notifier(name()));
42}
const Handle< YieldTermStructure > rate_
Definition: equityindex.hpp:97
const Handle< YieldTermStructure > dividend_
Definition: equityindex.hpp:97
Calendar fixingCalendar() const override
const Handle< Quote > spotQuote_
Definition: equityindex.hpp:99
std::string name() const override
Currency currency() const
Definition: equityindex.hpp:54
std::string familyName() const
Definition: equityindex.hpp:76
+ Here is the call graph for this function:

Member Function Documentation

◆ name()

std::string name ( ) const
override

Definition at line 107 of file equityindex.hpp.

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

◆ currency()

Currency currency ( ) const

Definition at line 54 of file equityindex.hpp.

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

◆ fixingCalendar()

Calendar fixingCalendar ( ) const
override

Definition at line 109 of file equityindex.hpp.

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

◆ isValidFixingDate()

bool isValidFixingDate ( const Date &  fixingDate) const
override

Definition at line 111 of file equityindex.hpp.

111{ return fixingCalendar().isBusinessDay(d); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixing() [1/2]

Real fixing ( const Date &  fixingDate,
bool  forecastTodaysFixing = false 
) const
override

Definition at line 44 of file equityindex.cpp.

44 {
45 return fixing(fixingDate, forecastTodaysFixing, false);
46}
Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
Definition: equityindex.cpp:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fixing() [2/2]

Real fixing ( const Date &  fixingDate,
bool  forecastTodaysFixing,
bool  incDividend 
) const

Definition at line 48 of file equityindex.cpp.

48 {
49
50 QL_REQUIRE(isValidFixingDate(fixingDate),
51 "Fixing date " << fixingDate << " is not valid for equity index '" << name_ << "'");
52
53 Date today = Settings::instance().evaluationDate();
54
55 if (fixingDate > today || (fixingDate == today && forecastTodaysFixing))
56 return forecastFixing(fixingDate, incDividend);
57
58 Real result = Null<Decimal>();
59
60 if (fixingDate < today || Settings::instance().enforcesTodaysHistoricFixings()) {
61 // must have been fixed
62 // do not catch exceptions
63 result = pastFixing(fixingDate);
64 QL_REQUIRE(result != Null<Real>(), "Missing equity index fixing " << name() << " fixing for " << fixingDate);
65 } else {
66 try {
67 // might have been fixed
68 result = pastFixing(fixingDate);
69 } catch (Error&) {
70 ; // fall through and forecast
71 }
72 if (result == Null<Real>())
73 return forecastFixing(fixingDate, incDividend);
74 }
75
76 return result;
77}
virtual Real forecastFixing(const Date &fixingDate) const
Definition: equityindex.cpp:79
bool isValidFixingDate(const Date &fixingDate) const override
virtual Real pastFixing(const Date &fixingDate) const override
returns a past fixing at the given date
+ Here is the call graph for this function:

◆ addDividend()

void addDividend ( const Dividend fixing,
bool  forceOverwrite = false 
)
virtual

stores the historical dividend at the given date

the date passed as arguments must be the actual calendar date of the dividend.

Reimplemented in CompoEquityIndex.

Definition at line 105 of file equityindex.cpp.

105 {
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) {
111 if (d == dividend)
112 duplicateFixing = true;
113 }
114 QL_REQUIRE(!duplicateFixing, "At least one duplicated fixing provided: ("
115 << dividend.name << ", " << dividend.exDate << ", " << dividend.rate << ")");
116 }
117 divs.insert(dividend);
118 DividendManager::instance().setHistory(tag, divs);
119}
+ Here is the call graph for this function:

◆ dividendFixings()

virtual const std::set< Dividend > & dividendFixings ( ) const
virtual

Reimplemented in CompoEquityIndex.

Definition at line 67 of file equityindex.hpp.

67{ return DividendManager::instance().getHistory(name()); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dividendsBetweenDates()

Real dividendsBetweenDates ( const Date &  startDate,
const Date &  endDate 
) const

Definition at line 121 of file equityindex.cpp.

121 {
122 const Date& today = Settings::instance().evaluationDate();
123
124 const std::set<Dividend>& history = dividendFixings();
125 Real dividends = 0.0;
126
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;
132 }
133 }
134 return dividends;
135}
virtual const std::set< Dividend > & dividendFixings() const
Definition: equityindex.hpp:67
+ Here is the call graph for this function:

◆ update()

void update ( )
override

Definition at line 113 of file equityindex.hpp.

113{ notifyObservers(); }

◆ familyName()

std::string familyName ( ) const

Definition at line 76 of file equityindex.hpp.

76{ return familyName_; }
+ Here is the caller graph for this function:

◆ equitySpot()

const Handle< Quote > & equitySpot ( ) const

Definition at line 77 of file equityindex.hpp.

77{ return spotQuote_; }

◆ equityForecastCurve()

const Handle< YieldTermStructure > & equityForecastCurve ( ) const

Definition at line 78 of file equityindex.hpp.

78{ return rate_; }

◆ equityDividendCurve()

const Handle< YieldTermStructure > & equityDividendCurve ( ) const

Definition at line 79 of file equityindex.hpp.

79{ return dividend_; }

◆ forecastFixing() [1/4]

Real forecastFixing ( const Date &  fixingDate) const
virtual

Definition at line 79 of file equityindex.cpp.

79{ return forecastFixing(fixingDate, false); }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ forecastFixing() [2/4]

Real forecastFixing ( const Time &  fixingTime) const
overridevirtual

returns the fixing at the given time

Implements EqFxIndexBase.

Definition at line 86 of file equityindex.cpp.

86{ return forecastFixing(fixingTime, false); }
+ Here is the call graph for this function:

◆ forecastFixing() [3/4]

Real forecastFixing ( const Date &  fixingDate,
bool  incDividend 
) const
virtual

Definition at line 81 of file equityindex.cpp.

81 {
82 QL_REQUIRE(!rate_.empty(), "null term structure set to this instance of " << name());
83 return forecastFixing(rate_->timeFromReference(fixingDate), incDividend);
84}
+ Here is the call graph for this function:

◆ forecastFixing() [4/4]

Real forecastFixing ( const Time &  fixingTime,
bool  incDividend 
) const
virtual

Definition at line 88 of file equityindex.cpp.

88 {
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());
91
92 // we base the forecast always on the spot quote (and not on today's fixing)
93 Real price = spotQuote_->value();
94
95 // compute the forecast applying the usual no arbitrage principle
96 Real forward;
97 if (incDividend) {
98 forward = price / rate_->discount(fixingTime);
99 } else {
100 forward = price * dividend_->discount(fixingTime) / rate_->discount(fixingTime);
101 }
102 return forward;
103}
+ Here is the call graph for this function:

◆ pastFixing()

Real pastFixing ( const Date &  fixingDate) const
overridevirtual

returns a past fixing at the given date

the date passed as arguments must be the actual calendar date of the fixing; no settlement days must be used.

Implements EqFxIndexBase.

Reimplemented in CompoEquityIndex.

Definition at line 115 of file equityindex.hpp.

115 {
116 QL_REQUIRE(isValidFixingDate(fixingDate), fixingDate << " is not a valid fixing date");
117 return timeSeries()[fixingDate];
118}
QuantLib::Date fixingDate(const QuantLib::Date &d, const QuantLib::Period obsLag, const QuantLib::Frequency freq, bool interpolated)
Definition: inflation.cpp:183
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clone()

QuantLib::ext::shared_ptr< EquityIndex2 > clone ( const Handle< Quote >  spotQuote,
const Handle< YieldTermStructure > &  rate,
const Handle< YieldTermStructure > &  dividend 
) const
virtual

Reimplemented in CompoEquityIndex.

Definition at line 137 of file equityindex.cpp.

138 {
139 return QuantLib::ext::make_shared<EquityIndex2>(familyName(), fixingCalendar(), currency(), spotQuote, rate, dividend);
140}
+ Here is the call graph for this function:

Member Data Documentation

◆ familyName_

std::string familyName_
protected

Definition at line 95 of file equityindex.hpp.

◆ currency_

Currency currency_
protected

Definition at line 96 of file equityindex.hpp.

◆ rate_

const Handle<YieldTermStructure> rate_
protected

Definition at line 97 of file equityindex.hpp.

◆ dividend_

const Handle<YieldTermStructure> dividend_
protected

Definition at line 97 of file equityindex.hpp.

◆ name_

std::string name_
protected

Definition at line 98 of file equityindex.hpp.

◆ spotQuote_

const Handle<Quote> spotQuote_
protected

Definition at line 99 of file equityindex.hpp.

◆ fixingCalendar_

Calendar fixingCalendar_
private

Definition at line 102 of file equityindex.hpp.