Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simmbucketmapperbase.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/simmbucketmapperbase.hpp
20 \brief Base SIMM class for mapping qualifiers to buckets
21*/
22
23#pragma once
24
30
31#include <map>
32#include <set>
33#include <string>
34
35namespace ore {
36namespace analytics {
37
39public:
40 BucketMapping(const std::string& bucket, const std::string& validFrom = "", const std::string& validTo = "", bool fallback = false)
42 const std::string& bucket() const { return bucket_; }
43 const std::string& validFrom() const { return validFrom_; }
44 const std::string& validTo() const { return validTo_; }
45 bool fallback() const { return fallback_; }
46 QuantLib::Date validToDate() const;
47 QuantLib::Date validFromDate() const;
48 std::string name() const;
49private:
50 std::string bucket_;
51 std::string validFrom_;
52 std::string validTo_;
54};
55
56bool operator< (const BucketMapping &a, const BucketMapping &b);
57
59public:
60 //! Default constructor that adds fixed known mappings
62 const QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager>& refDataManager = nullptr,
63 const QuantLib::ext::shared_ptr<SimmBasicNameMapper>& nameMapper = nullptr);
64
65 /*! Return the SIMM <em>bucket</em> for a given SIMM <em>RiskType</em> and
66 SIMM <em>Qualifier</em>. An error is thrown if there is no <em>bucket</em>
67 for the combination.
68 */
69 std::string bucket(const CrifRecord::RiskType& riskType, const std::string& qualifier) const override;
70
71 //! Check if the given SIMM <em>RiskType</em> has a bucket structure.
72 bool hasBuckets(const CrifRecord::RiskType& riskType) const override;
73
74 //! Check if the given \p riskType and \p qualifier has a valid mapping
75 bool has(const CrifRecord::RiskType& riskType, const std::string& qualifier,
76 boost::optional<bool> fallback = boost::none) const override;
77
78 //! \name Serialisation
79 //@{
81 void fromXML(ore::data::XMLNode* node) override;
82 //@}
83
84 //! Add a single \p bucket mapping for \p qualifier with risk type \p riskType
85 /*! \todo Not very convenient. If deemed useful, add more methods for adding
86 mappings e.g. <code>addMappingRange</code> that adds a range of
87 mappings at once
88 */
89 void addMapping(const CrifRecord::RiskType& riskType, const std::string& qualifier,
90 const std::string& bucket, const std::string& validFrom = "", const std::string& validTo = "", bool fallback = false) override;
91
92 //! Set the Reference data manager
93 void setSimmNameMapper(const QuantLib::ext::shared_ptr<SimmBasicNameMapper> nameMapper) { nameMapper_ = nameMapper; }
94
95 //! Set the Reference data manager
96 void setRefDataManger(const QuantLib::ext::shared_ptr<ore::data::BasicReferenceDataManager>& refDataManager) { refDataManager_ = refDataManager; }
97
98 const std::set<FailedMapping>& failedMappings() const override { return failedMappings_; }
99
100protected:
101 /*! Simple logic for RiskType Risk_IRCurve. Qualifier is a currency code and
102 this is checked here.
103 */
104 virtual std::string irBucket(const std::string& qualifier) const;
105
106 //! Check the risk type before adding a mapping entry
107 void checkRiskType(const CrifRecord::RiskType& riskType) const;
108
109 /*! Map from SIMM <em>RiskType</em> to another map that holds the
110 SIMM <em>Qualifier</em> to SIMM <em>bucket</em> mappings
111 */
112 std::map<CrifRecord::RiskType, std::map<std::string, std::set<BucketMapping>>> bucketMapping_;
113
114 //! Set of SIMM risk types that have buckets
115 std::set<CrifRecord::RiskType> rtWithBuckets_;
116
117private:
118 mutable std::map<std::pair<CrifRecord::RiskType, std::string>, std::string> cache_;
119
120 //! Reset the SIMM bucket mapper i.e. clears all mappings and adds the initial hard-coded commodity mappings
121 void reset();
122
123 //! Reference data manager
124 QuantLib::ext::shared_ptr<ore::data::ReferenceDataManager> refDataManager_;
125
126 //! Simm Name Mapper
127 QuantLib::ext::shared_ptr<SimmBasicNameMapper> nameMapper_;
128
129 mutable std::set<FailedMapping> failedMappings_;
130};
131
132} // namespace analytics
133} // namespace ore
QuantLib::Date validFromDate() const
BucketMapping(const std::string &bucket, const std::string &validFrom="", const std::string &validTo="", bool fallback=false)
const std::string & validFrom() const
const std::string & validTo() const
const std::string & bucket() const
QuantLib::Date validToDate() const
const std::set< FailedMapping > & failedMappings() const override
bool hasBuckets(const CrifRecord::RiskType &riskType) const override
Check if the given SIMM RiskType has a bucket structure.
std::string bucket(const CrifRecord::RiskType &riskType, const std::string &qualifier) const override
ore::data::XMLNode * toXML(ore::data::XMLDocument &) const override
void setRefDataManger(const QuantLib::ext::shared_ptr< ore::data::BasicReferenceDataManager > &refDataManager)
Set the Reference data manager.
void addMapping(const CrifRecord::RiskType &riskType, const std::string &qualifier, const std::string &bucket, const std::string &validFrom="", const std::string &validTo="", bool fallback=false) override
Add a single bucket mapping for qualifier with risk type riskType.
void fromXML(ore::data::XMLNode *node) override
bool has(const CrifRecord::RiskType &riskType, const std::string &qualifier, boost::optional< bool > fallback=boost::none) const override
Check if the given riskType and qualifier has a valid mapping.
virtual std::string irBucket(const std::string &qualifier) const
void checkRiskType(const CrifRecord::RiskType &riskType) const
Check the risk type before adding a mapping entry.
std::map< CrifRecord::RiskType, std::map< std::string, std::set< BucketMapping > > > bucketMapping_
QuantLib::ext::shared_ptr< ore::data::ReferenceDataManager > refDataManager_
Reference data manager.
void reset()
Reset the SIMM bucket mapper i.e. clears all mappings and adds the initial hard-coded commodity mappi...
void setSimmNameMapper(const QuantLib::ext::shared_ptr< SimmBasicNameMapper > nameMapper)
Set the Reference data manager.
std::set< CrifRecord::RiskType > rtWithBuckets_
Set of SIMM risk types that have buckets.
QuantLib::ext::shared_ptr< SimmBasicNameMapper > nameMapper_
Simm Name Mapper.
std::map< std::pair< CrifRecord::RiskType, std::string >, std::string > cache_
bool operator<(const Dividend &d1, const Dividend &d2)
Basic SIMM class for mapping names to SIMM qualifiers.
Abstract base class for classes that map SIMM qualifiers to buckets.
supporting utilities