195 {
196
197 BOOST_TEST_MESSAGE("Testing general aggregation using functions for categories");
198
199
201
202
203 map<string, function<
bool(
string)>> categories;
204
205 set<pair<string, QuantLib::Size>> trades = {make_pair("trade_001", 0), make_pair("trade_003", 1),
206 make_pair("trade_004", 2), make_pair("trade_005", 3),
207 make_pair("trade_006", 4)};
208
209 for (const auto& trade : trades) {
210 categories[trade.first] = [&trade](string tradeId) { return tradeId == trade.first; };
211 }
212
213 categories["all_except_002"] = [&trades](string tradeId) {
214 for (auto it = trades.begin(); it != trades.end(); ++it) {
215 if (it->first == tradeId)
216 return true;
217 }
218 return false;
219 };
220
221
223 sAgg.aggregate(ss);
224
225
226 set<SensitivityRecord>
exp;
227 set<SensitivityRecord> res;
228
229
230 for (const auto& trade : trades) {
232 res = sAgg.sensitivities(trade.first);
233 BOOST_TEST_MESSAGE("Testing for category with single trade " << trade.first);
234 check(exp, res, trade.first);
235 }
236
237
238 BOOST_TEST_MESSAGE("Testing for category 'all_except_002'");
239 res = sAgg.sensitivities("all_except_002");
241}