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

#include <ored/scripting/utilities.hpp>

+ Collaboration diagram for IndexInfo:

Public Member Functions

 IndexInfo (const std::string &name, const QuantLib::ext::shared_ptr< Market > &market=nullptr)
 
std::string name () const
 
bool isFx () const
 
bool isEq () const
 
bool isComm () const
 
bool isIr () const
 
bool isIrIbor () const
 
bool isIrSwap () const
 
bool isInf () const
 
bool isGeneric () const
 
QuantLib::ext::shared_ptr< FxIndexfx () const
 
QuantLib::ext::shared_ptr< EquityIndex2eq () const
 
QuantLib::ext::shared_ptr< QuantExt::CommodityIndexcomm (const Date &obsDate=Date()) const
 
QuantLib::ext::shared_ptr< InterestRateIndexir () const
 
QuantLib::ext::shared_ptr< IborIndexirIbor () const
 
QuantLib::ext::shared_ptr< FallbackIborIndexirIborFallback (const IborFallbackConfig &iborFallbackConfig, const Date &asof=QuantLib::Date::maxDate()) const
 
QuantLib::ext::shared_ptr< FallbackOvernightIndexirOvernightFallback (const IborFallbackConfig &iborFallbackConfig, const Date &asof=QuantLib::Date::maxDate()) const
 
QuantLib::ext::shared_ptr< SwapIndex > irSwap () const
 
QuantLib::ext::shared_ptr< ZeroInflationIndex > inf () const
 
QuantLib::ext::shared_ptr< Index > generic () const
 
QuantLib::ext::shared_ptr< Index > index (const Date &obsDate=Date()) const
 
std::string commName () const
 
std::string infName () const
 
bool operator== (const IndexInfo &j) const
 
bool operator!= (const IndexInfo &j) const
 
bool operator< (const IndexInfo &j) const
 
bool operator> (const IndexInfo &j) const
 
bool operator<= (const IndexInfo &j) const
 
bool operator>= (const IndexInfo &j) const
 

Private Attributes

std::string name_
 
QuantLib::ext::shared_ptr< Marketmarket_
 
bool isFx_
 
bool isEq_
 
bool isComm_
 
bool isIr_
 
bool isInf_
 
bool isIrIbor_
 
bool isIrSwap_
 
bool isGeneric_
 
QuantLib::ext::shared_ptr< FxIndexfx_
 
QuantLib::ext::shared_ptr< EquityIndex2eq_
 
QuantLib::ext::shared_ptr< InterestRateIndexir_
 
QuantLib::ext::shared_ptr< IborIndexirIbor_
 
QuantLib::ext::shared_ptr< SwapIndex > irSwap_
 
QuantLib::ext::shared_ptr< ZeroInflationIndex > inf_
 
QuantLib::ext::shared_ptr< Index > generic_
 
std::string commName_
 
std::string infName_
 

Detailed Description

Definition at line 93 of file utilities.hpp.

Constructor & Destructor Documentation

◆ IndexInfo()

IndexInfo ( const std::string &  name,
const QuantLib::ext::shared_ptr< Market > &  market = nullptr 
)
explicit

Definition at line 388 of file utilities.cpp.

