QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Instrument Class Referenceabstract

Abstract instrument class. More...

#include <ql/instrument.hpp>

+ Inheritance diagram for Instrument:
+ Collaboration diagram for Instrument:

Classes

class  results
 

Public Member Functions

 Instrument ()
 
Inspectors
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 >
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...
 
virtual bool isExpired () const =0
 returns whether the instrument might have value greater than zero. More...
 
Modifiers
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 ()
 

Protected Member Functions

Calculations
void calculate () const override
 
virtual void setupExpired () const
 
void performCalculations () const override
 
- Protected Member Functions inherited from LazyObject

Protected Attributes

Results

The value of this attribute and any other that derived classes might declare must be set during calculation.

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_
 

Additional Inherited Members

- Public Types inherited from Observer
typedef set_type::iterator iterator
 

Detailed Description

Abstract instrument class.

This class is purely abstract and defines the interface of concrete instruments which will be derived from this one.

Tests:
observability of class instances is checked.

Definition at line 44 of file instrument.hpp.

Constructor & Destructor Documentation

◆ Instrument()

Definition at line 26 of file instrument.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ NPV()

Real NPV ( ) const

returns the net present value of the instrument.

Examples
Bonds.cpp, CDS.cpp, ConvertibleBonds.cpp, EquityOption.cpp, FRA.cpp, MulticurveBootstrapping.cpp, Replication.cpp, and Repo.cpp.

Definition at line 167 of file instrument.hpp.

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

◆ errorEstimate()

Real errorEstimate ( ) const

returns the error estimate on the NPV when available.

Definition at line 173 of file instrument.hpp.

+ Here is the call graph for this function:

◆ valuationDate()

const Date & valuationDate ( ) const

returns the date the net present value refers to.

Definition at line 180 of file instrument.hpp.

+ Here is the call graph for this function:

◆ result()

T result ( const std::string &  tag) const

returns any additional result returned by the pricing engine.

Definition at line 188 of file instrument.hpp.

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

◆ additionalResults()

const std::map< std::string, ext::any > & additionalResults ( ) const

returns all additional result returned by the pricing engine.

Definition at line 198 of file instrument.hpp.

+ Here is the call graph for this function:

◆ isExpired()

virtual bool isExpired ( ) const
pure virtual

◆ setPricingEngine()

void setPricingEngine ( const ext::shared_ptr< PricingEngine > &  e)

set the pricing engine to be used.

Warning:
calling this method will have no effects in case the performCalculation method was overridden in a derived class.
Examples
Bonds.cpp, CDS.cpp, ConvertibleBonds.cpp, EquityOption.cpp, MulticurveBootstrapping.cpp, and Replication.cpp.

Definition at line 35 of file instrument.cpp.

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

◆ setupArguments()

void setupArguments ( PricingEngine::arguments ) const
virtual

◆ fetchResults()

void fetchResults ( const PricingEngine::results r) const
virtual

When a derived result structure is defined for an instrument, this method should be overridden to read from it. This is mandatory in case a pricing engine is used.

Reimplemented in QuantoDoubleBarrierOption, CatBond, EnergyCommodity, CdsOption, NthToDefault, SyntheticCDO, EverestOption, IrregularSwap, AssetSwap, Bond, CPISwap, CreditDefaultSwap, FixedVsFloatingSwap, FloatFloatSwap, ForwardVanillaOption, MargrabeOption, MultiAssetOption, NonstandardSwap, OneAssetOption, QuantoBarrierOption, QuantoForwardVanillaOption, QuantoVanillaOption, Swap, VarianceSwap, and YearOnYearInflationSwap.

Definition at line 155 of file instrument.hpp.

+ Here is the caller graph for this function:

◆ calculate()

void calculate ( ) const
overrideprotectedvirtual

This method performs all needed calculations by calling the performCalculations method.

Warning:
Objects cache the results of the previous calculation. Such results will be returned upon later invocations of calculate. When the results depend on arguments which could change between invocations, the lazy object must register itself as observer of such objects for the calculations to be performed again when they change.
Warning:
Should this method be redefined in derived classes, LazyObject::calculate() should be called in the overriding method.

Reimplemented from LazyObject.

Definition at line 129 of file instrument.hpp.

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

◆ setupExpired()

void setupExpired ( ) const
protectedvirtual

This method must leave the instrument in a consistent state when the expiration condition is met.

Reimplemented in QuantoDoubleBarrierOption, CDO, CdsOption, NthToDefault, RiskyAssetSwap, SyntheticCDO, PathMultiAssetOption, IrregularSwap, AssetSwap, Bond, CPISwap, CreditDefaultSwap, FixedVsFloatingSwap, FloatFloatSwap, ForwardRateAgreement, MultiAssetOption, NonstandardSwap, OneAssetOption, QuantoBarrierOption, QuantoForwardVanillaOption, QuantoVanillaOption, Swap, VarianceSwap, and YearOnYearInflationSwap.

Definition at line 140 of file instrument.hpp.

+ Here is the caller graph for this function:

◆ 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.

Implements LazyObject.

Reimplemented in BondForward, CompositeInstrument, Forward, ForwardRateAgreement, OvernightIndexFuture, and Stock.

Definition at line 146 of file instrument.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ NPV_

Real NPV_
mutableprotected

Definition at line 106 of file instrument.hpp.

◆ errorEstimate_

Real errorEstimate_
protected

Definition at line 106 of file instrument.hpp.

◆ valuationDate_

Date valuationDate_
mutableprotected

Definition at line 107 of file instrument.hpp.

◆ additionalResults_

std::map<std::string, ext::any> additionalResults_
mutableprotected

Definition at line 108 of file instrument.hpp.

◆ engine_

ext::shared_ptr<PricingEngine> engine_
protected

Definition at line 110 of file instrument.hpp.