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

Composite instrument More...

#include <qle/instruments/multiccycompositeinstrument.hpp>

+ Inheritance diagram for MultiCcyCompositeInstrument:
+ Collaboration diagram for MultiCcyCompositeInstrument:

Public Member Functions

void add (const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0, const Handle< Quote > &fx=Handle< Quote >(QuantLib::ext::make_shared< SimpleQuote >(1.0)))
 adds an instrument to the composite More...
 
void subtract (const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0, const Handle< Quote > &fx=Handle< Quote >(QuantLib::ext::make_shared< SimpleQuote >(1.0)))
 shorts an instrument from the composite More...
 
Observer interface
void deepUpdate () override
 

Private Types

typedef std::tuple< ext::shared_ptr< Instrument >, Real, Handle< Quote > > component
 
typedef std::list< component >::iterator iterator
 
typedef std::list< component >::const_iterator const_iterator
 

Instrument interface

std::list< componentcomponents_
 
bool isExpired () const override
 
void performCalculations () const override
 

Detailed Description

Composite instrument

This instrument is an aggregate of other instruments. Its NPV is the sum of the NPVs of its components, each possibly multiplied by a given factor, and an FX rate.

Warning:
Methods that drive the calculation directly (such as recalculate(), freeze() and others) might not work correctly.

Definition at line 46 of file multiccycompositeinstrument.hpp.

Member Typedef Documentation

◆ component

typedef std::tuple<ext::shared_ptr<Instrument>, Real, Handle<Quote> > component
private

Definition at line 47 of file multiccycompositeinstrument.hpp.

◆ iterator

typedef std::list<component>::iterator iterator
private

Definition at line 48 of file multiccycompositeinstrument.hpp.

◆ const_iterator

typedef std::list<component>::const_iterator const_iterator
private

Definition at line 49 of file multiccycompositeinstrument.hpp.

Member Function Documentation

◆ add()

void add ( const ext::shared_ptr< Instrument > &  instrument,
Real  multiplier = 1.0,
const Handle< Quote > &  fx = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0)) 
)

adds an instrument to the composite

Definition at line 24 of file multiccycompositeinstrument.cpp.

25 {
26 components_.push_back(std::make_tuple(instrument, multiplier, fx));
27 registerWith(instrument);
28 registerWith(fx);
29 update();
30 // When we ask for the NPV of an expired composite, the
31 // components are not recalculated and thus wouldn't forward
32 // later notifications according to the default behavior of
33 // LazyObject instances. This means that even if the
34 // evaluation date changes so that the composite is no longer
35 // expired, the instrument wouldn't be notified and thus it
36 // wouldn't recalculate. To avoid this, we override the
37 // default behavior of the components.
38 instrument->alwaysForwardNotifications();
39}
+ Here is the caller graph for this function:

◆ subtract()

void subtract ( const ext::shared_ptr< Instrument > &  instrument,
Real  multiplier = 1.0,
const Handle< Quote > &  fx = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0)) 
)

shorts an instrument from the composite

Definition at line 41 of file multiccycompositeinstrument.cpp.

42 {
43 add(instrument, -multiplier, fx);
44}
void add(const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0, const Handle< Quote > &fx=Handle< Quote >(QuantLib::ext::make_shared< SimpleQuote >(1.0)))
adds an instrument to the composite
+ Here is the call graph for this function:

◆ deepUpdate()

void deepUpdate ( )
override

Definition at line 69 of file multiccycompositeinstrument.cpp.

69 {
70 for (const_iterator i = components_.cbegin(); i != components_.end(); ++i) {
71 std::get<0>(*i)->deepUpdate();
72 }
73 update();
74}
std::list< component >::const_iterator const_iterator

◆ isExpired()

bool isExpired ( ) const
override

Definition at line 46 of file multiccycompositeinstrument.cpp.

46 {
47 for (const_iterator i = components_.cbegin(); i != components_.end(); ++i) {
48 if (!std::get<0>(*i)->isExpired())
49 return false;
50 }
51 return true;
52}

◆ performCalculations()

void performCalculations ( ) const
overrideprotected

Definition at line 54 of file multiccycompositeinstrument.cpp.

54 {
55 NPV_ = 0.0;
56 additionalResults_.clear();
57 Size counter = 0;
58 for (const_iterator i = components_.cbegin(); i != components_.end(); ++i, ++counter) {
59 // npv += npv * fx * multiplier
60 NPV_ += std::get<1>(*i) * std::get<2>(*i)->value() * std::get<0>(*i)->NPV();
61 for (auto const& k : std::get<0>(*i)->additionalResults()) {
62 additionalResults_[k.first + "_" + std::to_string(counter)] = k.second;
63 }
64 additionalResults_["__multiplier_" + std::to_string(counter)] = std::get<1>(*i);
65 additionalResults_["__fx_conversion_" + std::to_string(counter)] = std::get<2>(*i)->value();
66 }
67}

Member Data Documentation

◆ components_

std::list<component> components_
private

Definition at line 70 of file multiccycompositeinstrument.hpp.