388 : name_(name), market_(market) {
390 bool done = false;
391 // first handle the index types that we can recognise by a prefix
392 if (boost::starts_with(name, "COMM-")) {
393 // index will be created on the fly, since it depends on the obsDate in general
394 isComm_ = done = true;
395 std::vector<std::string> tokens;
396 boost::split(tokens, name, boost::is_any_of("#!"));
397 QL_REQUIRE(!tokens.empty(), "IndexInfo: no commodity name found for '" << name << "'");
398 commName_ = parseCommodityIndex(tokens.front())->underlyingName();
399 } else if (boost::starts_with(name, "FX-")) {
400 // parse fx index using conventions
401 fx_ = parseFxIndex(name, Handle<Quote>(), Handle<YieldTermStructure>(), Handle<YieldTermStructure>(), true);
402 isFx_ = done = true;
403 } else if (boost::starts_with(name, "EQ-")) {
405 if (market_ != nullptr) {
406 try {
407 eq_ = *market_->equityCurve(eq_->name());
408 } catch (...) {
409 }
410 }
411 isEq_ = done = true;
412 } else if (boost::starts_with(name, "GENERIC-")) {
414 isGeneric_ = done = true;
415 }
416 // no easy way to see if it is an Ibor index, so try and error
417 if (!done) {
418 try {
420 ir_ = irIbor_;
421 isIr_ = isIrIbor_ = done = true;
422 } catch (...) {
423 }
424 }
425 // same for swap
426 if (!done) {
427 try {
428 irSwap_ = parseSwapIndex(name, Handle<YieldTermStructure>(), Handle<YieldTermStructure>());
429 ir_ = irSwap_;
430 isIr_ = isIrSwap_ = done = true;
431 } catch (...) {
432 }
433 }
434 // and same for inflation
435 if (!done) {
436 try {
438 inf_ = res.first;
439 infName_ = res.second;
440 isInf_ = done = true;
441 } catch (...) {
442 }
443 }
444 QL_REQUIRE(done, "Could not build index info for '"
445 << name
446 << "', expected a valid COMM, FX, EQ, GENERIC, Ibor, Swap, Inflation index identifier.");
447}
QuantLib::ext::shared_ptr< Market > market_
Definition: utilities.hpp:142
QuantLib::ext::shared_ptr< ZeroInflationIndex > inf_
Definition: utilities.hpp:149
std::string name() const
Definition: utilities.hpp:98
QuantLib::ext::shared_ptr< IborIndex > irIbor_
Definition: utilities.hpp:147
QuantLib::ext::shared_ptr< FxIndex > fx_
Definition: utilities.hpp:144
std::string infName_
Definition: utilities.hpp:151
QuantLib::ext::shared_ptr< InterestRateIndex > ir_
Definition: utilities.hpp:146
QuantLib::ext::shared_ptr< EquityIndex2 > eq_
Definition: utilities.hpp:145
QuantLib::ext::shared_ptr< SwapIndex > irSwap_
Definition: utilities.hpp:148
std::string commName_
Definition: utilities.hpp:151
QuantLib::ext::shared_ptr< Index > generic_
Definition: utilities.hpp:150
QuantLib::ext::shared_ptr< SwapIndex > parseSwapIndex(const string &s, const Handle< YieldTermStructure > &f, const Handle< YieldTermStructure > &d)
Convert std::string to QuantLib::SwapIndex.
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > parseEquityIndex(const string &s)
Convert std::string (e.g SP5) to QuantExt::EquityIndex.
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
QuantLib::ext::shared_ptr< QuantLib::Index > parseGenericIndex(const string &s)
Convert std::string (GENERIC-...) to QuantExt::Index.
QL_DEPRECATED_DISABLE_WARNING std::pair< QuantLib::ext::shared_ptr< QuantLib::ZeroInflationIndex >, std::string > parseScriptedInflationIndex(const std::string &indexName)
Definition: utilities.cpp:593
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > parseCommodityIndex(const string &name, bool hasPrefix, const Handle< PriceTermStructure > &ts, const Calendar &cal, const bool enforceFutureIndex)
+ Here is the call graph for this function:

Member Function Documentation

◆ name()

std::string name ( ) const

Definition at line 98 of file utilities.hpp.

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

◆ isFx()

bool isFx ( ) const

Definition at line 100 of file utilities.hpp.

100{ return isFx_; }
+ Here is the caller graph for this function:

◆ isEq()

bool isEq ( ) const

Definition at line 101 of file utilities.hpp.

101{ return isEq_; }
+ Here is the caller graph for this function:

◆ isComm()

bool isComm ( ) const

Definition at line 102 of file utilities.hpp.

102{ return isComm_; }
+ Here is the caller graph for this function:

◆ isIr()

bool isIr ( ) const

Definition at line 103 of file utilities.hpp.

103{ return isIr_; }
+ Here is the caller graph for this function:

◆ isIrIbor()

bool isIrIbor ( ) const

Definition at line 104 of file utilities.hpp.

104{ return isIrIbor_; }
+ Here is the caller graph for this function:

◆ isIrSwap()

bool isIrSwap ( ) const

Definition at line 105 of file utilities.hpp.

105{ return isIrSwap_; }
+ Here is the caller graph for this function:

◆ isInf()

bool isInf ( ) const

Definition at line 106 of file utilities.hpp.

