Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
zerosensitivityloader.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2023 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
22
23namespace ore {
24namespace analytics {
25
26ZeroSensitivityLoader::ZeroSensitivityLoader(const std::string& filename, const std::string& idColumn,
27 const std::string& riskFactorColumn, const std::string& deltaColumn,
28 const std::string& currencyColumn, const std::string& baseNpvColumn,
29 const std::string& shiftSizeColumn) {
30 ore::data::CSVFileReader reader(filename, true);
31 // TODO: Check if all columns in file
32 while (reader.next()) {
33 QuantLib::Real shiftSize = QuantLib::Null<QuantLib::Real>();
34 QuantLib::Real baseNpv = QuantLib::Null<QuantLib::Real>();
35 QuantLib::Real delta = QuantLib::Null<QuantLib::Real>();
36 std::string id = reader.get(idColumn);
37 std::string key = reader.get(riskFactorColumn);
38 std::string currency = reader.get(currencyColumn);
39 bool validNpv = ore::data::tryParseReal(reader.get(baseNpvColumn), baseNpv);
40 bool validDelta = ore::data::tryParseReal(reader.get(deltaColumn), delta);
41 bool validShiftSize = ore::data::tryParseReal(reader.get(shiftSizeColumn), shiftSize);
42 if (validDelta && validNpv && validShiftSize && !QuantLib::close_enough(delta, 0.0)) {
43 sensitivities_[id].push_back({key, delta, currency, baseNpv, shiftSize});
44 }
45 }
46}
47
48} // namespace analytics
49} // namespace ore
std::map< std::string, std::vector< ZeroSensitivity > > sensitivities_
ZeroSensitivityLoader(const std::string &filename, const std::string &idColum="TradeId", const std::string &riskFactorColumn="Factor_1", const std::string &deltaColumn="Delta", const std::string &currencyColumn="Currency", const std::string &baseNpvColumn="Base NPV", const std::string &shiftSizeColumn="ShiftSize_1")
std::string get(const std::string &field) const
bool tryParseReal(const string &s, QuantLib::Real &result)
Class for structured analytics warnings.