Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
value.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <ored/scripting/value.hpp>
#include <oret/toplevelfixture.hpp>
#include <ql/time/date.hpp>
#include <ql/tuple.hpp>
#include <iostream>
#include <iomanip>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testValueRandomVariableBinaryOps)
 
 BOOST_AUTO_TEST_CASE (testValueRandomVariableUnaryOps)
 
 BOOST_AUTO_TEST_CASE (testValueIllegalOps)
 
 BOOST_AUTO_TEST_CASE (testAssignments)
 
 BOOST_AUTO_TEST_CASE (testIllegalAssignments)
 
 BOOST_AUTO_TEST_CASE (testComparisons)
 
 BOOST_AUTO_TEST_CASE (testIllegalComparisons)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( testValueRandomVariableBinaryOps  )

Definition at line 41 of file value.cpp.

41 {
42 BOOST_TEST_MESSAGE("Testing Value RandomVariable binary ops...");
43 constexpr Size n = 1;
44 RandomVariable a(n, 23), b(n, -10);
45 ValueType x(a), y(b);
46 BOOST_REQUIRE_EQUAL(x.which(), 0);
47 BOOST_REQUIRE_EQUAL(y.which(), 0);
48 ValueType z = x + y;
49 BOOST_REQUIRE_EQUAL(z.which(), 0);
50 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a + b);
51 z = x - y;
52 BOOST_REQUIRE_EQUAL(z.which(), 0);
53 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a - b);
54 z = x * y;
55 BOOST_REQUIRE_EQUAL(z.which(), 0);
56 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a * b);
57 z = x / y;
58 BOOST_REQUIRE_EQUAL(z.which(), 0);
59 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), a / b);
60 z = min(x, y);
61 BOOST_REQUIRE_EQUAL(z.which(), 0);
62 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), min(a, b));
63 z = max(x, y);
64 BOOST_REQUIRE_EQUAL(z.which(), 0);
65 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), max(a, b));
66 z = pow(x, y);
67 BOOST_REQUIRE_EQUAL(z.which(), 0);
68 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), pow(a, b));
69}
RandomVariable max(RandomVariable x, const RandomVariable &y)
RandomVariable pow(RandomVariable x, const RandomVariable &y)
RandomVariable min(RandomVariable x, const RandomVariable &y)
boost::variant< RandomVariable, EventVec, CurrencyVec, IndexVec, DaycounterVec, Filter > ValueType
Definition: value.hpp:60
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( testValueRandomVariableUnaryOps  )

Definition at line 71 of file value.cpp.

71 {
72 BOOST_TEST_MESSAGE("Testing Value RandomVariable unary ops...");
73 constexpr Size n = 1;
74 RandomVariable a(n, 3.0);
75 ValueType x(a);
76 BOOST_REQUIRE_EQUAL(x.which(), 0);
77 ValueType z = -x;
78 BOOST_REQUIRE_EQUAL(z.which(), 0);
79 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), -a);
80 z = abs(x);
81 BOOST_REQUIRE_EQUAL(z.which(), 0);
82 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), abs(a));
83 z = exp(x);
84 BOOST_REQUIRE_EQUAL(z.which(), 0);
85 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), exp(a));
86 z = log(x);
87 BOOST_REQUIRE_EQUAL(z.which(), 0);
88 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), log(a));
89 z = sqrt(x);
90 BOOST_REQUIRE_EQUAL(z.which(), 0);
91 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), sqrt(a));
92 z = normalCdf(x);
93 BOOST_REQUIRE_EQUAL(z.which(), 0);
94 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), normalCdf(a));
95 z = normalPdf(x);
96 BOOST_REQUIRE_EQUAL(z.which(), 0);
97 BOOST_CHECK_EQUAL(QuantLib::ext::get<RandomVariable>(z), normalPdf(a));
98}
RandomVariable exp(RandomVariable x)
RandomVariable sqrt(RandomVariable x)
RandomVariable log(RandomVariable x)
RandomVariable normalCdf(RandomVariable x)
RandomVariable abs(RandomVariable x)
RandomVariable normalPdf(RandomVariable x)
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( testValueIllegalOps  )

Definition at line 100 of file value.cpp.

