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

Scenario Generator description. More...

#include <orea/scenario/scenariogeneratordata.hpp>

+ Inheritance diagram for ScenarioGeneratorData:
+ Collaboration diagram for ScenarioGeneratorData:

Public Member Functions

 ScenarioGeneratorData ()
 
 ScenarioGeneratorData (QuantLib::ext::shared_ptr< DateGrid > dateGrid, SequenceType sequenceType, long seed, Size samples, SobolBrownianGenerator::Ordering ordering=SobolBrownianGenerator::Steps, SobolRsg::DirectionIntegers directionIntegers=SobolRsg::JoeKuoD7, bool withCloseOutLag=false, bool withMporStickyDate=false)
 Constructor. More...
 
void clear ()
 
virtual void fromXML (XMLNode *node) override
 Load members from XML. More...
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 Write members to XML. More...
 
Inspectors
QuantLib::ext::shared_ptr< DateGridgetGrid () const
 
SequenceType sequenceType () const
 
long seed () const
 
Size samples () const
 
SobolBrownianGenerator::Ordering ordering () const
 
SobolRsg::DirectionIntegers directionIntegers () const
 
QuantLib::ext::shared_ptr< DateGridcloseOutDateGrid () const
 
bool withCloseOutLag () const
 
bool withMporStickyDate () const
 
Period closeOutLag () const
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const=0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 
std::string toXMLString () const
 

Setters

QuantLib::ext::shared_ptr< DateGridgrid_
 
SequenceType sequenceType_
 
long seed_
 
Size samples_
 
SobolBrownianGenerator::Ordering ordering_
 
SobolRsg::DirectionIntegers directionIntegers_
 
QuantLib::ext::shared_ptr< DateGridcloseOutDateGrid_
 
bool withCloseOutLag_
 
bool withMporStickyDate_
 
Period closeOutLag_
 
MporCashFlowMode mporCashFlowMode_
 
string gridString_
 
void setGrid (QuantLib::ext::shared_ptr< DateGrid > grid)
 
SequenceTypesequenceType ()
 
long & seed ()
 
Size & samples ()
 
SobolBrownianGenerator::Ordering & ordering ()
 
SobolRsg::DirectionIntegers & directionIntegers ()
 
boolwithCloseOutLag ()
 
boolwithMporStickyDate ()
 
Period & closeOutLag ()
 

Detailed Description

Scenario Generator description.

ScenarioGeneratorData wraps the specification of how to build a scenario generator from a given cross asset model and covers the choice and configuration of

Definition at line 52 of file scenariogeneratordata.hpp.

Constructor & Destructor Documentation

◆ ScenarioGeneratorData() [1/2]

◆ ScenarioGeneratorData() [2/2]

ScenarioGeneratorData ( QuantLib::ext::shared_ptr< DateGrid dateGrid,
SequenceType  sequenceType,
long  seed,
Size  samples,
SobolBrownianGenerator::Ordering  ordering = SobolBrownianGenerator::Steps,
SobolRsg::DirectionIntegers  directionIntegers = SobolRsg::JoeKuoD7,
bool  withCloseOutLag = false,
bool  withMporStickyDate = false 
)

Constructor.

Definition at line 60 of file scenariogeneratordata.hpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ clear()

void clear ( )

Definition at line 39 of file scenariogeneratordata.cpp.

39 {
40 if (grid_)
41 grid_->truncate(0);
42}

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Load members from XML.

Implements XMLSerializable.

Definition at line 60 of file scenariogeneratordata.cpp.

