diff --git a/ql/indexes/equityindex.cpp b/ql/indexes/equityindex.cpp index 525a97336f2..6304b9d724c 100644 --- a/ql/indexes/equityindex.cpp +++ b/ql/indexes/equityindex.cpp @@ -36,8 +36,22 @@ namespace QuantLib { Handle interest, Handle dividend, Handle 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 interest, + Handle dividend, + Handle 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_); @@ -95,6 +109,7 @@ namespace QuantLib { ext::shared_ptr EquityIndex::clone(const Handle& interest, const Handle& dividend, const Handle& spot) const { - return ext::make_shared(name(), fixingCalendar(), interest, dividend, spot); + return ext::make_shared(name(), fixingCalendar(), currency(), interest, + dividend, spot); } } \ No newline at end of file diff --git a/ql/indexes/equityindex.hpp b/ql/indexes/equityindex.hpp index 84a72ed0a02..fc8f8ddd2c5 100644 --- a/ql/indexes/equityindex.hpp +++ b/ql/indexes/equityindex.hpp @@ -62,6 +62,17 @@ namespace QuantLib { */ class EquityIndex : public Index, public Observer { public: + EquityIndex(std::string name, + Calendar fixingCalendar, + Currency currency, + Handle interest = {}, + Handle dividend = {}, + Handle 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 interest = {}, @@ -81,6 +92,8 @@ namespace QuantLib { //@} //! \name Inspectors //@{ + //! The index currency + Currency currency() const { return currency_; } //! the rate curve used to forecast fixings Handle equityInterestRateCurve() const { return interest_; } //! the dividend curve used to forecast fixings @@ -105,6 +118,7 @@ namespace QuantLib { private: std::string name_; Calendar fixingCalendar_; + Currency currency_; Handle interest_; Handle dividend_; Handle spot_; @@ -117,4 +131,4 @@ namespace QuantLib { inline void EquityIndex::update() { notifyObservers(); } } -#endif \ No newline at end of file +#endif diff --git a/test-suite/equitycashflow.cpp b/test-suite/equitycashflow.cpp index 9b7f19030c4..b672794ee63 100644 --- a/test-suite/equitycashflow.cpp +++ b/test-suite/equitycashflow.cpp @@ -19,6 +19,7 @@ #include "toplevelfixture.hpp" #include "utilities.hpp" #include +#include #include #include #include @@ -60,7 +61,7 @@ struct CommonVars { today = calendar.adjust(Date(27, January, 2023)); Settings::instance().evaluationDate() = today; - equityIndex = ext::make_shared("eqIndex", calendar, localCcyInterestHandle, + equityIndex = ext::make_shared("eqIndex", calendar, EURCurrency(), localCcyInterestHandle, dividendHandle, spotHandle); equityIndex->addFixing(Date(5, January, 2023), 9010.0); equityIndex->addFixing(today, 8690.0); @@ -121,7 +122,6 @@ void checkQuantoCorrection(bool includeDividend, bool bumpData = false) { const Real tolerance = 1.0e-6; CommonVars vars; - ext::shared_ptr equityIndex = includeDividend ? vars.equityIndex : diff --git a/test-suite/equityindex.cpp b/test-suite/equityindex.cpp index 1ada1fb5ded..5c2885b98c1 100644 --- a/test-suite/equityindex.cpp +++ b/test-suite/equityindex.cpp @@ -18,6 +18,7 @@ #include "toplevelfixture.hpp" #include "utilities.hpp" +#include #include #include #include @@ -48,7 +49,7 @@ struct CommonVars { calendar = TARGET(); dayCount = Actual365Fixed(); - equityIndex = ext::make_shared("eqIndex", calendar, interestHandle, + equityIndex = ext::make_shared("eqIndex", calendar, EURCurrency(), interestHandle, dividendHandle, spotHandle); today = calendar.adjust(Date(27, January, 2023)); @@ -247,14 +248,14 @@ BOOST_AUTO_TEST_CASE(testFixingObservability) { CommonVars vars; ext::shared_ptr i1 = - ext::make_shared("observableEquityIndex", vars.calendar); + ext::make_shared("observableEquityIndex", vars.calendar, EURCurrency()); Flag flag; flag.registerWith(i1); flag.lower(); ext::shared_ptr i2 = - ext::make_shared("observableEquityIndex", vars.calendar); + ext::make_shared("observableEquityIndex", vars.calendar, EURCurrency()); i2->addFixing(vars.today, 100.0); if (!flag.isUp()) diff --git a/test-suite/equitytotalreturnswap.cpp b/test-suite/equitytotalreturnswap.cpp index 8611e1e0121..da1e29786f5 100644 --- a/test-suite/equitytotalreturnswap.cpp +++ b/test-suite/equitytotalreturnswap.cpp @@ -19,13 +19,13 @@ #include "toplevelfixture.hpp" #include "utilities.hpp" #include +#include #include #include #include -#include +#include #include #include - #include using namespace QuantLib; @@ -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("eqIndex", calendar, interestHandle, + equityIndex = ext::make_shared("eqIndex", calendar, USDCurrency(), interestHandle, dividendHandle, spotHandle); equityIndex->addFixing(Date(5, January, 2023), 9010.0); equityIndex->addFixing(today, 8690.0);