Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CrifLoader Class Referenceabstract

#include <orea/simm/crifloader.hpp>

+ Inheritance diagram for CrifLoader:
+ Collaboration diagram for CrifLoader:

Public Member Functions

 CrifLoader (const QuantLib::ext::shared_ptr< SimmConfiguration > &configuration, const std::vector< std::set< std::string > > &additionalHeaders={}, bool updateMapper=false, bool aggregateTrades=true)
 
virtual ~CrifLoader ()
 
virtual Crif loadCrif ()
 
const QuantLib::ext::shared_ptr< SimmConfiguration > & simmConfiguration ()
 SIMM configuration getter. More...
 

Protected Member Functions

virtual Crif loadCrifImpl ()=0
 
void addRecordToCrif (Crif &crif, CrifRecord &&recordToAdd) const
 
void validateSimmRecord (const CrifRecord &cr) const
 Check if the record is a valid Simm Crif Record. More...
 
void currencyOverrides (CrifRecord &crifRecord) const
 Override currency codes. More...
 
void updateMapping (const CrifRecord &cr) const
 update bucket mappings More...
 

Protected Attributes

QuantLib::ext::shared_ptr< SimmConfigurationconfiguration_
 Simm configuration that is used during loading of CRIF records. More...
 
std::vector< std::set< std::string > > additionalHeaders_
 Defines accepted column headers, beyond required and optional headers, see crifloader.cpp. More...
 
bool updateMapper_
 
bool aggregateTrades_
 

Static Protected Attributes

static std::map< QuantLib::Size, std::set< std::string > > requiredHeaders
 Map giving required CRIF file headers and their allowable alternatives. More...
 
static std::map< QuantLib::Size, std::set< std::string > > optionalHeaders
 Map giving optional CRIF file headers and their allowable alternatives. More...
 

Detailed Description

A class for loading CRIF records. The records are aggregated and stored in a SimmNetSensitivities object so that they can later be used in a SIMM calculation

Definition at line 40 of file crifloader.hpp.

Constructor & Destructor Documentation

◆ CrifLoader()

CrifLoader ( const QuantLib::ext::shared_ptr< SimmConfiguration > &  configuration,
const std::vector< std::set< std::string > > &  additionalHeaders = {},
bool  updateMapper = false,
bool  aggregateTrades = true 
)

Constructor We set the trade ID to an empty string if we are going to be netting at portfolio level. This is the default. To override this the flag keepTradeId may be set to true.

Definition at line 46 of file crifloader.hpp.

47 {},
48 bool updateMapper = false, bool aggregateTrades = true)
49 : configuration_(configuration), additionalHeaders_(additionalHeaders), updateMapper_(updateMapper),
50 aggregateTrades_(aggregateTrades) {}
QuantLib::ext::shared_ptr< SimmConfiguration > configuration_
Simm configuration that is used during loading of CRIF records.
Definition: crifloader.hpp:79
std::vector< std::set< std::string > > additionalHeaders_
Defines accepted column headers, beyond required and optional headers, see crifloader....
Definition: crifloader.hpp:82

◆ ~CrifLoader()

virtual ~CrifLoader ( )
virtual

Destructor

Definition at line 53 of file crifloader.hpp.

53{}

Member Function Documentation

◆ loadCrif()

virtual Crif loadCrif ( )
virtual

Definition at line 55 of file crifloader.hpp.

55 {
56 auto crif = loadCrifImpl();
57 if (updateMapper_ && configuration_->bucketMapper() != nullptr) {
58 configuration_->bucketMapper()->updateFromCrif(crif);
59 }
60 return crif;
61 }
virtual Crif loadCrifImpl()=0
+ Here is the call graph for this function:

◆ simmConfiguration()

const QuantLib::ext::shared_ptr< SimmConfiguration > & simmConfiguration ( )

SIMM configuration getter.

Definition at line 64 of file crifloader.hpp.

64{ return configuration_; }

◆ loadCrifImpl()

virtual Crif loadCrifImpl ( )
protectedpure virtual

