Skip to content

Commit

Permalink
Add Currency information to EquityIndex (#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Jul 25, 2024
2 parents 1b9bef1 + 90e04cc commit c75f65f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
19 changes: 17 additions & 2 deletions ql/indexes/equityindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,22 @@ namespace QuantLib {
Handle<YieldTermStructure> interest,
Handle<YieldTermStructure> dividend,
Handle<Quote> spot)
: EquityIndex(std::move(name),
std::move(fixingCalendar),
Currency(),
std::move(interest),
std::move(dividend),
std::move(spot)) {}

EquityIndex::EquityIndex(std::string name,
Calendar fixingCalendar,
Currency currency,
Handle<YieldTermStructure> interest,
Handle<YieldTermStructure> dividend,
Handle<Quote> spot)
: name_(std::move(name)), fixingCalendar_(std::move(fixingCalendar)),
interest_(std::move(interest)), dividend_(std::move(dividend)), spot_(std::move(spot)) {
currency_(std::move(currency)), interest_(std::move(interest)),
dividend_(std::move(dividend)), spot_(std::move(spot)) {

registerWith(interest_);
registerWith(dividend_);
Expand Down Expand Up @@ -95,6 +109,7 @@ namespace QuantLib {
ext::shared_ptr<EquityIndex> EquityIndex::clone(const Handle<YieldTermStructure>& interest,
const Handle<YieldTermStructure>& dividend,
const Handle<Quote>& spot) const {
return ext::make_shared<EquityIndex>(name(), fixingCalendar(), interest, dividend, spot);
return ext::make_shared<EquityIndex>(name(), fixingCalendar(), currency(), interest,
dividend, spot);
}
}
16 changes: 15 additions & 1 deletion ql/indexes/equityindex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ namespace QuantLib {
*/
class EquityIndex : public Index, public Observer {
public:
EquityIndex(std::string name,
Calendar fixingCalendar,
Currency currency,
Handle<YieldTermStructure> interest = {},
Handle<YieldTermStructure> dividend = {},
Handle<Quote> spot = {});

/*! \deprecated Use the constructor taking a currency.
Deprecated in version 1.36.
*/
[[deprecated("Use the constructor taking a currency")]]
EquityIndex(std::string name,
Calendar fixingCalendar,
Handle<YieldTermStructure> interest = {},
Expand All @@ -81,6 +92,8 @@ namespace QuantLib {
//@}
//! \name Inspectors
//@{
//! The index currency
Currency currency() const { return currency_; }
//! the rate curve used to forecast fixings
Handle<YieldTermStructure> equityInterestRateCurve() const { return interest_; }
//! the dividend curve used to forecast fixings
Expand All @@ -105,6 +118,7 @@ namespace QuantLib {
private:
std::string name_;
Calendar fixingCalendar_;
Currency currency_;
Handle<YieldTermStructure> interest_;
Handle<YieldTermStructure> dividend_;
Handle<Quote> spot_;
Expand All @@ -117,4 +131,4 @@ namespace QuantLib {
inline void EquityIndex::update() { notifyObservers(); }
}

#endif
#endif
4 changes: 2 additions & 2 deletions test-suite/equitycashflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <ql/cashflows/equitycashflow.hpp>
#include <ql/currencies/europe.hpp>
#include <ql/indexes/equityindex.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/quotes/simplequote.hpp>
Expand Down Expand Up @@ -60,7 +61,7 @@ struct CommonVars {
today = calendar.adjust(Date(27, January, 2023));
Settings::instance().evaluationDate() = today;

equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, localCcyInterestHandle,
equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, EURCurrency(), localCcyInterestHandle,
dividendHandle, spotHandle);
equityIndex->addFixing(Date(5, January, 2023), 9010.0);
equityIndex->addFixing(today, 8690.0);
Expand Down Expand Up @@ -121,7 +122,6 @@ void checkQuantoCorrection(bool includeDividend, bool bumpData = false) {
const Real tolerance = 1.0e-6;

CommonVars vars;

ext::shared_ptr<EquityIndex> equityIndex =
includeDividend ?
vars.equityIndex :
Expand Down
7 changes: 4 additions & 3 deletions test-suite/equityindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <ql/currencies/europe.hpp>
#include <ql/indexes/equityindex.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/quotes/simplequote.hpp>
Expand Down Expand Up @@ -48,7 +49,7 @@ struct CommonVars {
calendar = TARGET();
dayCount = Actual365Fixed();

equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, interestHandle,
equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, EURCurrency(), interestHandle,
dividendHandle, spotHandle);

today = calendar.adjust(Date(27, January, 2023));
Expand Down Expand Up @@ -247,14 +248,14 @@ BOOST_AUTO_TEST_CASE(testFixingObservability) {
CommonVars vars;

ext::shared_ptr<EquityIndex> i1 =
ext::make_shared<EquityIndex>("observableEquityIndex", vars.calendar);
ext::make_shared<EquityIndex>("observableEquityIndex", vars.calendar, EURCurrency());

Flag flag;
flag.registerWith(i1);
flag.lower();

ext::shared_ptr<Index> i2 =
ext::make_shared<EquityIndex>("observableEquityIndex", vars.calendar);
ext::make_shared<EquityIndex>("observableEquityIndex", vars.calendar, EURCurrency());

i2->addFixing(vars.today, 100.0);
if (!flag.isUp())
Expand Down
8 changes: 4 additions & 4 deletions test-suite/equitytotalreturnswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include "toplevelfixture.hpp"
#include "utilities.hpp"
#include <ql/instruments/equitytotalreturnswap.hpp>
#include <ql/currencies/america.hpp>
#include <ql/indexes/equityindex.hpp>
#include <ql/indexes/ibor/sofr.hpp>
#include <ql/indexes/ibor/usdlibor.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/pricingengines/swap/discountingswapengine.hpp>

#include <string>

using namespace QuantLib;
Expand Down Expand Up @@ -53,13 +53,13 @@ struct CommonVars {
// utilities

CommonVars() {
calendar = TARGET();
calendar = UnitedStates(UnitedStates::GovernmentBond);
dayCount = Actual365Fixed();

today = calendar.adjust(Date(27, January, 2023));
Settings::instance().evaluationDate() = today;

equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, interestHandle,
equityIndex = ext::make_shared<EquityIndex>("eqIndex", calendar, USDCurrency(), interestHandle,
dividendHandle, spotHandle);
equityIndex->addFixing(Date(5, January, 2023), 9010.0);
equityIndex->addFixing(today, 8690.0);
Expand Down

0 comments on commit c75f65f

Please sign in to comment.