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

formula based index class More...

#include <qle/indexes/formulabasedindex.hpp>

+ Inheritance diagram for FormulaBasedIndex:
+ Collaboration diagram for FormulaBasedIndex:

Public Member Functions

 FormulaBasedIndex (const std::string &familyName, const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > &indices, const CompiledFormula &formula, const Calendar &fixingCalendar)
 
Date maturityDate (const Date &valueDate) const override
 
Rate forecastFixing (const Date &fixingDate) const override
 
Rate pastFixing (const Date &fixingDate) const override
 
bool allowsNativeFixings () override
 
const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > & indices () const
 
const CompiledFormulaformula () const
 

Private Attributes

const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > indices_
 
const CompiledFormula formula_
 

Detailed Description

formula based index class

The variables in the given formula must correspond to index vector, both w.r.t. size and position.

Warning:

Definition at line 48 of file formulabasedindex.hpp.

Constructor & Destructor Documentation

◆ FormulaBasedIndex()

FormulaBasedIndex ( const std::string &  familyName,
const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > &  indices,
const CompiledFormula formula,
const Calendar &  fixingCalendar 
)

Definition at line 25 of file formulabasedindex.cpp.

28 : InterestRateIndex(familyName, 0 * Days, indices.front()->fixingDays(), Currency(), fixingCalendar,
29 SimpleDayCounter()),
31
32 std::ostringstream name;
33 name << familyName << "(";
34 for (Size i = 0; i < indices_.size(); ++i) {
35 registerWith(indices_[i]);
36 name << indices_[i]->name();
37 if (i < indices_.size() - 1)
38 name << ", ";
39 }
40 name << ")";
41 name_ = name.str();
42} // FormulaBasedIndex
const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > & indices() const
const CompiledFormula formula_
const CompiledFormula & formula() const
const std::vector< QuantLib::ext::shared_ptr< InterestRateIndex > > indices_

Member Function Documentation

◆ maturityDate()

Date maturityDate ( const Date &  valueDate) const
override

Definition at line 54 of file formulabasedindex.hpp.

54 {
55 QL_FAIL("FormulaBasedIndex does not provide a single maturity date");
56 }

◆ forecastFixing()

Rate forecastFixing ( const Date &  fixingDate) const
override

Definition at line 44 of file formulabasedindex.cpp.

44 {
45 std::vector<Real> values;
46 for (auto const& i : indices_) {
47 // this also handles the case when one of indices has
48 // a historic fixing on the evaluation date
49 values.push_back(i->fixing(fixingDate, false));
50 }
51 return formula_(values.begin(), values.end());
52}

◆ pastFixing()

Rate pastFixing ( const Date &  fixingDate) const
override

Definition at line 54 of file formulabasedindex.cpp.

54 {
55 std::vector<Real> values;
56 for (auto const& i : indices_) {
57 Real f = i->pastFixing(fixingDate);
58 // if one of the fixings is missing, the fixing of the composed
59 // index is also missing, this is indicated by a null value
60 if (f == Null<Real>())
61 return Null<Real>();
62 values.push_back(f);
63 }
64 return formula_(values.begin(), values.end());
65}

◆ allowsNativeFixings()

bool allowsNativeFixings ( )
override

Definition at line 59 of file formulabasedindex.hpp.

59{ return false; }

◆ indices()

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

Definition at line 62 of file formulabasedindex.hpp.

62{ return indices_; }

◆ formula()

const CompiledFormula & formula ( ) const

Definition at line 63 of file formulabasedindex.hpp.

63{ return formula_; }

Member Data Documentation

◆ indices_

const std::vector<QuantLib::ext::shared_ptr<InterestRateIndex> > indices_
private

Definition at line 66 of file formulabasedindex.hpp.

◆ formula_

const CompiledFormula formula_
private

Definition at line 67 of file formulabasedindex.hpp.