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

#include <orea/scenario/simplescenario.hpp>

+ Inheritance diagram for SimpleScenario:
+ Collaboration diagram for SimpleScenario:

Classes

struct  SharedData
 

Public Member Functions

 SimpleScenario ()
 
 SimpleScenario (Date asof, const std::string &label=std::string(), Real numeraire=0, const boost::shared_ptr< SharedData > &sharedData=nullptr)
 if sharedData is not provided, the instance will create its own shared data block 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
 Get the scenario label. More...
 
void label (const string &s) override
 Set the scenario 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 isAbsolute () const override
 Is this an absolute or difference scenario? More...
 
const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates () const override
 Get coordinates. More...
 
std::size_t keysHash () const override
 return fingerprint identifying the set of rf keys of the scenarios, or 0 if not provided by the implementation More...
 
bool has (const RiskFactorKey &key) const override
 Check whether this scenario provides the data for the given key. More...
 
const std::vector< RiskFactorKey > & keys () const override
 Risk factor keys for which this scenario provides data. More...
 
void add (const RiskFactorKey &key, Real value) override
 Add an element to the scenario. More...
 
Real get (const RiskFactorKey &key) const override
 Get an element from the scenario. More...
 
QuantLib::ext::shared_ptr< Scenarioclone () const override
 This does not close the shared data. More...
 
void setAbsolute (const bool isAbsolute) override
 Set if this is an absolute scenario. More...
 
void setCoordinates (const RiskFactorKey::KeyType type, const std::string &name, const std::vector< std::vector< Real > > &coordinates)
 
const boost::shared_ptr< SharedData > & sharedData () const
 get shared data block (for construction of sister scenarios) More...
 
const std::vector< Real > & data () const
 get data, order is the same as in keys() 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...
 

Private Attributes

QuantLib::ext::shared_ptr< SharedDatasharedData_
 
bool isAbsolute_ = true
 
Date asof_
 
std::string label_
 
Real numeraire_ = 0.0
 
std::vector< Real > data_
 

Detailed Description

Simple Scenario class

Definition at line 34 of file simplescenario.hpp.

Constructor & Destructor Documentation

◆ SimpleScenario() [1/2]

Definition at line 43 of file simplescenario.hpp.

43{}

◆ SimpleScenario() [2/2]

SimpleScenario ( Date  asof,
const std::string &  label = std::string(),
Real  numeraire = 0,
const boost::shared_ptr< SharedData > &  sharedData = nullptr 
)

if sharedData is not provided, the instance will create its own shared data block

Definition at line 30 of file simplescenario.cpp.

32 : sharedData_(sharedData == nullptr ? QuantLib::ext::make_shared<SharedData>() : sharedData), asof_(asof),
33 label_(label), numeraire_(numeraire) {}
const boost::shared_ptr< SharedData > & sharedData() const
get shared data block (for construction of sister scenarios)
const std::string & label() const override
Get the scenario label.
QuantLib::ext::shared_ptr< SharedData > sharedData_
const Date & asof() const override
Return the scenario asof date.

Member Function Documentation

◆ asof()

const Date & asof ( ) const
overridevirtual

Return the scenario asof date.

Implements Scenario.

Definition at line 48 of file simplescenario.hpp.

48{ return asof_; }

◆ setAsof()

void setAsof ( const Date &  d)
overridevirtual

Set the asof date.

Implements Scenario.

Definition at line 49 of file simplescenario.hpp.

49{ asof_ = d; }

◆ label() [1/2]

const std::string & label ( ) const
overridevirtual

Get the scenario label.

Implements Scenario.

Definition at line 51 of file simplescenario.hpp.

51{ return label_; }

◆ label() [2/2]

void label ( const string &  )
overridevirtual

Set the scenario label.

Implements Scenario.

Definition at line 52 of file simplescenario.hpp.

