22#include <ql/errors.hpp>
23#include <boost/algorithm/string.hpp>
24#include <boost/assign.hpp>
25#include <boost/bimap.hpp>
32using boost::assign::list_of;
36 bool operator()(
const string& lhs,
const string& rhs)
const {
37 return ((boost::to_lower_copy(lhs)) < (boost::to_lower_copy(rhs)));
42template <
typename T>
using bm = boost::bimap<T, boost::bimaps::set_of<string, string_cmp>>;
46 MarketRiskConfiguration::RiskClass::All,
"All")
47 (MarketRiskConfiguration::RiskClass::InterestRate,
"InterestRate")
48 (MarketRiskConfiguration::RiskClass::Inflation,
"Inflation")
49 (MarketRiskConfiguration::RiskClass::Credit,
"Credit")
50 (MarketRiskConfiguration::RiskClass::Equity,
"Equity")
51 (MarketRiskConfiguration::RiskClass::FX,
"FX");
54 MarketRiskConfiguration::RiskType::All,
"All")(
55 MarketRiskConfiguration::RiskType::DeltaGamma,
"DeltaGamma")(MarketRiskConfiguration::RiskType::Vega,
"Vega")(
56 MarketRiskConfiguration::RiskType::BaseCorrelation,
"BaseCorrelation");
60 "Risk class (" <<
static_cast<int>(rc) <<
") not a valid MarketRiskConfiguration::RiskClass");
66 "Risk type (" <<
static_cast<int>(mt) <<
") not a valid MarketRiskConfiguration::RiskType");
72 "Risk class string " << rc <<
" does not correspond to a valid MarketRiskConfiguration::RiskClass");
78 "Risk type string " << mt <<
" does not correspond to a valid MarketRiskConfiguration::RiskType");
87 set<RiskClass> result;
88 for (Size i = includeAll ? 0 : 1; i < numberOfRiskClasses; ++i)
100 for (Size i = includeAll ? 0 : 1; i < numberOfRiskTypes; ++i)
129 std::set<RiskFactorKey::KeyType> allowed_type, allowed;
131 if (riskType == MarketRiskConfiguration::RiskType::All) {
135 case MarketRiskConfiguration::RiskType::DeltaGamma:
150 case MarketRiskConfiguration::RiskType::Vega:
161 case MarketRiskConfiguration::RiskType::BaseCorrelation:
165 QL_FAIL(
"unexpected riskTypeIndex " << riskType);
169 if (riskClass == MarketRiskConfiguration::RiskClass::All) {
170 allowed = allowed_type;
172 std::set<RiskFactorKey::KeyType> allowed_class;
174 case MarketRiskConfiguration::RiskClass::InterestRate:
181 case MarketRiskConfiguration::RiskClass::Inflation:
185 case MarketRiskConfiguration::RiskClass::Credit:
189 case MarketRiskConfiguration::RiskClass::Equity:
193 case MarketRiskConfiguration::RiskClass::FX:
197 QL_FAIL(
"unexpected riskClassIndex " << riskClass);
199 std::set_intersection(allowed_type.begin(), allowed_type.end(), allowed_class.begin(), allowed_class.end(),
200 std::inserter(allowed, allowed.begin()));
203 if (allowed.size() > all.size() / 2) {
204 std::set_difference(all.begin(), all.end(), allowed.begin(), allowed.end(),
215 return neg_ ? !found : found;
static std::set< RiskClass > riskClasses(bool includeAll=false)
Give back a set containing the RiskClass values optionally excluding 'All'.
static std::set< RiskType > riskTypes(bool includeAll=false)
Give back a set containing the RiskType values optionally excluding 'All'.
Data types stored in the scenario class.
@ YoYInflationCapFloorVolatility
@ ZeroInflationCapFloorVolatility
std::set< RiskFactorKey::KeyType > allowed_
RiskFilter(const MarketRiskConfiguration::RiskClass &riskClass, const MarketRiskConfiguration::RiskType &riskType)
bool allow(const RiskFactorKey &t) const override
Allow this key to be updated.
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
MarketRiskConfiguration::RiskType parseVarMarginType(const string &mt)
MarketRiskConfiguration::RiskClass parseVarRiskClass(const string &rc)
const bm< MarketRiskConfiguration::RiskClass > riskClassMap
boost::bimap< T, boost::bimaps::set_of< string, string_cmp > > bm
const bm< MarketRiskConfiguration::RiskType > riskTypeMap
risk class and type filter