Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simmresults.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 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
19/*! \file orea/simm/simmresults.hpp
20 \brief Class for holding SIMM results
21*/
22
23#pragma once
24
25#include <map>
26#include <tuple>
27
30#include <ql/types.hpp>
31
32namespace ore {
33namespace analytics {
34
35/*! A container for SIMM results broken down by product class, risk class
36 and margin type.
37*/
39public:
43 typedef std::tuple<ProductClass, RiskClass, MarginType, std::string> Key;
44
45 SimmResults(const std::string& resultCcy = "", const std::string& calcCcy = "")
46 : resultCcy_(resultCcy), calcCcy_(calcCcy){};
47
48 /*! Add initial margin value \p im to the results container for the given combination of
49 SIMM <em>product class</em>, <em>risk class</em> and <em>margin type</em>
50
51 \remark If there is already a result in the container for that combination, it is
52 overwritten if overwrite=true. Otherwise, the amounts are added together.
53 Can check this using the <code>has</code> method before adding.
54 */
56 const SimmConfiguration::MarginType& mt, const std::string& b, QuantLib::Real im,
57 const std::string& resultCurrency, const std::string& calculationCurrency, const bool overwrite);
58
59 void add(const Key& key, QuantLib::Real im, const std::string& resultCurrency,
60 const std::string& calculationCurrency, const bool overwrite);
61
62 //! Convert SIMM amounts to a different currency
63 void convert(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const std::string& currency);
64 void convert(QuantLib::Real fxSpot, const std::string& currency);
65
66 /*! Get the initial margin value from the results container for the given combination of
67 SIMM <em>product class</em>, <em>risk class</em> and <em>margin type</em>
68
69 \warning returns <code>QuantLib::Null<QuantLib::Real></code> if there is no initial margin
70 value in the results for the given combination. Can avoid this by first checking
71 the results using the <code>has</code> method.
72 */
73 QuantLib::Real get(const CrifRecord::ProductClass& pc, const SimmConfiguration::RiskClass& rc,
74 const SimmConfiguration::MarginType& mt, const std::string b) const;
75
76 /*! Check if there is an initial margin value in the results container for the given combination of
77 SIMM <em>product class</em>, <em>risk class</em> and <em>margin type</em>
78 */
80 const SimmConfiguration::MarginType& mt, const std::string b) const;
81
82 //! Return true if the container is empty, otherwise false
83 bool empty() const;
84
85 //! Clear the results from the container
86 void clear();
87
88 //! Return the map containing the results
89 // Not nice to do this i.e. exposing inner implementation but it
90 // allows to iterate over results cleanly. Would be better to subclass
91 // std::iterator in this class.
92 const std::map<Key, QuantLib::Real>& data() const { return data_; }
93 std::map<Key, QuantLib::Real>& data() { return data_; }
94
95 std::string& resultCurrency() { return resultCcy_; }
96 const std::string& resultCurrency() const { return resultCcy_; }
97
98 std::string& calculationCurrency() { return calcCcy_; }
99 const std::string& calculationCurrency() const { return calcCcy_; }
100
101private:
102 std::map<Key, QuantLib::Real> data_;
103 std::string resultCcy_;
104 std::string calcCcy_;
105};
106
107//! Enable writing of Key
108std::ostream& operator<<(std::ostream& out, const SimmResults::Key& resultsKey);
109
110} // namespace analytics
111} // namespace ore
const std::map< Key, QuantLib::Real > & data() const
Return the map containing the results.
Definition: simmresults.hpp:92
std::map< Key, QuantLib::Real > & data()
Definition: simmresults.hpp:93
SimmConfiguration::RiskClass RiskClass
Definition: simmresults.hpp:41
std::string & calculationCurrency()
Definition: simmresults.hpp:98
SimmConfiguration::MarginType MarginType
Definition: simmresults.hpp:42
CrifRecord::ProductClass ProductClass
Definition: simmresults.hpp:40
void convert(QuantLib::Real fxSpot, const std::string &currency)
bool empty() const
Return true if the container is empty, otherwise false.
void add(const CrifRecord::ProductClass &pc, const SimmConfiguration::RiskClass &rc, const SimmConfiguration::MarginType &mt, const std::string &b, QuantLib::Real im, const std::string &resultCurrency, const std::string &calculationCurrency, const bool overwrite)
std::tuple< ProductClass, RiskClass, MarginType, std::string > Key
Definition: simmresults.hpp:43
bool has(const CrifRecord::ProductClass &pc, const SimmConfiguration::RiskClass &rc, const SimmConfiguration::MarginType &mt, const std::string b) const
const std::string & resultCurrency() const
Definition: simmresults.hpp:96
const std::string & calculationCurrency() const
Definition: simmresults.hpp:99
void convert(const QuantLib::ext::shared_ptr< ore::data::Market > &market, const std::string &currency)
Convert SIMM amounts to a different currency.
Definition: simmresults.cpp:73
SimmResults(const std::string &resultCcy="", const std::string &calcCcy="")
Definition: simmresults.hpp:45
QuantLib::Real get(const CrifRecord::ProductClass &pc, const SimmConfiguration::RiskClass &rc, const SimmConfiguration::MarginType &mt, const std::string b) const
Definition: simmresults.cpp:97
void clear()
Clear the results from the container.
std::string & resultCurrency()
Definition: simmresults.hpp:95
std::map< Key, QuantLib::Real > data_
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
SIMM configuration interface.