52{ 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 54 of file simplescenario.hpp.

54{ return numeraire_; }

◆ 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 55 of file simplescenario.hpp.

55{ numeraire_ = n; }

◆ isAbsolute()

bool isAbsolute ( ) const
overridevirtual

Is this an absolute or difference scenario?

Implements Scenario.

Definition at line 57 of file simplescenario.hpp.

+ Here is the caller graph for this function:

◆ 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 59 of file simplescenario.hpp.

59 {
60 return sharedData_->coordinates;
61 }
+ Here is the caller graph for this function:

◆ keysHash()

std::size_t keysHash ( ) const
overridevirtual

return fingerprint identifying the set of rf keys of the scenarios, or 0 if not provided by the implementation

Reimplemented from Scenario.

Definition at line 63 of file simplescenario.hpp.

63{ return sharedData_->keysHash; }

◆ has()

bool has ( const RiskFactorKey key) const
overridevirtual

Check whether this scenario provides the data for the given key.

Implements Scenario.

Definition at line 35 of file simplescenario.cpp.

35 {
36 return sharedData_->keyIndex.find(key) != sharedData_->keyIndex.end();
37}

◆ keys()

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

Risk factor keys for which this scenario provides data.

Implements Scenario.

Definition at line 66 of file simplescenario.hpp.

66{ return sharedData_->keys; }

◆ add()

void add ( const RiskFactorKey key,
Real  value 
)
overridevirtual

Add an element to the scenario.

Implements Scenario.

Definition at line 39 of file simplescenario.cpp.

39 {
40 Size dataIndex;
41 if (auto i = sharedData_->keyIndex.find(key); i != sharedData_->keyIndex.end()) {
42 dataIndex = i->second;
43 } else {
44 dataIndex = sharedData_->keyIndex[key] = sharedData_->keys.size();
45 sharedData_->keys.push_back(key);
46 boost::hash_combine(sharedData_->keysHash, key);
47 }
48
49 if (data_.size() <= dataIndex)
50 data_.resize(dataIndex + 1, QuantLib::Null<Real>());
51
52 data_[dataIndex] = value;
53}
SafeStack< ValueType > value
+ Here is the caller graph for this function:

◆ get()

Real get ( const RiskFactorKey key) const
overridevirtual

Get an element from the scenario.

Implements Scenario.

Definition at line 55 of file simplescenario.cpp.

55 {
56 auto i = sharedData_->keyIndex.find(key);
57 QL_REQUIRE(i != sharedData_->keyIndex.end(), "SimpleScenario does not provide data for key " << key);
58 return data_[i->second];
59}

◆ clone()

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

This does not close the shared data.

Implements Scenario.

Definition at line 61 of file simplescenario.cpp.

61 {
62 return QuantLib::ext::make_shared<SimpleScenario>(*this);
63}

◆ setAbsolute()

void setAbsolute ( const bool  b)
overridevirtual

Set if this is an absolute scenario.

Implements Scenario.

Definition at line 65 of file simplescenario.cpp.

bool isAbsolute() const override
Is this an absolute or difference scenario?
+ Here is the call graph for this function:

◆ setCoordinates()

void setCoordinates ( const RiskFactorKey::KeyType  type,
const std::string &  name,
const std::vector< std::vector< Real > > &  coordinates 
)

Definition at line 67 of file simplescenario.cpp.

68 {
69 sharedData_->coordinates[std::make_pair(type, name)] = coordinates;
70}
const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates() const override
Get coordinates.
+ Here is the call graph for this function:

◆ sharedData()

const boost::shared_ptr< SharedData > & sharedData ( ) const

get shared data block (for construction of sister scenarios)

Definition at line 78 of file simplescenario.hpp.

78{ return sharedData_; }

◆ data()

const std::vector< Real > & data ( ) const

get data, order is the same as in keys()

Definition at line 81 of file simplescenario.hpp.

81{ return data_; }

Member Data Documentation

◆ sharedData_

QuantLib::ext::shared_ptr<SharedData> sharedData_
private

Definition at line 84 of file simplescenario.hpp.

◆ isAbsolute_

bool isAbsolute_ = true
private

Definition at line 85 of file simplescenario.hpp.

◆ asof_

Date asof_
private

Definition at line 86 of file simplescenario.hpp.

◆ label_

std::string label_
private

Definition at line 87 of file simplescenario.hpp.

◆ numeraire_

Real numeraire_ = 0.0
private

Definition at line 88 of file simplescenario.hpp.

◆ data_

std::vector<Real> data_
private

Definition at line 89 of file simplescenario.hpp.