Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityschwartzmodeldata.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
22
23namespace ore {
24namespace data {
25
27
28 if (name_ != rhs.name_ || ccy_ != rhs.ccy_ || calibrationType_ != rhs.calibrationType_ ||
32 return false;
33 }
34 return true;
35}
36
37bool CommoditySchwartzData::operator!=(const CommoditySchwartzData& rhs) { return !(*this == rhs); }
38
40 name_ = XMLUtils::getAttribute(node, "name");
41 LOG("Cross-Asset Commodity Name = " << name_);
42
43 ccy_ = XMLUtils::getChildValue(node, "Currency", true);
44 LOG("Cross-Asset Commodity Currency = " << ccy_);
45
46 std::string calibTypeString = XMLUtils::getChildValue(node, "CalibrationType", true);
47 calibrationType_ = parseCalibrationType(calibTypeString);
48 LOG("Cross-Asset Commodity calibration type = " << calibTypeString);
49
50 XMLNode* sigmaNode = XMLUtils::getChildNode(node, "Sigma");
51 calibrateSigma_ = XMLUtils::getChildValueAsBool(sigmaNode, "Calibrate", true);
52 LOG("Cross-Asset Commodity Sigma calibrate = " << calibrateSigma_);
53 sigmaValue_ = XMLUtils::getChildValueAsDouble(sigmaNode, "InitialValue", true);
54 LOG("Cross-Asset Commodity Sigma initial value = " << sigmaValue_);
55
56 XMLNode* kappaNode = XMLUtils::getChildNode(node, "Kappa");
57 calibrateKappa_ = XMLUtils::getChildValueAsBool(kappaNode, "Calibrate", true);
58 LOG("Cross-Asset Commodity Kappa calibrate = " << calibrateKappa_);
59 kappaValue_ = XMLUtils::getChildValueAsDouble(kappaNode, "InitialValue", true);
60 LOG("Cross-Asset Commodity Kappa initial value = " << kappaValue_);
61
62 XMLNode* optionsNode = XMLUtils::getChildNode(node, "CalibrationOptions");
63 if (optionsNode) {
64 optionExpiries_ = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Expiries", true);
65 optionStrikes_ = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Strikes", false);
66 if (optionStrikes_.size() > 0) {
67 QL_REQUIRE(optionExpiries_.size() == optionStrikes_.size(),
68 "size mismatch in commodity option expiries/strike for name " << name_);
69 } else // default ATMF
70 optionStrikes_.resize(optionExpiries_.size(), "ATMF");
71 }
72
73 driftFreeState_ = XMLUtils::getChildValueAsBool(node, "DriftFreeState", false);
74}
75
77
78 XMLNode* node = doc.allocNode("CommoditySchwartz");
79 XMLUtils::addAttribute(doc, node, "name", name_);
80
81 XMLUtils::addChild(doc, node, "Currency", ccy_);
82 XMLUtils::addGenericChild(doc, node, "CalibrationType", calibrationType_);
83
84 XMLNode* sigmaNode = XMLUtils::addChild(doc, node, "Sigma");
85 XMLUtils::addChild(doc, sigmaNode, "Calibrate", calibrateSigma_);
86 XMLUtils::addChild(doc, sigmaNode, "InitialValue", sigmaValue_);
87
88 XMLNode* kappaNode = XMLUtils::addChild(doc, node, "Kappa");
89 XMLUtils::addChild(doc, kappaNode, "Calibrate", calibrateKappa_);
90 XMLUtils::addChild(doc, kappaNode, "InitialValue", kappaValue_);
91
92 XMLNode* calibrationOptionsNode = XMLUtils::addChild(doc, node, "CalibrationOptions");
93 XMLUtils::addGenericChildAsList(doc, calibrationOptionsNode, "Expiries", optionExpiries_);
94 XMLUtils::addGenericChildAsList(doc, calibrationOptionsNode, "Strikes", optionStrikes_);
95
96 XMLUtils::addChild(doc, node, "DriftFreeState", driftFreeState_);
97
98 return node;
99}
100} // namespace data
101} // namespace ore
bool operator!=(const CommoditySchwartzData &rhs)
bool operator==(const CommoditySchwartzData &rhs)
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
Definition: xmlutils.hpp:144
static void addGenericChild(XMLDocument &doc, XMLNode *n, const char *name, const T &value)
Adds <Name>p1,p2,p3</Name>
Definition: xmlutils.hpp:137
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:342
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
COM component data for the cross asset model.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define LOG(text)
Logging Macro (Level = Notice)
Definition: log.hpp:552
CalibrationType parseCalibrationType(const string &s)
Convert calibration type string into enumerated class value.
Definition: irmodeldata.cpp:47
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.