Implemented in StringStreamCrifLoader.

+ Here is the caller graph for this function:

◆ addRecordToCrif()

void addRecordToCrif ( Crif crif,
CrifRecord &&  recordToAdd 
) const
protected

Definition at line 95 of file crifloader.cpp.

95 {
96 bool add = recordToAdd.type() != CrifRecord::RecordType::Generic;
97 if (recordToAdd.type() == CrifRecord::RecordType::SIMM) {
98 validateSimmRecord(recordToAdd);
99 currencyOverrides(recordToAdd);
100 add = configuration_->isValidRiskType(recordToAdd.riskType);
101 }
102 if (aggregateTrades_) {
103 recordToAdd.tradeId = "";
104 }
105 if (add) {
106 crif.addRecord(recordToAdd);
107 } else {
108 QL_FAIL("Risk type string " << recordToAdd.riskType << " does not correspond to a valid SimmConfiguration::RiskType");
109 }
110}
void currencyOverrides(CrifRecord &crifRecord) const
Override currency codes.
Definition: crifloader.cpp:145
void validateSimmRecord(const CrifRecord &cr) const
Check if the record is a valid Simm Crif Record.
Definition: crifloader.cpp:112
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateSimmRecord()

void validateSimmRecord ( const CrifRecord cr) const
protected

Check if the record is a valid Simm Crif Record.

Definition at line 112 of file crifloader.cpp.

112 {
113 switch (cr.riskType) {
114 case RiskType::AddOnFixedAmount:
115 case RiskType::AddOnNotionalFactor:
116 QL_REQUIRE(cr.productClass == ProductClass::Empty,
117 "Expected product class " << ProductClass::Empty << " for risk type " << cr.riskType);
118 break;
119 case RiskType::ProductClassMultiplier: {
120
121 QL_REQUIRE(cr.productClass == ProductClass::Empty,
122 "Expected product class " << ProductClass::Empty << " for risk type " << cr.riskType);
123 // Check that the qualifier is a valid Product class
124 auto pc = parseProductClass(cr.qualifier);
125 QL_REQUIRE(pc != ProductClass::Empty,
126 "The qualifier " << cr.qualifier << " should parse to a valid product class for risk type "
127 << cr.riskType);
128 // Check that the amount is a number >= 1.0
129 QL_REQUIRE(cr.amount >= 0.0, "Expected an amount greater than or equal to 0 "
130 << "for risk type " << cr.riskType << " and qualifier " << cr.qualifier
131 << " but got " << cr.amount);
132 break;
133 }
134 case RiskType::Notional:
135 case RiskType::PV:
136 if (cr.imModel == "Schedule")
137 QL_REQUIRE(!cr.endDate.empty(),
138 "Expected end date for risk type " << cr.riskType << " and im_model=\'Schedule\'");
139 break;
140 default:
141 break;
142 }
143}
CrifRecord::ProductClass parseProductClass(const string &pc)
Definition: crifrecord.cpp:127
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currencyOverrides()

void currencyOverrides ( CrifRecord crifRecord) const
protected

Override currency codes.

Definition at line 145 of file crifloader.cpp.

145 {
146 switch (cr.riskType) {
147 case RiskType::IRCurve:
148 case RiskType::IRVol:
149 case RiskType::Inflation:
150 case RiskType::InflationVol:
151 case RiskType::XCcyBasis:
152 case RiskType::FX:
153 // TODO: Do we really need to switch CNH to CNY here?
154 // How many more are like this?
155 if (cr.qualifier == "CNH")
156 cr.qualifier = "CNY";
157 QL_REQUIRE(checkCurrency(cr.qualifier),
158 "currency code '" << cr.qualifier << "' is not a supported currency code");
159 break;
160 case RiskType::FXVol: {
161
162 // Normalise the qualifier i.e. XXXYYY and YYYXXX are the same
163 QL_REQUIRE(cr.qualifier.size() == 6,
164 "Expected a string of length 6 for FXVol qualifier but got " << cr.qualifier);
165 auto ccy_1 = cr.qualifier.substr(0, 3);
166 auto ccy_2 = cr.qualifier.substr(3);
167 if (ccy_1 == "CNH")
168 ccy_1 = "CNY";
169 if (ccy_2 == "CNH")
170 ccy_2 = "CNY";
171 QL_REQUIRE(checkCurrency(ccy_1), "currency code 1 in pair '" << cr.qualifier << "' (" << ccy_1
172 << ") is not a supported currency code");
173 QL_REQUIRE(checkCurrency(ccy_2), "currency code 2 in pair '" << cr.qualifier << "' (" << ccy_2
174 << ") is not a supported currency code");
175 if (ccy_1 > ccy_2)
176 ccy_1.swap(ccy_2);
177 cr.qualifier = ccy_1 + ccy_2;
178
179 break;
180 }
181 default:
182 break;
183 }
184}
bool checkCurrency(const string &code)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateMapping()