100 {
101 BOOST_TEST_MESSAGE("Testing Value illegal ops...");
102 constexpr Size n = 1;
103 ValueType a = RandomVariable(n, 23.0);
104 ValueType c = EventVec{n, Date()};
105 ValueType d = CurrencyVec{n, ""};
106 ValueType e = IndexVec{n, ""};
107 BOOST_CHECK_THROW(a + c, QuantLib::Error);
108 BOOST_CHECK_THROW(a + d, QuantLib::Error);
109 BOOST_CHECK_THROW(a + e, QuantLib::Error);
110 BOOST_CHECK_THROW(a - c, QuantLib::Error);
111 BOOST_CHECK_THROW(a - d, QuantLib::Error);
112 BOOST_CHECK_THROW(a - e, QuantLib::Error);
113 BOOST_CHECK_THROW(a * c, QuantLib::Error);
114 BOOST_CHECK_THROW(a * d, QuantLib::Error);
115 BOOST_CHECK_THROW(a * e, QuantLib::Error);
116 BOOST_CHECK_THROW(a / c, QuantLib::Error);
117 BOOST_CHECK_THROW(a / d, QuantLib::Error);
118 BOOST_CHECK_THROW(a / e, QuantLib::Error);
119 BOOST_CHECK_THROW(min(a, c), QuantLib::Error);
120 BOOST_CHECK_THROW(min(a, d), QuantLib::Error);
121 BOOST_CHECK_THROW(min(a, e), QuantLib::Error);
122 BOOST_CHECK_THROW(max(a, c), QuantLib::Error);
123 BOOST_CHECK_THROW(max(a, d), QuantLib::Error);
124 BOOST_CHECK_THROW(max(a, e), QuantLib::Error);
125 BOOST_CHECK_THROW(pow(a, c), QuantLib::Error);
126 BOOST_CHECK_THROW(pow(a, d), QuantLib::Error);
127 BOOST_CHECK_THROW(pow(a, e), QuantLib::Error);
128 BOOST_CHECK_THROW(-c, QuantLib::Error);
129 BOOST_CHECK_THROW(-d, QuantLib::Error);
130 BOOST_CHECK_THROW(-e, QuantLib::Error);
131 BOOST_CHECK_THROW(abs(c), QuantLib::Error);
132 BOOST_CHECK_THROW(abs(d), QuantLib::Error);
133 BOOST_CHECK_THROW(abs(e), QuantLib::Error);
134 BOOST_CHECK_THROW(exp(c), QuantLib::Error);
135 BOOST_CHECK_THROW(exp(d), QuantLib::Error);
136 BOOST_CHECK_THROW(exp(e), QuantLib::Error);
137 BOOST_CHECK_THROW(log(c), QuantLib::Error);
138 BOOST_CHECK_THROW(log(d), QuantLib::Error);
139 BOOST_CHECK_THROW(log(e), QuantLib::Error);
140}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( testAssignments  )

Definition at line 142 of file value.cpp.

142 {
143 BOOST_TEST_MESSAGE("Testing Value assignments...");
144 constexpr Size n = 1;
145 RandomVariable a(n, 10);
146 EventVec c{n, Date(2, Jan, 2017)};
147 CurrencyVec d{n, "EUR"};
148 IndexVec e{n, "EUR-EURIBOR-6M"};
149 ValueType a2(RandomVariable(n, 0.0));
150 ValueType c2(EventVec{n, Date()});
151 ValueType d2(CurrencyVec{n, ""});
152 ValueType e2(IndexVec{n, ""});
153 // type = type
154 BOOST_REQUIRE_NO_THROW(typeSafeAssign(a2, a););
155 BOOST_REQUIRE_EQUAL(a2, ValueType(a));
156 try {
157 typeSafeAssign(c2, c);
158 } catch (const std::exception& e) {
159 BOOST_FAIL(e.what());
160 }
161 BOOST_REQUIRE_NO_THROW(typeSafeAssign(c2, c););
162 BOOST_REQUIRE_EQUAL(c2, ValueType(c));
163 BOOST_REQUIRE_NO_THROW(typeSafeAssign(d2, d););
164 BOOST_REQUIRE_EQUAL(d2, ValueType(d));
165 BOOST_REQUIRE_NO_THROW(typeSafeAssign(e2, e););
166 BOOST_REQUIRE_EQUAL(e2, ValueType(e));
167}
ValueType typeSafeAssign(ValueType &x, const ValueType &y)
Definition: value.cpp:213
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( testIllegalAssignments  )

