Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
sensitivityreportstream.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 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
23#include <ql/errors.hpp>
24
25#include <boost/algorithm/string.hpp>
26
30using std::getline;
31using std::string;
32using std::vector;
33
34namespace ore {
35namespace analytics {
36
38 row_++;
39 if (row_ <= report_->rows()) {
40 vector<Report::ReportType> entries;
41 for (Size i = 0; i < report_->columns(); i++) {
42 entries.push_back(report_->data(i).at(row_ - 1));
43 }
44 return processRecord(entries);
45 }
46
47 // If we get to here, no more lines to process so return empty record
48 return SensitivityRecord();
49}
50
52 row_ = 0;
53}
54
55SensitivityRecord SensitivityReportStream::processRecord(const vector<Report::ReportType>& entries) const {
56
57 QL_REQUIRE(entries.size() == 10, "On row number " << row_ << ": A sensitivity record needs 10 entries");
58
60 sr.tradeId = QuantLib::ext::get<std::string>(entries[0]);
61 sr.isPar = parseBool(QuantLib::ext::get<std::string>(entries[1]));
62
63 auto p = deconstructFactor(QuantLib::ext::get<std::string>(entries[2]));
64 sr.key_1 = p.first;
65 sr.desc_1 = p.second;
66 sr.shift_1 = QuantLib::ext::get<Real>(entries[3]);
67
68 p = deconstructFactor(QuantLib::ext::get<std::string>(entries[4]));
69 sr.key_2 = p.first;
70 sr.desc_2 = p.second;
71 sr.shift_2 = QuantLib::ext::get<Real>(entries[5]);
72
73 sr.currency = QuantLib::ext::get<std::string>(entries[6]);
74 sr.baseNpv = QuantLib::ext::get<Real>(entries[7]);
75 sr.delta = QuantLib::ext::get<Real>(entries[8]);
76 sr.gamma = QuantLib::ext::get<Real>(entries[9]);
77
78 return sr;
79}
80
81} // namespace analytics
82} // namespace ore
SensitivityRecord processRecord(const std::vector< ore::data::Report::ReportType > &entries) const
Create a record from a collection of strings.
QuantLib::ext::shared_ptr< ore::data::InMemoryReport > report_
void reset() override
Resets the stream so that SensitivityRecord objects can be streamed again.
SensitivityRecord next() override
Returns the next SensitivityRecord in the stream.
bool parseBool(const string &s)
Real parseReal(const string &s)
pair< RiskFactorKey, string > deconstructFactor(const string &factor)
Class for streaming SensitivityRecords from a report.
Shift scenario generation.