QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Member Functions | Private Types | List of all members
CompositeInstrument Class Reference

Composite instrument More...

#include <compositeinstrument.hpp>

+ Inheritance diagram for CompositeInstrument:
+ Collaboration diagram for CompositeInstrument:

Public Member Functions

void add (const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0)
 adds an instrument to the composite More...
 
void subtract (const ext::shared_ptr< Instrument > &instrument, Real multiplier=1.0)
 shorts an instrument from the composite More...
 
Observer interface
void deepUpdate () override
 
- Public Member Functions inherited from Instrument
 Instrument ()
 
Real NPV () const
 returns the net present value of the instrument. More...
 
Real errorEstimate () const
 returns the error estimate on the NPV when available. More...
 
const DatevaluationDate () const
 returns the date the net present value refers to. More...
 
template<typename T >
T result (const std::string &tag) const
 returns any additional result returned by the pricing engine. More...
 
const std::map< std::string, ext::any > & additionalResults () const
 returns all additional result returned by the pricing engine. More...
 
void setPricingEngine (const ext::shared_ptr< PricingEngine > &)
 set the pricing engine to be used. More...
 
virtual void setupArguments (PricingEngine::arguments *) const
 
virtual void fetchResults (const PricingEngine::results *) const
 
- Public Member Functions inherited from LazyObject
 LazyObject ()
 
 ~LazyObject () override=default
 
void update () override
 
bool isCalculated () const
 
void forwardFirstNotificationOnly ()
 
void alwaysForwardNotifications ()
 
void recalculate ()
 
void freeze ()
 
void unfreeze ()
 
- Public Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 
Observableoperator= (const Observable &)
 
 Observable (Observable &&)=delete
 
Observableoperator= (Observable &&)=delete
 
virtual ~Observable ()=default
 
void notifyObservers ()
 
- Public Member Functions inherited from Observer
 Observer ()=default
 
 Observer (const Observer &)
 
Observeroperator= (const Observer &)
 
virtual ~Observer ()
 
std::pair< iterator, boolregisterWith (const ext::shared_ptr< Observable > &)
 
void registerWithObservables (const ext::shared_ptr< Observer > &)
 
Size unregisterWith (const ext::shared_ptr< Observable > &)
 
void unregisterWithAll ()
 
virtual void update ()=0
 
virtual void deepUpdate ()
 

Private Types

typedef std::pair< ext::shared_ptr< Instrument >, Realcomponent
 
typedef std::list< component >::iterator iterator
 
typedef std::list< component >::const_iterator const_iterator
 

Instrument interface

std::list< componentcomponents_
 
bool isExpired () const override
 returns whether the instrument might have value greater than zero. More...
 
void performCalculations () const override
 

Additional Inherited Members

- Public Types inherited from Observer
typedef set_type::iterator iterator
 
- Protected Member Functions inherited from Instrument
void calculate () const override
 
virtual void setupExpired () const
 
- Protected Member Functions inherited from LazyObject
- Protected Attributes inherited from Instrument
Real NPV_
 
Real errorEstimate_
 
Date valuationDate_
 
std::map< std::string, ext::any > additionalResults_
 
ext::shared_ptr< PricingEngineengine_
 
- Protected Attributes inherited from LazyObject
bool calculated_ = false
 
bool frozen_ = false
 
bool alwaysForward_
 

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.

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

Definition at line 44 of file compositeinstrument.hpp.

Member Typedef Documentation

◆ component

typedef std::pair<ext::shared_ptr<Instrument>, Real> component
private

Definition at line 45 of file compositeinstrument.hpp.

◆ iterator

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

Definition at line 46 of file compositeinstrument.hpp.

◆ const_iterator

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

Definition at line 47 of file compositeinstrument.hpp.

Member Function Documentation

◆ add()

void add ( const ext::shared_ptr< Instrument > &  instrument,
Real  multiplier = 1.0 
)

adds an instrument to the composite

Examples
Replication.cpp.

Definition at line 24 of file compositeinstrument.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subtract()

void subtract ( const ext::shared_ptr< Instrument > &  instrument,
Real  multiplier = 1.0 
)

shorts an instrument from the composite

Examples
Replication.cpp.

Definition at line 40 of file compositeinstrument.cpp.

+ Here is the call graph for this function:

◆ deepUpdate()

void deepUpdate ( )
overridevirtual

This method allows to explicitly update the instance itself and nested observers. If notifications are disabled a call to this method ensures an update of such nested observers. It should be implemented in derived classes whenever applicable

Reimplemented from Observer.

Definition at line 60 of file compositeinstrument.cpp.

+ Here is the call graph for this function:

◆ isExpired()

bool isExpired ( ) const
overridevirtual

returns whether the instrument might have value greater than zero.

Implements Instrument.

Definition at line 45 of file compositeinstrument.cpp.

◆ performCalculations()

void performCalculations ( ) const
overrideprotectedvirtual

In case a pricing engine is not used, this method must be overridden to perform the actual calculations and set any needed results. In case a pricing engine is used, the default implementation can be used.

Reimplemented from Instrument.

Definition at line 53 of file compositeinstrument.cpp.

Member Data Documentation

◆ components_

std::list<component> components_
private

Definition at line 67 of file compositeinstrument.hpp.