Definition at line 169 of file value.cpp.

169 {
170 BOOST_TEST_MESSAGE("Testing Value illegal assignments...");
171 constexpr Size n = 1;
172 RandomVariable a(n, 10);
173 EventVec c{n, Date(2, Jan, 2017)};
174 CurrencyVec d{n, "EUR"};
175 IndexVec e{n, "EUR-EURIBOR-6M"};
176 ValueType a2(RandomVariable(n, 0.0));
177 ValueType c2(EventVec{n, Date()});
178 ValueType d2(CurrencyVec{n, ""});
179 ValueType e2(IndexVec{n, ""});
180 // Illegal assignments
181 BOOST_CHECK_THROW(typeSafeAssign(a2, c);, QuantLib::Error);
182 BOOST_CHECK_THROW(typeSafeAssign(a2, d);, QuantLib::Error);
183 BOOST_CHECK_THROW(typeSafeAssign(a2, e);, QuantLib::Error);
184 BOOST_CHECK_THROW(typeSafeAssign(c2, a);, QuantLib::Error);
185 BOOST_CHECK_THROW(typeSafeAssign(c2, d);, QuantLib::Error);
186 BOOST_CHECK_THROW(typeSafeAssign(c2, e);, QuantLib::Error);
187 BOOST_CHECK_THROW(typeSafeAssign(d2, a);, QuantLib::Error);
188 BOOST_CHECK_THROW(typeSafeAssign(d2, c);, QuantLib::Error);
189 BOOST_CHECK_THROW(typeSafeAssign(d2, e);, QuantLib::Error);
190 BOOST_CHECK_THROW(typeSafeAssign(e2, a);, QuantLib::Error);
191 BOOST_CHECK_THROW(typeSafeAssign(e2, c);, QuantLib::Error);
192 BOOST_CHECK_THROW(typeSafeAssign(e2, d);, QuantLib::Error);
193}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/7]

BOOST_AUTO_TEST_CASE ( testComparisons  )

Definition at line 195 of file value.cpp.

195 {
196 BOOST_TEST_MESSAGE("Testing Value comparisons...");
197 constexpr Size n = 1;
198 ValueType a = RandomVariable(n, 10.0), a2 = RandomVariable(n, 11.0);
199 ValueType c = EventVec{n, Date(2, Jan, 2017)}, c2 = EventVec{n, Date(3, Jan, 2017)};
200 ValueType d = CurrencyVec{n, "EUR"}, d2 = CurrencyVec{n, "USD"};
201 ValueType e = IndexVec{n, "EUR-EURIBOR-6M"}, e2 = IndexVec{n, "USD-LIBOR-3M"};
202 // RandomVariable
203 BOOST_CHECK(equal(a, a).at(0));
204 BOOST_CHECK(notequal(a, a2).at(0));
205 BOOST_CHECK(lt(a, a2).at(0));
206 BOOST_CHECK(leq(a, a).at(0));
207 BOOST_CHECK(gt(a2, a).at(0));
208 BOOST_CHECK(geq(a, a).at(0));
209 // EventVec
210 BOOST_CHECK(equal(c, c).at(0));
211 BOOST_CHECK(notequal(c, c2).at(0));
212 BOOST_CHECK(lt(c, c2).at(0));
213 BOOST_CHECK(leq(c, c).at(0));
214 BOOST_CHECK(gt(c2, c).at(0));
215 BOOST_CHECK(geq(c, c).at(0));
216 // CurrencyVec
217 BOOST_CHECK(equal(d, d).at(0));
218 BOOST_CHECK(notequal(d, d2).at(0));
219 BOOST_CHECK_THROW(lt(d, d2), QuantLib::Error);
220 BOOST_CHECK_THROW(leq(d, d2), QuantLib::Error);
221 BOOST_CHECK_THROW(gt(d, d2), QuantLib::Error);
222 BOOST_CHECK_THROW(geq(d, d2), QuantLib::Error);
223 // IndexVec
224 BOOST_CHECK(equal(e, e).at(0));
225 BOOST_CHECK(notequal(e, e2).at(0));
226 BOOST_CHECK_THROW(lt(e, e2), QuantLib::Error);
227 BOOST_CHECK_THROW(leq(e, e2), QuantLib::Error);
228 BOOST_CHECK_THROW(gt(e, e2), QuantLib::Error);
229 BOOST_CHECK_THROW(geq(e, e2), QuantLib::Error);
230}
Filter equal(Filter x, const Filter &y)
Filter lt(const ValueType &x, const ValueType &y)
Definition: value.cpp:263
Filter notequal(const ValueType &x, const ValueType &y)
Definition: value.cpp:239
Filter gt(const ValueType &x, const ValueType &y)
Definition: value.cpp:282
Filter leq(const ValueType &x, const ValueType &y)
Definition: value.cpp:301
Filter geq(const ValueType &x, const ValueType &y)
Definition: value.cpp:321
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( testIllegalComparisons  )

