Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
creditsimulationparameters.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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
20
24
25#include <boost/lexical_cast.hpp>
26
27using namespace QuantLib;
28
29namespace ore {
30namespace analytics {
31
33 XMLNode* sim = XMLUtils::locateNode(root, "CreditSimulation");
34 XMLNode* node = XMLUtils::getChildNode(sim, "TransitionMatrices");
35 QL_REQUIRE(node != nullptr, "CreditSimulationParameters: Node TransitionMatrices not found.");
36
37 node = XMLUtils::getChildNode(node, "TransitionMatrix");
38 while (node != nullptr) {
39 string name = XMLUtils::getChildValue(node, "Name", true);
40 std::vector<Real> data = XMLUtils::getChildrenValuesAsDoublesCompact(node, "Data", true);
41 Size n = static_cast<Size>(std::sqrt(data.size()));
42 QL_REQUIRE(data.size() == n * n, "CreditSimulationParameters: Square matrix required, found " << data.size()
43 << " elements");
44 Matrix m(n, n, 0.0);
45 for (Size i = 0; i < n; ++i) {
46 for (Size j = 0; j < n; ++j) {
47 m[i][j] = data[i * n + j];
48 }
49 }
51 node = XMLUtils::getNextSibling(node, "TransitionMatrix");
52 }
53
54 node = XMLUtils::getChildNode(sim, "Entities");
55 QL_REQUIRE(node != nullptr, "CreditSimulationparameters: Node Entities not found.");
56 node = XMLUtils::getChildNode(node, "Entity");
57 while (node != nullptr) {
58 string name = XMLUtils::getChildValue(node, "Name", true);
59 std::vector<Real> tmp = XMLUtils::getChildrenValuesAsDoublesCompact(node, "FactorLoadings", true);
60 Array loadings(tmp.begin(), tmp.end());
61 string transitionMatrix = XMLUtils::getChildValue(node, "TransitionMatrix", true);
62 Size initialState = XMLUtils::getChildValueAsInt(node, "InitialState", true);
63 entities_.push_back(name);
64 factorLoadings_.push_back(loadings);
66 initialStates_.push_back(initialState);
67 node = XMLUtils::getNextSibling(node, "Entity");
68 }
69
70 node = XMLUtils::getChildNode(sim, "Risk");
71 QL_REQUIRE(node != nullptr, "CreditSimulationParameters: Node Risk not found.");
72 marketRisk_ = XMLUtils::getChildValueAsBool(node, "Market", true);
73 creditRisk_ = XMLUtils::getChildValueAsBool(node, "Credit", true);
74 zeroMarketPnl_ = XMLUtils::getChildValueAsBool(node, "ZeroMarketPnl", true);
75 evaluation_ = XMLUtils::getChildValue(node, "Evaluation", true);
76 doubleDefault_ = XMLUtils::getChildValueAsBool(node, "DoubleDefault", true);
77 seed_ = XMLUtils::getChildValueAsInt(node, "Seed", true);
78 paths_ = XMLUtils::getChildValueAsInt(node, "Paths", true);
79 creditMode_ = XMLUtils::getChildValue(node, "CreditMode", true);
80 loanExposureMode_ = XMLUtils::getChildValue(node, "LoanExposureMode", true);
81
82 nettingSetIds_ = parseListOfValues(XMLUtils::getChildValue(sim, "NettingSetIds", true));
83}
84
86 QL_FAIL("CreditSimulationParameters::toXML() not implemented");
87}
88
89} // namespace analytics
90} // namespace ore
virtual XMLNode * toXML(XMLDocument &doc) const
const std::map< string, Matrix > & transitionMatrix() const
std::map< string, Matrix > transitionMatrix_
\Equality Operators
static XMLNode * locateNode(XMLNode *n, const string &name="")
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
static vector< Real > getChildrenValuesAsDoublesCompact(XMLNode *node, const string &name, bool mandatory=false)
Credit simulation parameter class.
data
std::vector< string > parseListOfValues(string s, const char escape, const char delim, const char quote)
string name