Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simplescenario.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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/errors.hpp>
23#include <ql/utilities/null.hpp>
24
25#include <boost/make_shared.hpp>
26
27namespace ore {
28namespace analytics {
29
30SimpleScenario::SimpleScenario(Date asof, const std::string& label, Real numeraire,
31 const boost::shared_ptr<SharedData>& sharedData)
32 : sharedData_(sharedData == nullptr ? QuantLib::ext::make_shared<SharedData>() : sharedData), asof_(asof),
33 label_(label), numeraire_(numeraire) {}
34
35bool SimpleScenario::has(const RiskFactorKey& key) const {
36 return sharedData_->keyIndex.find(key) != sharedData_->keyIndex.end();
37}
38
39void SimpleScenario::add(const RiskFactorKey& key, Real value) {
40 Size dataIndex;
41 if (auto i = sharedData_->keyIndex.find(key); i != sharedData_->keyIndex.end()) {
42 dataIndex = i->second;
43 } else {
44 dataIndex = sharedData_->keyIndex[key] = sharedData_->keys.size();
45 sharedData_->keys.push_back(key);
46 boost::hash_combine(sharedData_->keysHash, key);
47 }
48
49 if (data_.size() <= dataIndex)
50 data_.resize(dataIndex + 1, QuantLib::Null<Real>());
51
52 data_[dataIndex] = value;
53}
54
55Real SimpleScenario::get(const RiskFactorKey& key) const {
56 auto i = sharedData_->keyIndex.find(key);
57 QL_REQUIRE(i != sharedData_->keyIndex.end(), "SimpleScenario does not provide data for key " << key);
58 return data_[i->second];
59}
60
61QuantLib::ext::shared_ptr<Scenario> SimpleScenario::clone() const {
62 return QuantLib::ext::make_shared<SimpleScenario>(*this);
63}
64
65void SimpleScenario::setAbsolute(const bool isAbsolute) { isAbsolute_ = isAbsolute; }
66
67void SimpleScenario::setCoordinates(const RiskFactorKey::KeyType type, const std::string& name,
68 const std::vector<std::vector<Real>>& coordinates) {
69 sharedData_->coordinates[std::make_pair(type, name)] = coordinates;
70}
71
72} // namespace analytics
73} // namespace ore
Data types stored in the scenario class.
Definition: scenario.hpp:48
KeyType
Risk Factor types.
Definition: scenario.hpp:51
const std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > & coordinates() const override
Get coordinates.
void setCoordinates(const RiskFactorKey::KeyType type, const std::string &name, const std::vector< std::vector< Real > > &coordinates)
QuantLib::ext::shared_ptr< Scenario > clone() const override
This does not close the shared data.
Real get(const RiskFactorKey &key) const override
Get an element from the scenario.
void add(const RiskFactorKey &key, Real value) override
Add an element to the scenario.
QuantLib::ext::shared_ptr< SharedData > sharedData_
void setAbsolute(const bool isAbsolute) override
Set if this is an absolute scenario.
bool isAbsolute() const override
Is this an absolute or difference scenario?
bool has(const RiskFactorKey &key) const override
Check whether this scenario provides the data for the given key.
SafeStack< ValueType > value
Simple scenario class.
Date asof(14, Jun, 2018)
string name