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

#include <ored/configuration/onedimsolverconfig.hpp>

+ Inheritance diagram for OneDimSolverConfig:
+ Collaboration diagram for OneDimSolverConfig:

Public Member Functions

 OneDimSolverConfig ()
 Default constructor with everything QuantLib::Null. More...
 
 OneDimSolverConfig (QuantLib::Size maxEvaluations, QuantLib::Real initialGuess, QuantLib::Real accuracy, const std::pair< QuantLib::Real, QuantLib::Real > &minMax, QuantLib::Real lowerBound=QuantLib::Null< QuantLib::Real >(), QuantLib::Real upperBound=QuantLib::Null< QuantLib::Real >())
 Constructor for max min based solver configuration. More...
 
 OneDimSolverConfig (QuantLib::Size maxEvaluations, QuantLib::Real initialGuess, QuantLib::Real accuracy, QuantLib::Real step, QuantLib::Real lowerBound=QuantLib::Null< QuantLib::Real >(), QuantLib::Real upperBound=QuantLib::Null< QuantLib::Real >())
 Constructor for step based solver configuration. More...
 
XMLSerializable interface
void fromXML (ore::data::XMLNode *node) override
 
ore::data::XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
- 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)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Inspectors

QuantLib::Size maxEvaluations_
 
QuantLib::Real initialGuess_
 
QuantLib::Real accuracy_
 
std::pair< QuantLib::Real, QuantLib::Real > minMax_
 
QuantLib::Real step_
 
QuantLib::Real lowerBound_
 
QuantLib::Real upperBound_
 
bool empty_
 
QuantLib::Size maxEvaluations () const
 
QuantLib::Real initialGuess () const
 
QuantLib::Real accuracy () const
 
const std::pair< QuantLib::Real, QuantLib::Real > & minMax () const
 
QuantLib::Real step () const
 
QuantLib::Real lowerBound () const
 
QuantLib::Real upperBound () const
 
bool empty () const
 Return true if default constructed and not populated i.e. no useful configuration. More...
 
 operator QuantExt::Solver1DOptions () const
 Conversion to QuantExt::Solver1DOptions. More...
 
void check () const
 Basic checks. More...
 

Detailed Description

Serializable 1-D solver configuration

Definition at line 36 of file onedimsolverconfig.hpp.

Constructor & Destructor Documentation

◆ OneDimSolverConfig() [1/3]

Default constructor with everything QuantLib::Null.

Definition at line 30 of file onedimsolverconfig.cpp.

31 : maxEvaluations_(Null<Size>()),
32 initialGuess_(Null<Real>()),
33 accuracy_(Null<Real>()),
34 minMax_(make_pair(Null<Real>(), Null<Real>())),
35 step_(Null<Real>()),
36 lowerBound_(Null<Real>()),
37 upperBound_(Null<Real>()),
38 empty_(true) {}
std::pair< QuantLib::Real, QuantLib::Real > minMax_

◆ OneDimSolverConfig() [2/3]

OneDimSolverConfig ( QuantLib::Size  maxEvaluations,
QuantLib::Real  initialGuess,
QuantLib::Real  accuracy,
const std::pair< QuantLib::Real, QuantLib::Real > &  minMax,
QuantLib::Real  lowerBound = QuantLib::Null< QuantLib::Real >(),
QuantLib::Real  upperBound = QuantLib::Null< QuantLib::Real >() 
)

Constructor for max min based solver configuration.

◆ OneDimSolverConfig() [3/3]

OneDimSolverConfig ( QuantLib::Size  maxEvaluations,
QuantLib::Real  initialGuess,
QuantLib::Real  accuracy,
QuantLib::Real  step,
QuantLib::Real  lowerBound = QuantLib::Null< QuantLib::Real >(),
QuantLib::Real  upperBound = QuantLib::Null< QuantLib::Real >() 
)

Constructor for step based solver configuration.

Member Function Documentation

◆ fromXML()