60 {
61 XMLNode* sim = XMLUtils::locateNode(root, "Simulation");
62 XMLNode* node = XMLUtils::getChildNode(sim, "Parameters");
63 XMLUtils::checkNode(node, "Parameters");
64
65 std::string calString = XMLUtils::getChildValue(node, "Calendar", true);
66 Calendar cal = parseCalendar(calString);
67
68 std::string dcString = XMLUtils::getChildValue(node, "DayCounter", false);
69 DayCounter dc = dcString.empty() ? ActualActual(ActualActual::ISDA) : parseDayCounter(dcString);
70
71 gridString_ = XMLUtils::getChildValue(node, "Grid", true);
72 std::vector<std::string> tokens;
73 boost::split(tokens, gridString_, boost::is_any_of(","));
74 if (tokens.size() <= 2) {
75 grid_ = QuantLib::ext::make_shared<DateGrid>(gridString_, cal, dc);
76 } else {
77 std::vector<Period> gridTenors = XMLUtils::getChildrenValuesAsPeriods(node, "Grid", true);
78 grid_ = QuantLib::ext::make_shared<DateGrid>(gridTenors, cal, dc);
79 }
80 LOG("ScenarioGeneratorData grid points size = " << grid_->size());
81
82 std::string sequenceTypeString = XMLUtils::getChildValue(node, "Sequence", true);
83 sequenceType_ = parseSequenceType(sequenceTypeString);
84 LOG("ScenarioGeneratorData sequence type = " << sequenceTypeString);
85
86 seed_ = XMLUtils::getChildValueAsInt(node, "Seed", true);
87 LOG("ScenarioGeneratorData seed = " << seed_);
88
89 samples_ = XMLUtils::getChildValueAsInt(node, "Samples", true);
90 LOG("ScenarioGeneratorData samples = " << samples_);
91
92 // overwrite samples with environment variable OVERWRITE_SCENARIOGENERATOR_SAMPLES
93 if (auto c = getenv("OVERWRITE_SCENARIOGENERATOR_SAMPLES")) {
94 try {
95 samples_ = std::stol(c);
96 } catch (const std::exception& e) {
97 WLOG("enviroment variable OVERWRITE_SCENARIOGENERATOR_SAMPLES is set ("
98 << c << ") but can not be parsed to a number - ignoring.");
99 }
100 LOG("Overwrite samples with " << samples_ << " from environment variable OVERWRITE_SCENARIOGENERATOR_SAMPLES")
101 }
102
103 if (auto n = XMLUtils::getChildNode(node, "Ordering"))
105 else
106 ordering_ = SobolBrownianGenerator::Steps;
107
108 if (auto n = XMLUtils::getChildNode(node, "DirectionIntegers"))
110 else
111 directionIntegers_ = SobolRsg::JoeKuoD7;
112
113 withCloseOutLag_ = false;
114 if (XMLUtils::getChildNode(node, "CloseOutLag") != NULL) {
115 withCloseOutLag_ = true;
116 closeOutLag_ = parsePeriod(XMLUtils::getChildValue(node, "CloseOutLag", true));
117 grid_->addCloseOutDates(closeOutLag_);
118 LOG("Use lagged close out grid, lag period is " << closeOutLag_);
119 }
120 withMporStickyDate_ = false;
121 if (XMLUtils::getChildNode(node, "MporMode") != NULL) {
122 string mporMode = XMLUtils::getChildValue(node, "MporMode", true);
123 if (mporMode == "StickyDate") {
124 withMporStickyDate_ = true;
125 LOG("Use Mpor sticky date mode");
126 } else if (mporMode == "ActualDate") {
127 withMporStickyDate_ = false;
128 LOG("Use Mpor actual date mode");
129 } else {
130 QL_FAIL("MporMode " << mporMode << " not recognised");
131 }
132 }
133
134 LOG("ScenarioGeneratorData done.");
135}
static void checkNode(XMLNode *n, const string &expectedName)
static XMLNode * locateNode(XMLNode *n, const string &name="")
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static vector< Period > getChildrenValuesAsPeriods(XMLNode *node, const string &name, bool mandatory=false)
Calendar parseCalendar(const string &s)
SequenceType parseSequenceType(const std::string &s)
Period parsePeriod(const string &s)
SobolRsg::DirectionIntegers parseSobolRsgDirectionIntegers(const std::string &s)
SobolBrownianGenerator::Ordering parseSobolBrownianGeneratorOrdering(const std::string &s)
DayCounter parseDayCounter(const string &s)
#define LOG(text)
#define WLOG(text)
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Write members to XML.

Implements XMLSerializable.

Definition at line 137 of file scenariogeneratordata.cpp.

137 {
138 XMLNode* node = doc.allocNode("Simulation");
139 XMLNode* pNode = XMLUtils::addChild(doc, node, "Parameters");
140
141 if (grid_) {
142 XMLUtils::addChild(doc, pNode, "Calendar", grid_->calendar().name());
143 XMLUtils::addChild(doc, pNode, "DayCounter", grid_->dayCounter().name());
144 if (!gridString_.empty()) {
145 XMLUtils::addChild(doc, pNode, "Grid", gridString_);
146 } else {
147 XMLUtils::addGenericChildAsList(doc, pNode, "Grid", grid_->tenors());
148 }
149 }
150
151 XMLUtils::addChild(doc, pNode, "Sequence", ore::data::to_string( sequenceType_));
152 XMLUtils::addChild(doc, pNode, "Seed", to_string(seed_));
153 XMLUtils::addChild(doc, pNode, "Samples", to_string(samples_));
154
155 XMLUtils::addChild(doc, pNode, "Ordering", ore::data::to_string((SobolBrownianGenerator::Ordering) ordering_) );
156 XMLUtils::addChild(doc, pNode, "DirectionIntegers", ore::data::to_string(directionIntegers_));
157
158 if (withCloseOutLag_) {
159 XMLUtils::addChild(doc, pNode, "CloseOutLag", closeOutLag_);
160 }
162 XMLUtils::addChild(doc, pNode, "MporMode", "StickyDate");
163 } else {
164 XMLUtils::addChild(doc, pNode, "MporMode", "ActualDate");
165 }
166
167 return node;
168}
XMLNode * allocNode(const string &nodeName)
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
std::string to_string(const LocationInfo &l)
+ Here is the call graph for this function:

◆ getGrid()

QuantLib::ext::shared_ptr< DateGrid > getGrid ( ) const

Definition at line 79 of file scenariogeneratordata.hpp.

79{ return grid_; }

◆ sequenceType() [1/2]

SequenceType sequenceType ( ) const

Definition at line 80 of file scenariogeneratordata.hpp.

80{ return sequenceType_; }

