Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
simplescenario.hpp
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
19/*! \file scenario/simplescenario.hpp
20 \brief Simple scenario class
21 \ingroup scenario
22*/
23
24#pragma once
25
27
28namespace ore {
29namespace analytics {
30using std::string;
31
32/*! Simple Scenario class
33 \ingroup scenario */
34class SimpleScenario : public Scenario {
35public:
36 struct SharedData {
37 std::vector<RiskFactorKey> keys;
38 std::map<RiskFactorKey, std::size_t> keyIndex;
39 std::map<std::pair<RiskFactorKey::KeyType, std::string>, std::vector<std::vector<Real>>> coordinates;
40 std::size_t keysHash = 0;
41 };
42
44 //! if sharedData is not provided, the instance will create its own shared data block
45 SimpleScenario(Date asof, const std::string& label = std::string(), Real numeraire = 0,
46 const boost::shared_ptr<SharedData>& sharedData = nullptr);
47
48 const Date& asof() const override { return asof_; }
49 void setAsof(const Date& d) override { asof_ = d; }
50
51 const std::string& label() const override { return label_; }
52 void label(const string& s) override { label_ = s; }
53
54 Real getNumeraire() const override { return numeraire_; }
55 void setNumeraire(Real n) override { numeraire_ = n; }
56
57 bool isAbsolute() const override { return isAbsolute_; }
58 const std::map<std::pair<RiskFactorKey::KeyType, std::string>, std::vector<std::vector<Real>>>&
59 coordinates() const override {
60 return sharedData_->coordinates;
61 }
62
63 std::size_t keysHash() const override { return sharedData_->keysHash; }
64
65 bool has(const RiskFactorKey& key) const override;
66 const std::vector<RiskFactorKey>& keys() const override { return sharedData_->keys; }
67 void add(const RiskFactorKey& key, Real value) override;
68 Real get(const RiskFactorKey& key) const override;
69
70 //! This does _not_ close the shared data
71 QuantLib::ext::shared_ptr<Scenario> clone() const override;
72
73 void setAbsolute(const bool isAbsolute) override;
74 void setCoordinates(const RiskFactorKey::KeyType type, const std::string& name,
75 const std::vector<std::vector<Real>>& coordinates);
76
77 //! get shared data block (for construction of sister scenarios)
78 const boost::shared_ptr<SharedData>& sharedData() const { return sharedData_; }
79
80 //! get data, order is the same as in keys()
81 const std::vector<Real>& data() const { return data_; }
82
83private:
84 QuantLib::ext::shared_ptr<SharedData> sharedData_;
85 bool isAbsolute_ = true;
86 Date asof_;
87 std::string label_;
88 Real numeraire_ = 0.0;
89 std::vector<Real> data_;
90};
91
92} // namespace analytics
93} // namespace ore
Data types stored in the scenario class.
Definition: scenario.hpp:48
KeyType
Risk Factor types.
Definition: scenario.hpp:51
Scenario Base Class.
Definition: scenario.hpp:138
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.
std::size_t keysHash() const override
return fingerprint identifying the set of rf keys of the scenarios, or 0 if not provided by the imple...
const boost::shared_ptr< SharedData > & sharedData() const
get shared data block (for construction of sister scenarios)
const std::string & label() const override
Get the scenario label.
void add(const RiskFactorKey &key, Real value) override
Add an element to the scenario.
QuantLib::ext::shared_ptr< SharedData > sharedData_
const Date & asof() const override
Return the scenario asof date.
const std::vector< Real > & data() const
get data, order is the same as in keys()
void setAbsolute(const bool isAbsolute) override
Set if this is an absolute scenario.
bool isAbsolute() const override
Is this an absolute or difference scenario?
void setAsof(const Date &d) override
Set the asof date.
const std::vector< RiskFactorKey > & keys() const override
Risk factor keys for which this scenario provides data.
void setNumeraire(Real n) override
Set the Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].
void label(const string &s) override
Set the scenario label.
Real getNumeraire() const override
Get Numeraire ratio n = N(t) / N(0) so that Price(0) = N(0) * E [Price(t) / N(t) ].
bool has(const RiskFactorKey &key) const override
Check whether this scenario provides the data for the given key.
Scenario class.
std::map< std::pair< RiskFactorKey::KeyType, std::string >, std::vector< std::vector< Real > > > coordinates
std::map< RiskFactorKey, std::size_t > keyIndex