Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
fxbsdata.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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 (foreignCcy_ != rhs.foreignCcy_ || domesticCcy_ != rhs.domesticCcy_ ||
32 return false;
33 }
34 return true;
35}
36
37bool FxBsData::operator!=(const FxBsData& rhs) { return !(*this == rhs); }
38
40 foreignCcy_ = XMLUtils::getAttribute(node, "foreignCcy");
41 LOG("CC-LGM foreignCcy = " << foreignCcy_);
42
43 domesticCcy_ = XMLUtils::getChildValue(node, "DomesticCcy", true);
44 LOG("CC-LGM domesticCcy = " << domesticCcy_);
45
46 std::string calibTypeString = XMLUtils::getChildValue(node, "CalibrationType", true);
47 calibrationType_ = parseCalibrationType(calibTypeString);
48 LOG("CC-LGM calibration type = " << calibTypeString);
49
50 XMLNode* sigmaNode = XMLUtils::getChildNode(node, "Sigma");
51 calibrateSigma_ = XMLUtils::getChildValueAsBool(sigmaNode, "Calibrate", true);
52 LOG("CC-LGM Sigma calibrate = " << calibrateSigma_);
53
54 std::string sigmaTypeString = XMLUtils::getChildValue(sigmaNode, "ParamType", true);
55 sigmaType_ = parseParamType(sigmaTypeString);
56 LOG("CC-LGM Sigma parameter type = " << sigmaTypeString);
57
58 sigmaTimes_ = XMLUtils::getChildrenValuesAsDoublesCompact(sigmaNode, "TimeGrid", true);
59 LOG("CC-LGM Sigma time grid size = " << sigmaTimes_.size());
60
61 sigmaValues_ = XMLUtils::getChildrenValuesAsDoublesCompact(sigmaNode, "InitialValue", true);
62 LOG("CC-LGM Sigma initial values size = " << sigmaValues_.size());
63
64 // Add FX Option calibration instruments
65 if (XMLNode* optionsNode = XMLUtils::getChildNode(node, "CalibrationOptions")) {
66 optionExpiries_ = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Expiries", false);
67 optionStrikes_ = XMLUtils::getChildrenValuesAsStrings(optionsNode, "Strikes", false);
68 if (optionStrikes_.size() > 0) {
69 QL_REQUIRE(optionExpiries_.size() == optionStrikes_.size(),
70 "size mismatch in FX option expiries/strike for foreign ccy " << foreignCcy_);
71 } else {
72 optionStrikes_.resize(optionExpiries_.size(), "ATMF");
73 }
74 }
75}
76
78
79 XMLNode* crossCcyLGMNode = doc.allocNode("CrossCcyLGM");
80 XMLUtils::addAttribute(doc, crossCcyLGMNode, "foreignCcy", foreignCcy_);
81
82 XMLUtils::addChild(doc, crossCcyLGMNode, "DomesticCcy", domesticCcy_);
83 XMLUtils::addGenericChild(doc, crossCcyLGMNode, "CalibrationType", calibrationType_);
84
85 XMLNode* sigmaNode = XMLUtils::addChild(doc, crossCcyLGMNode, "Sigma");
86 XMLUtils::addChild(doc, sigmaNode, "Calibrate", calibrateSigma_);
87 XMLUtils::addGenericChild(doc, sigmaNode, "ParamType", sigmaType_);
88 XMLUtils::addGenericChildAsList(doc, sigmaNode, "TimeGrid", sigmaTimes_);
89 XMLUtils::addGenericChildAsList(doc, sigmaNode, "InitialValue", sigmaValues_);
90
91 XMLNode* calibrationOptionsNode = XMLUtils::addChild(doc, crossCcyLGMNode, "CalibrationOptions");
92 XMLUtils::addGenericChildAsList(doc, calibrationOptionsNode, "Expiries", optionExpiries_);
93 XMLUtils::addGenericChildAsList(doc, calibrationOptionsNode, "Strikes", optionStrikes_);
94
95 return crossCcyLGMNode;
96}
97} // namespace data
98} // namespace ore
FX Model Parameters.
Definition: fxbsdata.hpp:50
std::string foreignCcy_
Definition: fxbsdata.hpp:90
std::string domesticCcy_
Definition: fxbsdata.hpp:91
void fromXML(XMLNode *node)
Definition: fxbsdata.cpp:39
bool operator!=(const FxBsData &rhs)
Definition: fxbsdata.cpp:37
CalibrationType calibrationType_
Definition: fxbsdata.hpp:92
ParamType sigmaType_
Definition: fxbsdata.hpp:94
std::vector< std::string > optionExpiries_
Definition: fxbsdata.hpp:97
XMLNode * toXML(XMLDocument &doc)
Definition: fxbsdata.cpp:77
std::vector< Time > sigmaTimes_
Definition: fxbsdata.hpp:95
std::vector< Real > sigmaValues_
Definition: fxbsdata.hpp:96
bool operator==(const FxBsData &rhs)
Definition: fxbsdata.cpp:26
std::vector< std::string > optionStrikes_
Definition: fxbsdata.hpp:98
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 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 vector< Real > getChildrenValuesAsDoublesCompact(XMLNode *node, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:327
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
FX 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
ParamType parseParamType(const string &s)
Convert parameter type string into enumerated class value.
Definition: irmodeldata.cpp:38
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.