Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
imscheduleresults.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 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
21
22#include <ql/utilities/null.hpp>
23
24using QuantLib::Null;
25using QuantLib::Real;
26using std::make_pair;
27using std::ostream;
28using std::string;
29
30namespace ore {
31namespace analytics {
32
33void IMScheduleResults::add(const CrifRecord::ProductClass& pc, const string& calculationCcy, const Real grossIM,
34 const Real grossRC, const Real netRC, const Real ngr, const Real scheduleIM) {
35
36 // Add the value as long as the currencies are matching. If the IMScheduleResults container does not yet have
37 // a currency, we set it to be that of the incoming value
38 if (ccy_.empty())
39 ccy_ = calculationCcy;
40 else
41 QL_REQUIRE(calculationCcy == ccy_, "Cannot add value to IMScheduleResults in a different currency ("
42 << calculationCcy << "). Expected " << ccy_ << ".");
43
44 if (has(pc)) {
45 QL_REQUIRE(grossIM != Null<Real>(), "IMScheduleResults: Gross IM cannot be null.");
46 data_[pc].grossIM += grossIM;
47 } else {
48 IMScheduleResult result = IMScheduleResult(grossIM, grossRC, netRC, ngr, scheduleIM);
49 data_[pc] = result;
50 }
51}
52
53// void IMScheduleResults::convert(const QuantLib::ext::shared_ptr<ore::data::Market>& market, const string& currency) {
54// // Get corresponding FX spot rate
55// Real fxSpot = market->fxRate(ccy_ + currency)->value();
56//
57// convert(fxSpot, currency);
58// }
59//
60// void IMScheduleResults::convert(Real fxSpot, const string& currency) {
61// // Check that target currency is valid
62// QL_REQUIRE(ore::data::checkCurrency(currency), "Cannot convert IMSchedule results. The target currency ("
63// << currency << ") must be a valid ISO currency code");
64//
65// // Skip if already in target currency
66// if (ccy_ == currency)
67// return;
68//
69// // Convert Schedule IM results to target currency
70// for (auto& sr : data_)
71// sr.second *= fxSpot;
72//
73// // Update currency
74// ccy_ = currency;
75// }
76
78 if (has(pc))
79 return data_.at(pc);
80 else
81 return IMScheduleResult(QuantLib::Null<Real>(), QuantLib::Null<Real>(), QuantLib::Null<Real>(),
82 QuantLib::Null<Real>(), QuantLib::Null<Real>());
83}
84
85bool IMScheduleResults::has(const CrifRecord::ProductClass& pc) const { return data_.count(pc) > 0; }
86
87bool IMScheduleResults::empty() const { return data_.empty(); }
88
90
91} // namespace analytics
92} // namespace ore
bool has(const CrifRecord::ProductClass &pc) const
bool empty() const
Return true if the container is empty, otherwise false.
IMScheduleResult get(const CrifRecord::ProductClass &pc) const
Convert Schedule IM amounts to a different currency.
std::map< CrifRecord::ProductClass, IMScheduleResult > data_
void add(const CrifRecord::ProductClass &pc, const std::string &calculationCurrency, const QuantLib::Real grossIM, const QuantLib::Real grossRC, const QuantLib::Real netRC, const QuantLib::Real ngr, const QuantLib::Real scheduleIM)
void clear()
Clear the results from the container.
Class for holding IMSchedule results.