Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
scenariofilter.hpp
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
19/*! \file orea/scenario/scenariofilter.hpp
20 \brief Scenario Filter classes
21 \ingroup scenario
22*/
23
24#pragma once
25
27
28namespace ore {
29namespace analytics {
30
31//! Filter that will only allow specified RiskFactorKey::KeyTypes
32/*! To create an FX only scenario filter:
33 *
34 * ScenarioFilter *sf = new RiskFactorTypeScenarioFilter(
35 * { FXSpot, FXVolatility });
36 */
38public:
39 //! Include any RiskFactorKey::KeyTypes
40 RiskFactorTypeScenarioFilter(const std::vector<RiskFactorKey::KeyType>& factors) : factors_(factors) {}
41
42 bool allow(const RiskFactorKey& key) const override {
43 // return true if we are in the set of factors
44 return std::find(factors_.begin(), factors_.end(), key.keytype) != factors_.end();
45 }
46
47private:
48 std::vector<RiskFactorKey::KeyType> factors_;
49};
50
51//! Filter that will only allow specified keys
53public:
54 //! Include only this risk factor
55 /*! If ignore index is true, we only check the keytype and name
56 */
57 RiskFactorScenarioFilter(const RiskFactorKey& key, bool ignoreIndex = true)
58 : key_(key), ignoreIndex_(ignoreIndex) {}
59
60 bool allow(const RiskFactorKey& key) const override {
61 // Only allow key_ in
62 return key.keytype == key_.keytype && key.name == key_.name && (ignoreIndex_ || key.index == key_.index);
63 }
64
65private:
68};
69
70//! Filter for combining the above
72public:
74 CompositeScenarioFilter(const vector<ScenarioFilter>& filters) : filters_(filters) {}
75
76 // add a filter
77 void add(const ScenarioFilter& filter) { filters_.push_back(filter); }
78
79 //! If any one of the filters allows this key, we allow it.
80 bool allow(const RiskFactorKey& key) const override {
81 for (auto filter : filters_) {
82 if (filter.allow(key))
83 return true;
84 }
85 return false;
86 }
87
88private:
89 std::vector<ScenarioFilter> filters_;
90};
91
92} // namespace analytics
93} // namespace oreplus
Filter for combining the above.
void add(const ScenarioFilter &filter)
CompositeScenarioFilter(const vector< ScenarioFilter > &filters)
bool allow(const RiskFactorKey &key) const override
If any one of the filters allows this key, we allow it.
std::vector< ScenarioFilter > filters_
Data types stored in the scenario class.
Definition: scenario.hpp:48
KeyType keytype
Key type.
Definition: scenario.hpp:89
std::string name
Key name.
Definition: scenario.hpp:94
Filter that will only allow specified keys.
RiskFactorScenarioFilter(const RiskFactorKey &key, bool ignoreIndex=true)
Include only this risk factor.
bool allow(const RiskFactorKey &key) const override
Allow this key to be updated.
Filter that will only allow specified RiskFactorKey::KeyTypes.
RiskFactorTypeScenarioFilter(const std::vector< RiskFactorKey::KeyType > &factors)
Include any RiskFactorKey::KeyTypes.
std::vector< RiskFactorKey::KeyType > factors_
bool allow(const RiskFactorKey &key) const override
Allow this key to be updated.
A scenario filter can exclude certain key from updating the scenario.
SafeStack< Filter > filter
A Market class that can be updated by Scenarios.