Definition at line 232 of file value.cpp.

232 {
233 BOOST_TEST_MESSAGE("Testing Value illegal comparisons...");
234 constexpr Size n = 1;
235 ValueType a = RandomVariable(n, 23.0);
236 ValueType c = EventVec{n, Date()};
237 ValueType d = CurrencyVec{n, ""};
238 ValueType e = IndexVec{n, ""};
239 BOOST_CHECK_THROW(equal(a, c), QuantLib::Error);
240 BOOST_CHECK_THROW(equal(a, d), QuantLib::Error);
241 BOOST_CHECK_THROW(equal(a, e), QuantLib::Error);
242 BOOST_CHECK_THROW(equal(c, d), QuantLib::Error);
243 BOOST_CHECK_THROW(equal(c, e), QuantLib::Error);
244 BOOST_CHECK_THROW(equal(d, e), QuantLib::Error);
245 BOOST_CHECK_THROW(notequal(a, c), QuantLib::Error);
246 BOOST_CHECK_THROW(notequal(a, d), QuantLib::Error);
247 BOOST_CHECK_THROW(notequal(a, e), QuantLib::Error);
248 BOOST_CHECK_THROW(notequal(c, d), QuantLib::Error);
249 BOOST_CHECK_THROW(notequal(c, e), QuantLib::Error);
250 BOOST_CHECK_THROW(notequal(d, e), QuantLib::Error);
251 BOOST_CHECK_THROW(lt(a, c), QuantLib::Error);
252 BOOST_CHECK_THROW(lt(a, d), QuantLib::Error);
253 BOOST_CHECK_THROW(lt(a, e), QuantLib::Error);
254 BOOST_CHECK_THROW(lt(c, d), QuantLib::Error);
255 BOOST_CHECK_THROW(lt(c, e), QuantLib::Error);
256 BOOST_CHECK_THROW(lt(d, e), QuantLib::Error);
257 BOOST_CHECK_THROW(leq(a, c), QuantLib::Error);
258 BOOST_CHECK_THROW(leq(a, d), QuantLib::Error);
259 BOOST_CHECK_THROW(leq(a, e), QuantLib::Error);
260 BOOST_CHECK_THROW(leq(c, d), QuantLib::Error);
261 BOOST_CHECK_THROW(leq(c, e), QuantLib::Error);
262 BOOST_CHECK_THROW(leq(d, e), QuantLib::Error);
263 BOOST_CHECK_THROW(gt(a, c), QuantLib::Error);
264 BOOST_CHECK_THROW(gt(a, d), QuantLib::Error);
265 BOOST_CHECK_THROW(gt(a, e), QuantLib::Error);
266 BOOST_CHECK_THROW(gt(c, d), QuantLib::Error);
267 BOOST_CHECK_THROW(gt(c, e), QuantLib::Error);
268 BOOST_CHECK_THROW(gt(d, e), QuantLib::Error);
269 BOOST_CHECK_THROW(geq(a, c), QuantLib::Error);
270 BOOST_CHECK_THROW(geq(a, d), QuantLib::Error);
271 BOOST_CHECK_THROW(geq(a, e), QuantLib::Error);
272 BOOST_CHECK_THROW(geq(c, d), QuantLib::Error);
273 BOOST_CHECK_THROW(geq(c, e), QuantLib::Error);
274 BOOST_CHECK_THROW(geq(d, e), QuantLib::Error);
275}
+ Here is the call graph for this function: