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

Delta Scenario class. More...

#include <orea/scenario/deltascenario.hpp>

+ Inheritance diagram for DeltaScenario:
+ Collaboration diagram for DeltaScenario:

Public Member Functions

 DeltaScenario ()
 Constructor. More...
 
 DeltaScenario (const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &baseScenario, const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &incrementalScenario)
 Constructor. More...
 
const Date & asof () const override
 Return the scenario asof date. More...
 
void setAsof (const Date &d) override
 Set the asof date. More...
 
const std::string & label () const override
 Return the scenario label. More...
 
void label (const string &s) override
 set the label More...
 
Real getNumeraire () const override
 Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]. More...
 
void setNumeraire (Real n) override
 Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]. More...
 
bool has (const ore::analytics::RiskFactorKey &key) const override
 Check, get, add a single market point. More...
 
const std::vector< ore::analytics::RiskFactorKey > & keys () const override
 Risk factor keys for which this scenario provides data. More...
 
void add (const ore::analytics::RiskFactorKey &key, Real value) override
 Add an element to the scenario. More...
 
Real get (const ore::analytics::RiskFactorKey &key) const override
 Get an element from the scenario. More...
 
bool isAbsolute () const override
 Is this an absolute or difference scenario? More...
 
void setAbsolute (const bool b) override
 Set if this is an absolute scenario. More...
 
const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates () const override
 Get coordinates. More...
 
QuantLib::ext::shared_ptr< Scenariobase () const
 Get base. More...
 
QuantLib::ext::shared_ptr< Scenariodelta () const
 Get delta. More...
 
QuantLib::ext::shared_ptr< Scenarioclone () const override
 clones a scenario and returns a pointer to the new object More...
 
bool isCloseEnough (const QuantLib::ext::shared_ptr< Scenario > &s) const override
 checks for equality up to numerical differences More...
 
- Public Member Functions inherited from Scenario
virtual ~Scenario ()
 Destructor. More...
 
virtual const Date & asof () const =0
 Return the scenario asof date. More...
 
virtual void setAsof (const Date &d)=0
 Set the asof date. More...
 
virtual const string & label () const =0
 Get the scenario label. More...
 
virtual void label (const string &)=0
 Set the scenario label. More...
 
virtual Real getNumeraire () const =0
 Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]. More...
 
virtual void setNumeraire (Real n)=0
 Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ]. More...
 
virtual bool has (const RiskFactorKey &key) const =0
 Check whether this scenario provides the data for the given key. More...
 
virtual const std::vector< RiskFactorKey > & keys () const =0
 Risk factor keys for which this scenario provides data. More...
 
virtual void add (const RiskFactorKey &key, Real value)=0
 Add an element to the scenario. More...
 
virtual Real get (const RiskFactorKey &key) const =0
 Get an element from the scenario. More...
 
virtual bool isAbsolute () const =0
 Is this an absolute or difference scenario? More...
 
virtual void setAbsolute (const bool b)=0
 Set if this is an absolute scenario. More...
 
virtual const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates () const =0
 Get coordinates. More...
 
virtual QuantLib::ext::shared_ptr< Scenarioclone () const =0
 clones a scenario and returns a pointer to the new object More...
 
virtual bool isCloseEnough (const QuantLib::ext::shared_ptr< Scenario > &s) const
 checks for equality up to numerical differences More...
 
virtual std::size_t keysHash () const
 return fingerprint identifying the set of rf keys of the scenarios, or 0 if not provided by the implementation More...
 

Protected Attributes

QuantLib::ext::shared_ptr< ScenariobaseScenario_
 
QuantLib::ext::shared_ptr< Scenariodelta_
 

Detailed Description

Delta Scenario class.

This implementation stores a pointer to a "base scenario", as well as a smaller "delta" scenario, which stores values for any keys where the value is different to base. This is intended as an efficient storage mechanism for e.g. sensitivity scenarios, where many scenario instances are managed in memory but the actual differences are minor.

Definition at line 41 of file deltascenario.hpp.

Constructor & Destructor Documentation

◆ DeltaScenario() [1/2]

Constructor.

Definition at line 44 of file deltascenario.hpp.

44{}

◆ DeltaScenario() [2/2]

DeltaScenario ( const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &  baseScenario,
const QuantLib::ext::shared_ptr< ore::analytics::Scenario > &  incrementalScenario 
)

Constructor.

Definition at line 28 of file deltascenario.cpp.

30 : baseScenario_(baseScenario), delta_(incrementalScenario) {
31 QL_REQUIRE(
32 baseScenario->isAbsolute() == incrementalScenario->isAbsolute(),
33 "DeltaScenario(): base and incremental scenario must be both absolute or both difference, got isAbsolute = "
34 << std::boolalpha << baseScenario->isAbsolute() << ", " << incrementalScenario->isAbsolute());
35}
QuantLib::ext::shared_ptr< Scenario > baseScenario_
QuantLib::ext::shared_ptr< Scenario > delta_

Member Function Documentation

◆ asof()

const Date & asof ( ) const
overridevirtual

Return the scenario asof date.

Implements Scenario.

Definition at line 49 of file deltascenario.hpp.

49{ return delta_->asof(); }

