Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
calibrationpointcache.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
20
21#include <ql/math/comparison.hpp>
22
23namespace ore {
24namespace data {
25
26bool CalibrationPointCache::hasChanged(const std::vector<std::vector<Real>>& curveTimes,
27 const std::vector<std::vector<Real>>& curveData,
28 const std::vector<std::vector<std::pair<Real, Real>>>& volTimesStrikes,
29 const std::vector<std::vector<Real>>& volData, const bool updateCache) {
30
31 bool dirty = false;
32
33 // check for changes in the times/strikes or data
34
35 dirty = dirty || curveTimes.size() != curveTimes_.size();
36 dirty = dirty || curveData.size() != curveData_.size();
37 dirty = dirty || volTimesStrikes.size() != volTimesStrikes_.size();
38 dirty = dirty || volData.size() != volData_.size();
39
40 for (Size i = 0; i < curveTimes.size() && !dirty; ++i) {
41 dirty = dirty || (curveTimes[i].size() != curveTimes_[i].size());
42 for (Size j = 0; j < curveTimes[i].size() && !dirty; ++j) {
43 dirty = dirty || curveTimes[i][j] != curveTimes_[i][j];
44 }
45 }
46
47 for (Size i = 0; i < curveData.size() && !dirty; ++i) {
48 dirty = dirty || (curveData[i].size() != curveData_[i].size());
49 for (Size j = 0; j < curveData[i].size() && !dirty; ++j) {
50 dirty = dirty || curveData[i][j] != curveData_[i][j];
51 }
52 }
53
54 for (Size i = 0; i < volTimesStrikes.size() && !dirty; ++i) {
55 dirty = dirty || (volTimesStrikes[i].size() != volTimesStrikes_[i].size());
56 for (Size j = 0; j < volTimesStrikes[i].size() && !dirty; ++j) {
57 dirty = dirty || volTimesStrikes[i][j].first != volTimesStrikes_[i][j].first;
58 dirty = dirty || volTimesStrikes[i][j].second != volTimesStrikes_[i][j].second;
59 }
60 }
61
62 for (Size i = 0; i < volData.size() && !dirty; ++i) {
63 dirty = dirty || (volData[i].size() != volData_[i].size());
64 for (Size j = 0; j < volData[i].size() && !dirty; ++j) {
65 dirty = dirty || volData[i][j] != volData_[i][j];
66 }
67 }
68
69 // if dirty update reference results if requested
70
71 if (dirty && updateCache) {
72 curveTimes_ = curveTimes;
73 curveData_ = curveData;
74 volTimesStrikes_ = volTimesStrikes;
75 volData_ = volData;
76 }
77
78 return dirty;
79}
80
81} // namespace data
82} // namespace oreplus
cache for relevant points on curve / vol surfaces
bool hasChanged(const std::vector< std::vector< Real > > &curveTimes, const std::vector< std::vector< Real > > &curveData, const std::vector< std::vector< std::pair< Real, Real > > > &volTimesStrikes, const std::vector< std::vector< Real > > &volData, const bool updateCache)
std::vector< std::vector< Real > > curveTimes_
std::vector< std::vector< std::pair< Real, Real > > > volTimesStrikes_
std::vector< std::vector< Real > > curveData_
std::vector< std::vector< Real > > volData_
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23