Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
external_randomvariable_ops.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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
20
22
23namespace QuantExt {
24
25ExternalRandomVariable::ExternalRandomVariable(std::size_t id) : initialized_(true), id_(id) {}
26
27ExternalRandomVariable::ExternalRandomVariable(double v) : initialized_(true), v_(v) {
28 id_ = ComputeEnvironment::instance().context().createInputVariable(v);
29}
30
31ExternalRandomVariable::ExternalRandomVariable(const std::size_t randomVariableOpCode,
32 const std::vector<const ExternalRandomVariable*>& args) {
33 std::vector<std::size_t> argIds(args.size());
34 std::transform(args.begin(), args.end(), argIds.begin(), [](const ExternalRandomVariable* v) { return v->id(); });
35 id_ = ComputeEnvironment::instance().context().applyOperation(randomVariableOpCode, argIds);
36 initialized_ = true;
37}
38
40 QL_REQUIRE(initialized_, "ExternalRandomVariable::clear(): not initialized");
41 ComputeEnvironment::instance().context().freeVariable(id_);
42 initialized_ = false;
43}
44
46 QL_REQUIRE(initialized_, "ExternalRandomVariable::declareAsOutput(): not initialized");
47 ComputeEnvironment::instance().context().declareOutputVariable(id_);
48}
49
50std::size_t ExternalRandomVariable::id() const {
51 QL_REQUIRE(initialized_, "ExternalRandomVariable::id(): not initialized");
52 return id_;
53}
54
56 std::function<void(ExternalRandomVariable&)>([](ExternalRandomVariable& x) { x.clear(); });
57
58std::vector<ExternalRandomVariableOp> getExternalRandomVariableOps() {
59 std::vector<ExternalRandomVariableOp> ops;
60
61 // None = 0
62 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) -> ExternalRandomVariable {
63 QL_FAIL("ExternRandomVariable does not support op None");
64 });
65
66 // Add = 1
67 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
69 });
70
71 // Subtract = 2
72 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
74 });
75
76 // Negative = 3
77 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
79 });
80
81 // Mult = 4
82 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
84 });
85
86 // Div = 5
87 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
89 });
90
91 // ConditionalExpectation = 6
92 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
94 });
95
96 // IndicatorEq = 7
97 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
99 });
100
101 // IndicatorGt = 8
102 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
104 });
105
106 // IndicatorGeq = 9
107 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
109 });
110
111 // Min = 10
112 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
114 });
115
116 // Max = 11
117 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
119 });
120
121 // Abs = 12
122 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
124 });
125
126 // Exp = 13
127 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
129 });
130
131 // Sqrt = 14
132 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
134 });
135
136 // Log = 15
137 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
139 });
140
141 // Pow = 16
142 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
144 });
145
146 // NormalCdf = 17
147 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
149 });
150
151 // NormalPdf = 18
152 ops.push_back([](const std::vector<const ExternalRandomVariable*>& args) {
154 });
155
156 return ops;
157}
158
159std::vector<ExternalRandomVariableGrad> getExternalRandomVariableGradients() { return {}; }
160
161} // namespace QuantExt
static std::function< void(ExternalRandomVariable &)> deleter
interface to compute envs
ops for external randomvariables
std::vector< ExternalRandomVariableOp > getExternalRandomVariableOps()
std::vector< ExternalRandomVariableGrad > getExternalRandomVariableGradients()
static constexpr std::size_t Sqrt
static constexpr std::size_t IndicatorEq
static constexpr std::size_t Max
static constexpr std::size_t Add
static constexpr std::size_t Mult
static constexpr std::size_t IndicatorGeq
static constexpr std::size_t Log
static constexpr std::size_t Pow
static constexpr std::size_t Min
static constexpr std::size_t Negative
static constexpr std::size_t Subtract
static constexpr std::size_t NormalCdf
static constexpr std::size_t NormalPdf
static constexpr std::size_t Abs
static constexpr std::size_t ConditionalExpectation
static constexpr std::size_t IndicatorGt
static constexpr std::size_t Div
static constexpr std::size_t Exp