QuantLib_LazyObject man page

LazyObject — Framework for calculation on demand and result caching.  


#include <ql/patterns/lazyobject.hpp>

Inherits Observable, and Observer.

Inherited by AbcdAtmVolCurve, Basket, CalibrationHelper, CapFloorTermVolCurve, CapFloorTermVolSurface, CmsMarket, EurodollarFuturesImpliedStdDevQuote, Fdm1DimSolver, Fdm2dBlackScholesSolver, Fdm2DimSolver, Fdm3DimSolver, FdmBatesSolver, FdmBlackScholesSolver, FdmExtOUJumpSolver, FdmG2Solver, FdmHestonHullWhiteSolver, FdmHestonSolver, FdmHullWhiteSolver, FdmKlugeExtOUSolver< N >, FdmNdimSolver< N >, FdmSimple2dBSSolver, FdmSimple2dExtOUSolver, FdmSimple3dExtOUJumpSolver, FittedBondDiscountCurve, FlatForward, ForwardSwapQuote, Gaussian1dModel, HestonSLVFDMModel, HestonSLVMCModel, ImpliedStdDevQuote, Instrument, InterpolatedSmileSection< Interpolator >, LocalVolRNDCalculator, MultiCurveSensitivities, NoArbSabrInterpolatedSmileSection, NormalCLVModel, OneFactorCopula, PiecewiseDefaultCurve< Traits, Interpolator, Bootstrap >, PiecewiseYieldCurve< Traits, Interpolator, Bootstrap >, PiecewiseYoYInflationCurve< Interpolator, Bootstrap, Traits >, PiecewiseYoYOptionletVolatilityCurve< Interpolator, Bootstrap, Traits >, PiecewiseZeroInflationCurve< Interpolator, Bootstrap, Traits >, RandomLM< derivedRandomLM, copulaPolicy, USNG > [virtual], RendistatoCalculator [private], SabrInterpolatedSmileSection, SquareRootCLVModel, StrippedOptionletAdapter, StrippedOptionletBase, SviInterpolatedSmileSection, SwaptionVolatilityDiscrete, ZabrInterpolatedSmileSection< Evaluation >, RandomLM< RandomDefaultLM, copulaPolicy, USNG > [virtual], and RandomLM< RandomLossLM, copulaPolicy, USNG > [virtual].

Public Member Functions

Observer interface

void update ()

Protected Attributes

bool calculated_
bool frozen_
bool alwaysForward_


These methods do not modify the structure of the object and are therefore declared as const. Data members which will be calculated on demand need to be declared as mutable.

void recalculate ()
void freeze ()
void unfreeze ()
void alwaysForwardNotifications ()
virtual void calculate () const
virtual void performCalculations () const =0

Additional Inherited Members

Detailed Description

Framework for calculation on demand and result caching.

Member Function Documentation

void update () [virtual]

This method must be implemented in derived classes. An instance of Observer does not call this method directly: instead, it will be called by the observables the instance registered with when they need to notify any changes.

Implements Observer.

Reimplemented in PiecewiseYieldCurve< Traits, Interpolator, Bootstrap >, PiecewiseDefaultCurve< Traits, Interpolator, Bootstrap >, FittedBondDiscountCurve, RandomLM< RandomDefaultLM, copulaPolicy, USNG >, RandomLM< RandomLossLM, copulaPolicy, USNG >, PiecewiseYoYInflationCurve< Interpolator, Bootstrap, Traits >, CapFloorTermVolCurve, CapFloorTermVolSurface, PiecewiseZeroInflationCurve< Interpolator, Bootstrap, Traits >, FlatForward, StrippedOptionletAdapter, CmsMarket, and ForwardSwapQuote.

void recalculate ()

This method force the recalculation of any results which would otherwise be cached. It is not declared as const since it needs to call the non-const notifyObservers method.


Explicit invocation of this method is not necessary if the object registered itself as observer with the structures on which such results depend. It is strongly advised to follow this policy when possible.

void freeze ()

This method constrains the object to return the presently cached results on successive invocations, even if arguments upon which they depend should change.

void unfreeze ()

This method reverts the effect of the freeze method, thus re-enabling recalculations.

void alwaysForwardNotifications ()

This method causes the object to forward all notifications, even when not calculated. The default behavior is to forward the first notification received, and discard the others until recalculated; the rationale is that observers were already notified, and don't need further notification until they recalculate, at which point this object would be recalculated too. After recalculation, this object would again forward the first notification received.


Forwarding all notifications will cause a performance hit, and should be used only when discarding notifications cause an incorrect behavior.

void calculate () const [protected], [virtual]

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


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.


Should this method be redefined in derived classes, LazyObject::calculate() should be called in the overriding method.

Reimplemented in Instrument.

virtual void performCalculations () const [protected], [pure virtual]

This method must implement any calculations which must be (re)done in order to calculate the desired results.

Implemented in MarkovFunctional, Gaussian1dModel, Gsr, FixedRateBondForward, Forward, RandomLM< derivedRandomLM, copulaPolicy, USNG >, RandomLM< RandomDefaultLM, copulaPolicy, USNG >, RandomLM< RandomLossLM, copulaPolicy, USNG >, SwaptionVolatilityMatrix, Instrument, CapFloorTermVolCurve, CapFloorTermVolSurface, SwaptionVolatilityCube, RiskyBond, AbcdAtmVolCurve, ConvertibleBond, OptionletStripper1, CompositeInstrument, EnergyVanillaSwap, EnergyBasisSwap, HestonSLVMCModel, StrippedOptionletAdapter, HestonModelHelper, CalibrationHelper, OptionletStripper2, ForwardSwapQuote, EurodollarFuturesImpliedStdDevQuote, ImpliedStdDevQuote, EnergyFuture, and Stock.


Generated automatically by Doxygen for QuantLib from the source code.

Referenced By

The man pages alwaysForward_(3), alwaysForwardNotifications(3), calculated_(3), freeze(3), frozen_(3), recalculate(3) and unfreeze(3) are aliases of QuantLib_LazyObject(3).

Wed Feb 7 2018 Version 1.10.1 QuantLib