◆ setAsof()

void setAsof ( const Date &  d)
overridevirtual

Set the asof date.

Implements Scenario.

Definition at line 50 of file deltascenario.hpp.

50{ delta_->setAsof(d); }

◆ label() [1/2]

const std::string & label ( ) const
overridevirtual

Return the scenario label.

Implements Scenario.

Definition at line 53 of file deltascenario.hpp.

53{ return delta_->label(); }

◆ label() [2/2]

void label ( const string &  s)
overridevirtual

set the label

Implements Scenario.

Definition at line 55 of file deltascenario.hpp.

55{ delta_->label(s); }

◆ getNumeraire()

Real getNumeraire ( ) const
overridevirtual

Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].

Implements Scenario.

Definition at line 57 of file deltascenario.cpp.

57 {
58 Real deltaNum = delta_->getNumeraire();
59 if (deltaNum == 0.0)
60 deltaNum = baseScenario_->getNumeraire();
61 return deltaNum;
62}

◆ setNumeraire()

void setNumeraire ( Real  n)
overridevirtual

Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].

Implements Scenario.

Definition at line 60 of file deltascenario.hpp.

60{ delta_->setNumeraire(n); }

◆ has()

bool has ( const ore::analytics::RiskFactorKey key) const
overridevirtual

Check, get, add a single market point.

Implements Scenario.

Definition at line 63 of file deltascenario.hpp.

63{ return baseScenario_->has(key); }

◆ keys()

const std::vector< ore::analytics::RiskFactorKey > & keys ( ) const
overridevirtual

Risk factor keys for which this scenario provides data.

Implements Scenario.

Definition at line 64 of file deltascenario.hpp.

64{ return baseScenario_->keys(); }

◆ add()

void add ( const ore::analytics::RiskFactorKey key,
Real  value 
)
overridevirtual

Add an element to the scenario.

Implements Scenario.

Definition at line 37 of file deltascenario.cpp.

37 {
38 QL_REQUIRE(baseScenario_->has(key), "base scenario must also possess key");
39 if (baseScenario_->get(key) != value)
40 delta_->add(key, value);
41}

◆ get()

Real get ( const ore::analytics::RiskFactorKey key) const
overridevirtual

Get an element from the scenario.

Implements Scenario.

Definition at line 43 of file deltascenario.cpp.

43 {
44 if (delta_->has(key)) {
45 return delta_->get(key);
46 } else {
47 return baseScenario_->get(key);
48 }
49}

◆ isAbsolute()

bool isAbsolute ( ) const
overridevirtual

Is this an absolute or difference scenario?

Implements Scenario.

Definition at line 68 of file deltascenario.hpp.

68{ return baseScenario_->isAbsolute(); }

◆ setAbsolute()

void setAbsolute ( const bool  b)
overridevirtual

Set if this is an absolute scenario.

Implements Scenario.

Definition at line 69 of file deltascenario.hpp.

69{ baseScenario_->setAbsolute(b); }

◆ coordinates()

const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates ( ) const
overridevirtual

Get coordinates.

Implements Scenario.

Definition at line 72 of file deltascenario.hpp.

72 {
73 return baseScenario_->coordinates();
74 }

◆ base()

QuantLib::ext::shared_ptr< Scenario > base ( ) const

Get base.

Definition at line 77 of file deltascenario.hpp.

77{ return baseScenario_; }

◆ delta()

QuantLib::ext::shared_ptr< Scenario > delta ( ) const

Get delta.

Definition at line 80 of file deltascenario.hpp.

80{ return delta_; }

◆ clone()

QuantLib::ext::shared_ptr< ore::analytics::Scenario > clone ( ) const
overridevirtual

clones a scenario and returns a pointer to the new object

Implements Scenario.

Definition at line 51 of file deltascenario.cpp.

51 {
52 // NOTE - we are not cloning the base here (is this appropriate?)
53 QuantLib::ext::shared_ptr<Scenario> newDelta = delta_->clone();
54 return QuantLib::ext::make_shared<DeltaScenario>(baseScenario_, newDelta);
55}

◆ isCloseEnough()

bool isCloseEnough ( const QuantLib::ext::shared_ptr< Scenario > &  s) const
overridevirtual

checks for equality up to numerical differences

Reimplemented from Scenario.

Definition at line 64 of file deltascenario.cpp.

64 {
65 if (auto d = QuantLib::ext::dynamic_pointer_cast<DeltaScenario>(s)) {
66 return (baseScenario_.get() == d->baseScenario_.get() || baseScenario_->isCloseEnough(s)) &&
67 (delta_.get() == d->delta_.get() || delta_->isCloseEnough(s));
68 } else {
70 }
71}
virtual bool isCloseEnough(const QuantLib::ext::shared_ptr< Scenario > &s) const
checks for equality up to numerical differences
Definition: scenario.cpp:38
+ Here is the call graph for this function:

Member Data Documentation

◆ baseScenario_

QuantLib::ext::shared_ptr<Scenario> baseScenario_
protected

Definition at line 87 of file deltascenario.hpp.

◆ delta_

QuantLib::ext::shared_ptr<Scenario> delta_
protected

Definition at line 88 of file deltascenario.hpp.