Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
filteredsensitivitystream.cpp
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#include <math.h>
21
22using QuantLib::Real;
23using std::fabs;
24
25namespace ore {
26namespace analytics {
27
28FilteredSensitivityStream::FilteredSensitivityStream(const QuantLib::ext::shared_ptr<SensitivityStream>& ss,
29 Real deltaThreshold, Real gammaThreshold)
30 : ss_(ss), deltaThreshold_(deltaThreshold), gammaThreshold_(gammaThreshold) {
31 // Reset the underlying stream in case
32 ss_->reset();
33 while (SensitivityRecord sr = ss_->next()) {
34 if (sr.isCrossGamma() && fabs(sr.gamma) > gammaThreshold_) {
35 deltaKeys_.insert(sr.key_1);
36 deltaKeys_.insert(sr.key_2);
37 }
38 }
39 ss_->reset();
40}
41
42FilteredSensitivityStream::FilteredSensitivityStream(const QuantLib::ext::shared_ptr<SensitivityStream>& ss,
43 QuantLib::Real threshold)
44 : FilteredSensitivityStream(ss, threshold, threshold) {}
45
47 // Return the next sensitivity record in the underlying stream that satisfies
48 // the threshold conditions
49 while (SensitivityRecord sr = ss_->next()) {
50 if (fabs(sr.delta) > deltaThreshold_ || fabs(sr.gamma) > gammaThreshold_ ||
51 (!sr.isCrossGamma() && deltaKeys_.find(sr.key_1) != deltaKeys_.end())) {
52 return sr;
53 }
54 }
55
56 // If we get to here, no more records in underlying stream
57 return SensitivityRecord();
58}
59
61 // Reset the underlying stream
62 ss_->reset();
63}
64
65} // namespace analytics
66} // namespace ore
Class that wraps a sensitivity stream and filters out negligible records.
QuantLib::Real gammaThreshold_
The gamma threshold.
FilteredSensitivityStream(const QuantLib::ext::shared_ptr< SensitivityStream > &ss, QuantLib::Real deltaThreshold, QuantLib::Real gammaThreshold)
QuantLib::ext::shared_ptr< SensitivityStream > ss_
The underlying sensitivity stream that has been wrapped.
QuantLib::Real deltaThreshold_
The delta threshold.
void reset() override
Resets the stream so that SensitivityRecord objects can be streamed again.
SensitivityRecord next() override
Returns the next SensitivityRecord in the stream after filtering.
std::set< RiskFactorKey > deltaKeys_
Set to hold Delta Keys appearing in CrossGammas.
Class that wraps a sensitivity stream and filters out negligible records.