106{ return isInf_; }
+ Here is the caller graph for this function:

◆ isGeneric()

bool isGeneric ( ) const

Definition at line 107 of file utilities.hpp.

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

◆ fx()

QuantLib::ext::shared_ptr< FxIndex > fx ( ) const

Definition at line 109 of file utilities.hpp.

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

◆ eq()

QuantLib::ext::shared_ptr< EquityIndex2 > eq ( ) const

Definition at line 110 of file utilities.hpp.

110{ return eq_; }
+ Here is the caller graph for this function:

◆ comm()

QuantLib::ext::shared_ptr< CommodityIndex > comm ( const Date &  obsDate = Date()) const

Definition at line 467 of file utilities.cpp.

467 {
468 if (isComm())
469 return parseScriptedCommodityIndex(name(), obsDate);
470 else
471 return nullptr;
472}
bool isComm() const
Definition: utilities.hpp:102
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > parseScriptedCommodityIndex(const std::string &indexName, const QuantLib::Date &obsDate)
Definition: utilities.cpp:530
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ir()

QuantLib::ext::shared_ptr< InterestRateIndex > ir ( ) const

Definition at line 114 of file utilities.hpp.

114{ return ir_; }
+ Here is the caller graph for this function:

◆ irIbor()

QuantLib::ext::shared_ptr< IborIndex > irIbor ( ) const

Definition at line 115 of file utilities.hpp.

115{ return irIbor_; }
+ Here is the caller graph for this function:

◆ irIborFallback()

QuantLib::ext::shared_ptr< FallbackIborIndex > irIborFallback ( const IborFallbackConfig iborFallbackConfig,
const Date &  asof = QuantLib::Date::maxDate() 
) const

Definition at line 501 of file utilities.cpp.

502 {
503 if (isIrIbor_ && iborFallbackConfig.isIndexReplaced(name_, asof)) {
504 auto data = iborFallbackConfig.fallbackData(name_);
505 // we don't support convention based rfr fallback indices, with ore ticket 1758 this might change
506 auto on = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(parseIborIndex(data.rfrIndex));
507 QL_REQUIRE(on, "IndexInfo::irIborFallback(): could not cast rfr index '"
508 << data.rfrIndex << "' for ibor fallback index '" << name_ << "' to an overnight index");
509 return QuantLib::ext::make_shared<FallbackIborIndex>(irIbor_, on, data.spread, data.switchDate, false);
510 }
511 return nullptr;
512}
@ data
Definition: log.hpp:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ irOvernightFallback()

QuantLib::ext::shared_ptr< FallbackOvernightIndex > irOvernightFallback ( const IborFallbackConfig iborFallbackConfig,
const Date &  asof = QuantLib::Date::maxDate() 
) const

Definition at line 514 of file utilities.cpp.

515 {
516 if (isIrIbor_ && iborFallbackConfig.isIndexReplaced(name_, asof)) {
517 auto data = iborFallbackConfig.fallbackData(name_);
518 // we don't support convention based rfr fallback indices, with ore ticket 1758 this might change
519 auto on = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(parseIborIndex(data.rfrIndex));
520 QL_REQUIRE(on, "IndexInfo::irIborFallback(): could not cast rfr index '"
521 << data.rfrIndex << "' for ibor fallback index '" << name_ << "' to an overnight index");
522 if (auto original = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(irIbor_))
523 return QuantLib::ext::make_shared<FallbackOvernightIndex>(original, on, data.spread, data.switchDate, false);
524 else
525 return nullptr;
526 }
527 return nullptr;
528}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ irSwap()

QuantLib::ext::shared_ptr< SwapIndex > irSwap ( ) const

Definition at line 122 of file utilities.hpp.

122{ return irSwap_; }
+ Here is the caller graph for this function:

◆ inf()

QuantLib::ext::shared_ptr< ZeroInflationIndex > inf ( ) const

Definition at line 123 of file utilities.hpp.

123{ return inf_; }
+ Here is the caller graph for this function:

◆ generic()

QuantLib::ext::shared_ptr< Index > generic ( ) const

Definition at line 124 of file utilities.hpp.

124{ return generic_; }
+ Here is the caller graph for this function:

◆ index()

QuantLib::ext::shared_ptr< Index > index ( const Date &  obsDate = Date()) const

Definition at line 449 of file utilities.cpp.

449 {
450 if (isFx_)
451 return fx_;
452 else if (isEq_)
453 return eq_;
454 else if (isIr_)
455 return ir_;
456 else if (isInf_)
457 return inf_;
458 else if (isGeneric_)
459 return generic_;
460 else if (isComm_) {
461 return comm(obsDate);
462 } else {
463 QL_FAIL("could not parse index '" << name_ << "'");
464 }
465}
QuantLib::ext::shared_ptr< QuantExt::CommodityIndex > comm(const Date &obsDate=Date()) const
Definition: utilities.cpp:467
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commName()

std::string commName ( ) const

Definition at line 474 of file utilities.cpp.

474 {
475 QL_REQUIRE(isComm(), "IndexInfo::commName(): commodity index required, got " << *this);
476 return commName_;
477}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ infName()

std::string infName ( ) const

Definition at line 479 of file utilities.cpp.

479 {
480 QL_REQUIRE(isInf(), "IndexInfo::infName(): inflation index required, got " << *this);
481 return infName_;
482}
bool isInf() const
Definition: utilities.hpp:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator==()

bool operator== ( const IndexInfo j) const

Definition at line 133 of file utilities.hpp.

133{ return name() == j.name(); }
+ Here is the call graph for this function:

◆ operator!=()

bool operator!= ( const IndexInfo j) const

Definition at line 134 of file utilities.hpp.

134{ return !(*this == j); }

◆ operator<()

bool operator< ( const IndexInfo j) const

Definition at line 135 of file utilities.hpp.

135{ return name() < j.name(); }
+ Here is the call graph for this function:

◆ operator>()

bool operator> ( const IndexInfo j) const

Definition at line 136 of file utilities.hpp.

136{ return j < (*this); }

◆ operator<=()

bool operator<= ( const IndexInfo j) const

Definition at line 137 of file utilities.hpp.

137{ return !((*this) > j); }

◆ operator>=()

bool operator>= ( const IndexInfo j) const

Definition at line 138 of file utilities.hpp.

138{ return !((*this) < j); }

Member Data Documentation

◆ name_

std::string name_
private

Definition at line 141 of file utilities.hpp.

◆ market_

QuantLib::ext::shared_ptr<Market> market_
private

Definition at line 142 of file utilities.hpp.

◆ isFx_

bool isFx_
private

Definition at line 143 of file utilities.hpp.

◆ isEq_

bool isEq_
private

Definition at line 143 of file utilities.hpp.

◆ isComm_

bool isComm_
private

Definition at line 143 of file utilities.hpp.

◆ isIr_

bool isIr_
private

Definition at line 143 of file utilities.hpp.

◆ isInf_

bool isInf_
private

Definition at line 143 of file utilities.hpp.

◆ isIrIbor_

bool isIrIbor_
private

Definition at line 143 of file utilities.hpp.

◆ isIrSwap_

bool isIrSwap_
private

Definition at line 143 of file utilities.hpp.

◆ isGeneric_

bool isGeneric_
private

Definition at line 143 of file utilities.hpp.

◆ fx_

QuantLib::ext::shared_ptr<FxIndex> fx_
private

Definition at line 144 of file utilities.hpp.

◆ eq_

QuantLib::ext::shared_ptr<EquityIndex2> eq_
private

Definition at line 145 of file utilities.hpp.

◆ ir_

QuantLib::ext::shared_ptr<InterestRateIndex> ir_
private

Definition at line 146 of file utilities.hpp.

◆ irIbor_

QuantLib::ext::shared_ptr<IborIndex> irIbor_
private

Definition at line 147 of file utilities.hpp.

◆ irSwap_

QuantLib::ext::shared_ptr<SwapIndex> irSwap_
private

Definition at line 148 of file utilities.hpp.

◆ inf_

QuantLib::ext::shared_ptr<ZeroInflationIndex> inf_
private

Definition at line 149 of file utilities.hpp.

◆ generic_

QuantLib::ext::shared_ptr<Index> generic_
private

Definition at line 150 of file utilities.hpp.

◆ commName_

std::string commName_
private

Definition at line 151 of file utilities.hpp.

◆ infName_

std::string infName_
private

Definition at line 151 of file utilities.hpp.