void fromXML ( ore::data::XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 74 of file onedimsolverconfig.cpp.

74 {
75
76 XMLUtils::checkNode(node, "OneDimSolverConfig");
77
78 maxEvaluations_ = XMLUtils::getChildValueAsInt(node, "MaxEvaluations", true);
79 initialGuess_ = XMLUtils::getChildValueAsDouble(node, "InitialGuess", true);
80 accuracy_ = XMLUtils::getChildValueAsDouble(node, "Accuracy", true);
81
82 // Choice between (min, max) pair or step
83 if (XMLNode* minMaxNode = XMLUtils::getChildNode(node, "MinMax")) {
84 Real min = XMLUtils::getChildValueAsDouble(minMaxNode, "Min", true);
85 Real max = XMLUtils::getChildValueAsDouble(minMaxNode, "Max", true);
86 minMax_ = make_pair(min, max);
87 } else if (XMLNode* stepNode = XMLUtils::getChildNode(node, "Step")) {
89 } else {
90 QL_FAIL("OneDimSolverConfig: expected a MinMax or Step node.");
91 }
92
93 lowerBound_ = Null<Real>();
94 if (XMLNode* n = XMLUtils::getChildNode(node, "LowerBound")) {
96 }
97
98 upperBound_ = Null<Real>();
99 if (XMLNode* n = XMLUtils::getChildNode(node, "UpperBound")) {
101 }
102
103 check();
104
105 empty_ = false;
106}
void check() const
Basic checks.
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
Definition: xmlutils.cpp:291
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
RandomVariable max(RandomVariable x, const RandomVariable &y)
RandomVariable min(RandomVariable x, const RandomVariable &y)
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 108 of file onedimsolverconfig.cpp.

108 {
109
110 XMLNode* node = doc.allocNode("OneDimSolverConfig");
111
112 XMLUtils::addChild(doc, node, "MaxEvaluations", static_cast<int>(maxEvaluations_));
113 XMLUtils::addChild(doc, node, "InitialGuess", initialGuess_);
114 XMLUtils::addChild(doc, node, "Accuracy", accuracy_);
115
116 if (step_ != Null<Real>()) {
117 XMLUtils::addChild(doc, node, "Step", accuracy_);
118 } else {
119 XMLNode* minMaxNode = doc.allocNode("MinMax");
120 XMLUtils::addChild(doc, minMaxNode, "Min", minMax_.first);
121 XMLUtils::addChild(doc, minMaxNode, "Max", minMax_.second);
122 XMLUtils::appendNode(node, minMaxNode);
123 }
124
125 if (lowerBound_ != Null<Real>())
126 XMLUtils::addChild(doc, node, "LowerBound", lowerBound_);
127
128 if (upperBound_ != Null<Real>())
129 XMLUtils::addChild(doc, node, "UpperBound", upperBound_);
130
131 return node;
132}
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maxEvaluations()

QuantLib::Size maxEvaluations ( ) const

Definition at line 65 of file onedimsolverconfig.hpp.

65{ return maxEvaluations_; }

◆ initialGuess()

QuantLib::Real initialGuess ( ) const

Definition at line 66 of file onedimsolverconfig.hpp.

66{ return initialGuess_; }

◆ accuracy()

QuantLib::Real accuracy ( ) const

Definition at line 67 of file onedimsolverconfig.hpp.

67{ return accuracy_; }

◆ minMax()

const std::pair< QuantLib::Real, QuantLib::Real > & minMax ( ) const

Definition at line 68 of file onedimsolverconfig.hpp.

68{ return minMax_; }

◆ step()

QuantLib::Real step ( ) const

Definition at line 69 of file onedimsolverconfig.hpp.

69{ return step_; }

◆ lowerBound()

QuantLib::Real lowerBound ( ) const

Definition at line 70 of file onedimsolverconfig.hpp.

70{ return lowerBound_; }

◆ upperBound()

QuantLib::Real upperBound ( ) const

Definition at line 71 of file onedimsolverconfig.hpp.

71{ return upperBound_; }

◆ empty()

bool empty ( ) const

Return true if default constructed and not populated i.e. no useful configuration.

Definition at line 75 of file onedimsolverconfig.hpp.

75{ return empty_; }
+ Here is the caller graph for this function:

◆ operator QuantExt::Solver1DOptions()

operator QuantExt::Solver1DOptions ( ) const

Conversion to QuantExt::Solver1DOptions.

Definition at line 136 of file onedimsolverconfig.cpp.

136 {
137
138 Solver1DOptions solverOptions;
139
140 if (!empty_) {
141 solverOptions.maxEvaluations = maxEvaluations_;
142 solverOptions.accuracy = accuracy_;
143 solverOptions.initialGuess = initialGuess_;
144 solverOptions.minMax = minMax_;
145 solverOptions.step = step_;
146 solverOptions.lowerBound = lowerBound_;
147 solverOptions.upperBound = upperBound_;
148 }
149
150 return solverOptions;
151}
std::pair< QuantLib::Real, QuantLib::Real > minMax
QuantLib::Real initialGuess
QuantLib::Real upperBound
QuantLib::Real lowerBound
QuantLib::Size maxEvaluations

◆ check()

void check ( ) const
private

Basic checks.

Definition at line 153 of file onedimsolverconfig.cpp.

153 {
154
155 QL_REQUIRE(maxEvaluations_ > 0, "MaxEvaluations (" << maxEvaluations_ << ") should be positive.");
156 QL_REQUIRE(accuracy_ > 0, "Accuracy (" << accuracy_ << ") should be positive.");
157
158 if (step_ != Null<Real>()) {
159 QL_REQUIRE(step_ > 0, "Step (" << step_ << ") should be positive when given.");
160 } else {
161 const Real& min = minMax_.first;
162 const Real& max = minMax_.second;
163 QL_REQUIRE(min != Null<Real>() && max != Null<Real>(), "When Step is not given" <<
164 " Min and Max should be provided.");
165 QL_REQUIRE(min < max, "When given, Min (" << min << ") should be less than Max (" << max <<").");
166 }
167
168 if (lowerBound_ != Null<Real>() && upperBound_ != Null<Real>()) {
169 QL_REQUIRE(lowerBound_ < upperBound_, "When given, LowerBound (" << lowerBound_ <<
170 ") should be less than UpperBound (" << upperBound_ << ").");
171 }
172}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ maxEvaluations_

QuantLib::Size maxEvaluations_
private

Definition at line 81 of file onedimsolverconfig.hpp.

◆ initialGuess_

QuantLib::Real initialGuess_
private

Definition at line 82 of file onedimsolverconfig.hpp.

◆ accuracy_

QuantLib::Real accuracy_
private

Definition at line 83 of file onedimsolverconfig.hpp.

◆ minMax_

std::pair<QuantLib::Real, QuantLib::Real> minMax_
private

Definition at line 84 of file onedimsolverconfig.hpp.

◆ step_

QuantLib::Real step_
private

Definition at line 85 of file onedimsolverconfig.hpp.

◆ lowerBound_

QuantLib::Real lowerBound_
private

Definition at line 86 of file onedimsolverconfig.hpp.

◆ upperBound_

QuantLib::Real upperBound_
private

Definition at line 87 of file onedimsolverconfig.hpp.

◆ empty_

bool empty_
private

Definition at line 90 of file onedimsolverconfig.hpp.