void updateMapping ( const CrifRecord cr) const
protected

update bucket mappings

Definition at line 186 of file crifloader.cpp.

186 {
187 // Update the SIMM configuration's bucket mapper if the
188 // loader has set this flag
189 if (updateMapper_ && !cr.isSimmParameter()) {
190 const auto& bm = configuration_->bucketMapper();
191 if (bm->hasBuckets(cr.riskType)) {
192 bm->addMapping(cr.riskType, cr.qualifier, cr.bucket);
193 }
194 }
195}
boost::bimap< T, boost::bimaps::set_of< string, string_cmp > > bm
Definition: riskfilter.cpp:42
+ Here is the call graph for this function:

Member Data Documentation

◆ configuration_

QuantLib::ext::shared_ptr<SimmConfiguration> configuration_
protected

Simm configuration that is used during loading of CRIF records.

Definition at line 79 of file crifloader.hpp.

◆ additionalHeaders_

std::vector<std::set<std::string> > additionalHeaders_
protected

Defines accepted column headers, beyond required and optional headers, see crifloader.cpp.

Definition at line 82 of file crifloader.hpp.

◆ updateMapper_

bool updateMapper_
protected

If true, the SIMM configuration's bucket mapper is updated during the CRIF loading with the mapping from SIMM qualifier to SIMM bucket. This is useful when consuming CRIF files from elsewhere in that it allows for using the mapping that is already present in the external file.

Definition at line 89 of file crifloader.hpp.

◆ aggregateTrades_

bool aggregateTrades_
protected

If true, aggregate over trade ids

Definition at line 92 of file crifloader.hpp.

◆ requiredHeaders

map< Size, set< string > > requiredHeaders
staticprotected
Initial value:
= {
{0, {"tradeid", "trade_id"}},
{1, {"portfolioid", "portfolio_id"}},
{2, {"productclass", "product_class", "asset_class"}},
{3, {"risktype", "risk_type"}},
{4, {"qualifier"}},
{5, {"bucket"}},
{6, {"label1"}},
{7, {"label2"}},
{8, {"amountcurrency", "currency", "amount_currency"}},
{9, {"amount"}},
{10, {"amountusd", "amount_usd"}}}

Map giving required CRIF file headers and their allowable alternatives.

Definition at line 95 of file crifloader.hpp.

◆ optionalHeaders

map< Size, set< string > > optionalHeaders
staticprotected
Initial value:
= {
{11, {"agreementtype", "agreement_type"}},
{12, {"calltype", "call_type"}},
{13, {"initialmargintype", "initial_margin_type"}},
{14, {"legalentityid", "legal_entity_id"}},
{15, {"tradetype", "trade_type"}},
{16, {"immodel", "im_model"}},
{17, {"post_regulations"}},
{18, {"collect_regulations"}},
{19, {"end_date"}},
{20, {"label_3"}},
{21, {"creditquality"}},
{22, {"longshortind"}},
{23, {"coveredbonind"}},
{24, {"tranchethickness"}},
{25, {"bb_rw"}}}

Map giving optional CRIF file headers and their allowable alternatives.

Definition at line 98 of file crifloader.hpp.