◆ seed() [1/2]

long seed ( ) const

Definition at line 81 of file scenariogeneratordata.hpp.

81{ return seed_; }

◆ samples() [1/2]

Size samples ( ) const

Definition at line 82 of file scenariogeneratordata.hpp.

82{ return samples_; }

◆ ordering() [1/2]

SobolBrownianGenerator::Ordering ordering ( ) const

Definition at line 83 of file scenariogeneratordata.hpp.

83{ return ordering_; }

◆ directionIntegers() [1/2]

SobolRsg::DirectionIntegers directionIntegers ( ) const

Definition at line 84 of file scenariogeneratordata.hpp.

84{ return directionIntegers_; }

◆ closeOutDateGrid()

QuantLib::ext::shared_ptr< DateGrid > closeOutDateGrid ( ) const

Definition at line 85 of file scenariogeneratordata.hpp.

85{ return closeOutDateGrid_; }
QuantLib::ext::shared_ptr< DateGrid > closeOutDateGrid_

◆ withCloseOutLag() [1/2]

bool withCloseOutLag ( ) const

Definition at line 86 of file scenariogeneratordata.hpp.

86{ return withCloseOutLag_; }

◆ withMporStickyDate() [1/2]

bool withMporStickyDate ( ) const

Definition at line 87 of file scenariogeneratordata.hpp.

87{ return withMporStickyDate_; }

◆ closeOutLag() [1/2]

Period closeOutLag ( ) const

Definition at line 88 of file scenariogeneratordata.hpp.

88{ return closeOutLag_; }

◆ setGrid()

void setGrid ( QuantLib::ext::shared_ptr< DateGrid grid)

Definition at line 44 of file scenariogeneratordata.cpp.

44 {
45 grid_ = grid;
46
47 std::ostringstream oss;
48 if (grid->tenors().size() == 0) {
49 oss << "";
50 } else {
51 oss << grid->tenors()[0];
52 for (Size i = 1; i < grid->tenors().size(); i++) {
53 oss << ", " << grid->tenors()[i];
54 }
55 }
56
57 gridString_ = oss.str();
58}
Size size(const ValueType &v)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sequenceType() [2/2]

SequenceType & sequenceType ( )

Definition at line 94 of file scenariogeneratordata.hpp.

94{ return sequenceType_; }

◆ seed() [2/2]

long & seed ( )

Definition at line 95 of file scenariogeneratordata.hpp.

95{ return seed_; }

◆ samples() [2/2]

Size & samples ( )

Definition at line 96 of file scenariogeneratordata.hpp.

96{ return samples_; }

◆ ordering() [2/2]

SobolBrownianGenerator::Ordering & ordering ( )

Definition at line 97 of file scenariogeneratordata.hpp.

97{ return ordering_; }

◆ directionIntegers() [2/2]

SobolRsg::DirectionIntegers & directionIntegers ( )

Definition at line 98 of file scenariogeneratordata.hpp.

98{ return directionIntegers_; }

◆ withCloseOutLag() [2/2]

bool & withCloseOutLag ( )

Definition at line 99 of file scenariogeneratordata.hpp.

99{ return withCloseOutLag_; }

◆ withMporStickyDate() [2/2]

bool & withMporStickyDate ( )

Definition at line 100 of file scenariogeneratordata.hpp.

100{ return withMporStickyDate_; }

◆ closeOutLag() [2/2]

Period & closeOutLag ( )

Definition at line 101 of file scenariogeneratordata.hpp.

101{ return closeOutLag_; }

Member Data Documentation

◆ grid_

QuantLib::ext::shared_ptr<DateGrid> grid_
private

Definition at line 104 of file scenariogeneratordata.hpp.

◆ sequenceType_

SequenceType sequenceType_
private

Definition at line 105 of file scenariogeneratordata.hpp.

◆ seed_

long seed_
private

Definition at line 106 of file scenariogeneratordata.hpp.

◆ samples_

Size samples_
private

Definition at line 107 of file scenariogeneratordata.hpp.

◆ ordering_

SobolBrownianGenerator::Ordering ordering_
private

Definition at line 108 of file scenariogeneratordata.hpp.

◆ directionIntegers_

SobolRsg::DirectionIntegers directionIntegers_
private

Definition at line 109 of file scenariogeneratordata.hpp.

◆ closeOutDateGrid_

QuantLib::ext::shared_ptr<DateGrid> closeOutDateGrid_
private

Definition at line 110 of file scenariogeneratordata.hpp.

◆ withCloseOutLag_

bool withCloseOutLag_
private

Definition at line 111 of file scenariogeneratordata.hpp.

◆ withMporStickyDate_

bool withMporStickyDate_
private

Definition at line 112 of file scenariogeneratordata.hpp.

◆ closeOutLag_

Period closeOutLag_
private

Definition at line 113 of file scenariogeneratordata.hpp.

◆ mporCashFlowMode_

MporCashFlowMode mporCashFlowMode_
private

Definition at line 114 of file scenariogeneratordata.hpp.

◆ gridString_

string gridString_
private

Definition at line 115 of file scenariogeneratordata.hpp.