Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BondBasket Class Reference

Bond Basket. More...

#include <qle/instruments/bondbasket.hpp>

+ Collaboration diagram for BondBasket:

Public Member Functions

 BondBasket (const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > &qlBonds, const std::map< std::string, double > &recoveries, const std::map< std::string, double > &multipliers, const std::map< std::string, QuantLib::Handle< QuantLib::YieldTermStructure > > &yieldTermStructures, const std::map< std::string, Currency > &currencies, const QuantLib::ext::shared_ptr< QuantLib::Pool > pool, Currency baseCcy, const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &fxIndexMap, const QuantLib::Date &reinvestmentEndDate, const std::map< std::string, std::vector< double > > &reinvestmentScalar, const std::map< std::string, std::vector< std::string > > &flowType)
 
const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > & bonds () const
 Inspectors. More...
 
const QuantLib::ext::shared_ptr< QuantLib::Pool > & pool () const
 
const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > & fxIndexMap () const
 
const std::set< QuantLib::Currency > unique_currencies () const
 
const double recoveryRate (const std::string &name) const
 
const double multiplier (const std::string &name) const
 
Real convert (Real amount, Currency ccy, Date date=Date())
 
void setGrid (std::vector< Date > dates)
 
std::map< Currency, std::vector< Cash > > scenarioCashflow (std::vector< Date > dates)
 
std::map< Currency, std::vector< Cash > > scenarioInterestflow (std::vector< Date > dates)
 
std::map< Currency, std::vector< Cash > > scenarioPrincipalflow (std::vector< Date > dates)
 
std::map< Currency, std::vector< Real > > scenarioRemainingNotional (std::vector< Date > dates)
 
std::map< Currency, std::vector< Cash > > scenarioLossflow (std::vector< Date > dates)
 
std::map< Currency, std::vector< Cash > > scenarioFeeflow (const std::vector< QuantLib::Date > &dates)
 
void fillFlowMaps ()
 

Private Member Functions

const double getScalar (const std::string &name, const QuantLib::Date &currentDate) const
 
const QuantLib::Handle< QuantLib::YieldTermStructure > yts (const std::string &name) const
 
const Currency currency (const std::string &name) const
 
const std::vector< double > reinvestmentScalar (const std::string &name) const
 
const std::string flowType (const std::string &name, int idx) const
 
const QuantLib::ext::shared_ptr< QuantExt::FxIndexfxIndex (const std::string &name) const
 

Private Attributes

const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > qlBonds_
 
const std::map< std::string, double > recoveries_
 
const std::map< std::string, double > multipliers_
 
const std::map< std::string, QuantLib::Handle< QuantLib::YieldTermStructure > > yieldTermStructures_
 
const std::map< std::string, QuantLib::Currency > currencies_
 
const QuantLib::ext::shared_ptr< QuantLib::Pool > pool_
 
const Currency baseCcy_
 
const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > fxIndexMap_
 
const Date reinvestmentEndDate_
 
const std::map< std::string, std::vector< double > > reinvestmentScalar_
 
const std::map< std::string, std::vector< std::string > > flowType_
 
std::set< QuantLib::Currency > unique_currencies_
 
std::vector< Date > grid_
 
std::map< std::string, std::vector< int > > cashflow2grid_
 
std::map< std::string, std::vector< int > > interestflow2grid_
 
std::map< std::string, std::vector< int > > notionalflow2grid_
 
std::map< std::string, std::vector< int > > feeflow2grid_
 
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > cashflows_
 
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > interestFlows_
 
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > notionalFlows_
 
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > feeFlows_
 

Detailed Description

Bond Basket.

This class holds a basket of defaultable bonds along with the pool of relevant names. There may be more bonds than names involved, e.g. several different bonds with same issuer.

The class provides tools for evaluating basket cash flows of different kinds (interest, principal) for scenarios of default times stored for all names involved in the Pool structure.

For further information refer to the detailed QuantExt documentation.

Definition at line 71 of file bondbasket.hpp.

Constructor & Destructor Documentation

◆ BondBasket()

BondBasket ( const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > &  qlBonds,
const std::map< std::string, double > &  recoveries,
const std::map< std::string, double > &  multipliers,
const std::map< std::string, QuantLib::Handle< QuantLib::YieldTermStructure > > &  yieldTermStructures,
const std::map< std::string, Currency > &  currencies,
const QuantLib::ext::shared_ptr< QuantLib::Pool >  pool,
Currency  baseCcy,
const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > &  fxIndexMap,
const QuantLib::Date &  reinvestmentEndDate,
const std::map< std::string, std::vector< double > > &  reinvestmentScalar,
const std::map< std::string, std::vector< std::string > > &  flowType 
)
Parameters
qlBondsmap of QuantLib bonds
recoveriesrecoveries per bonds
multipliersmultipliers per bonds
yieldTermStructuresdiscount curves per bonds
currenciescurrencies per bonds
poolPool storing default time for all names involved in the basekt above
baseCcyBase currency
fxIndexMapForex structure to compute spot and forward FX rates
reinvestmentEndDateend of reinvestment period
reinvestmentScalarscalar for reinvestment period per bonds
flowTypeflow types of cashflows per bonds

Definition at line 130 of file bondbasket.cpp.

141 : qlBonds_(qlBonds),
142 recoveries_(recoveries),
143 multipliers_(multipliers),
144 yieldTermStructures_(yieldTermStructures),
145 currencies_(currencies),
146 pool_(pool),
147 baseCcy_(baseCcy),
149 reinvestmentEndDate_(reinvestmentEndDate),
152 {
153
154 QL_REQUIRE(!qlBonds_.empty(), "no bonds given");
155 QL_REQUIRE(qlBonds_.size() == recoveries_.size(), "mismatch number bonds vs recoveries");
156 QL_REQUIRE(qlBonds_.size() == multipliers_.size(), "mismatch number bonds vs multipliers");
157 QL_REQUIRE(qlBonds_.size() == yieldTermStructures_.size(), "mismatch number bonds vs yieldTermStructures");
158 QL_REQUIRE(qlBonds_.size() == currencies_.size(), "mismatch number bonds vs currencies");
159
160 for (const auto& ccy : currencies_)
161 unique_currencies_.insert(ccy.second);
162
163 grid_ = vector<Date>();
164
165 }
const QuantLib::ext::shared_ptr< QuantLib::Pool > pool_
Definition: bondbasket.hpp:144
const Date reinvestmentEndDate_
Definition: bondbasket.hpp:147
const Currency baseCcy_
Definition: bondbasket.hpp:145
std::vector< Date > grid_
Definition: bondbasket.hpp:152
const std::map< std::string, std::vector< double > > reinvestmentScalar_
Definition: bondbasket.hpp:148
const std::map< std::string, double > recoveries_
Definition: bondbasket.hpp:140
const std::vector< double > reinvestmentScalar(const std::string &name) const
Definition: bondbasket.cpp:199
const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > fxIndexMap_
Definition: bondbasket.hpp:146
const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > qlBonds_
Definition: bondbasket.hpp:139
std::set< QuantLib::Currency > unique_currencies_
Definition: bondbasket.hpp:151
const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > & fxIndexMap() const
Definition: bondbasket.hpp:104
const std::map< std::string, QuantLib::Currency > currencies_
Definition: bondbasket.hpp:143
const std::map< std::string, std::vector< std::string > > flowType_
Definition: bondbasket.hpp:149
const std::string flowType(const std::string &name, int idx) const
Definition: bondbasket.cpp:206
const QuantLib::ext::shared_ptr< QuantLib::Pool > & pool() const
Definition: bondbasket.cpp:167
const std::map< std::string, QuantLib::Handle< QuantLib::YieldTermStructure > > yieldTermStructures_
Definition: bondbasket.hpp:142
const std::map< std::string, double > multipliers_
Definition: bondbasket.hpp:141

Member Function Documentation

◆ bonds()

const std::map< std::string, QuantLib::ext::shared_ptr< QuantLib::Bond > > & bonds ( ) const

Inspectors.

Vector of risky bonds

Definition at line 100 of file bondbasket.hpp.

100{ return qlBonds_; }

◆ pool()

const QuantLib::ext::shared_ptr< Pool > & pool ( ) const

Pool of names with associated default times

Definition at line 167 of file bondbasket.cpp.

167 {
168 return pool_;
169 }

◆ fxIndexMap()

const std::map< std::string, QuantLib::ext::shared_ptr< QuantExt::FxIndex > > & fxIndexMap ( ) const

Forex structure

Definition at line 104 of file bondbasket.hpp.

104{ return fxIndexMap_;}

◆ unique_currencies()

const std::set< QuantLib::Currency > unique_currencies ( ) const

Unique currencies involved

Definition at line 106 of file bondbasket.hpp.

106{ return unique_currencies_; }

◆ recoveryRate()

const double recoveryRate ( const std::string &  name) const

Recovery rate for given name

Definition at line 171 of file bondbasket.cpp.

171 {
172 auto it = recoveries_.find(name);
173 if(it != recoveries_.end())
174 return it->second;
175 QL_FAIL("no recovery value for bond " << name);
176 };
+ Here is the caller graph for this function:

◆ multiplier()

const double multiplier ( const std::string &  name) const

Multiplier for given name

Definition at line 178 of file bondbasket.cpp.

178 {
179 auto it = multipliers_.find(name);
180 if(it != multipliers_.end())
181 return it->second;
182 QL_FAIL("no multiplier for bond " << name);
183 };
+ Here is the caller graph for this function:

◆ convert()

Real convert ( Real  amount,
Currency  ccy,
Date  date = Date() 
)

FX conversion

Definition at line 115 of file bondbasket.cpp.

115 {
116
117 if(date == Date())
118 date = Settings::instance().evaluationDate();
119
120 if (ccy == baseCcy_)
121 return amount;
122 else {
123 std::string code = ccy.code();
124 double fxRate = fxIndex(code)->fixing(date, false);
125 double inBase = fxRate * amount;
126 return inBase;
127 }
128 }
const QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex(const std::string &name) const
Definition: bondbasket.cpp:213
+ Here is the call graph for this function:

◆ setGrid()

void setGrid ( std::vector< Date >  dates)

Set the date grid for mapping cash flows. Store for each bond cash flow date the associated date grid bucket.

Definition at line 220 of file bondbasket.cpp.

220 {
221 grid_ = dates;
222 for (auto bond : qlBonds_) {
223 string name = bond.first;
224 cashflow2grid_[name].resize(cashflows_[name].size(), -1);
225 for (Size j = 0; j < cashflows_[name].size(); j++) {
226 Date d = cashflows_[name][j]->date();
227 for (Size k = 1; k < dates.size(); k++) {
228 if (d > dates[k-1] && d <= dates[k]) {
229 cashflow2grid_[name][j] = k;
230 continue;
231 }
232 }
233 }
234 interestflow2grid_[name].resize(interestFlows_[name].size(),-1);
235 for (Size j = 0; j < interestFlows_[name].size(); j++) {
236 Date d = interestFlows_[name][j]->date();
237 for (Size k = 1; k < dates.size(); k++) {
238 if (d > dates[k-1] && d <= dates[k]) {
239 interestflow2grid_[name][j] = k;
240 continue;
241 }
242 }
243 }
244 notionalflow2grid_[name].resize(notionalFlows_[name].size(), -1);
245 for (Size j = 0; j < notionalFlows_[name].size(); j++) {
246 Date d = notionalFlows_[name][j]->date();
247 for (Size k = 1; k < dates.size(); k++) {
248 if (d > dates[k-1] && d <= dates[k]) {
249 notionalflow2grid_[name][j] = k;
250 continue;
251 }
252 }
253 }
254 feeflow2grid_[name].resize(feeFlows_[name].size(), -1);
255 for (Size j = 0; j < feeFlows_[name].size(); j++) {
256 Date d = feeFlows_[name][j]->date();
257 for (Size k = 1; k < dates.size(); k++) {
258 if (d > dates[k-1] && d <= dates[k]) {
259 feeflow2grid_[name][j] = k;
260 continue;
261 }
262 }
263 }
264 }
265 }
std::map< std::string, std::vector< int > > interestflow2grid_
Definition: bondbasket.hpp:155
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > feeFlows_
Definition: bondbasket.hpp:162
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > notionalFlows_
Definition: bondbasket.hpp:161
std::map< std::string, std::vector< int > > cashflow2grid_
Definition: bondbasket.hpp:154
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > interestFlows_
Definition: bondbasket.hpp:160
std::map< std::string, std::vector< int > > notionalflow2grid_
Definition: bondbasket.hpp:156
std::map< std::string, std::vector< int > > feeflow2grid_
Definition: bondbasket.hpp:157
std::map< std::string, std::vector< ext::shared_ptr< QuantLib::CashFlow > > > cashflows_
Definition: bondbasket.hpp:159

◆ scenarioCashflow()

std::map< Currency, vector< Cash > > scenarioCashflow ( std::vector< Date >  dates)

Definition at line 268 of file bondbasket.cpp.

268 {
269 QL_REQUIRE(grid_.size() > 0, "grid not set");
270 Date today = Settings::instance().evaluationDate();
271 map<Currency,vector<Cash> > cf;
272 for (const auto & ccy : unique_currencies_)
273 cf[ccy].resize(dates.size(), Cash());
274 for (const auto & bond : qlBonds_) {
275 string name = bond.first;
276 DayCounter dc = yts(name)->dayCounter();
277 Currency ccy = currency(name);
278 Real defaultTime = pool_->getTime(name);
279 Real maturityTime = dc.yearFraction(today, bond.second->maturityDate());
280 for (Size j = 0; j < cashflows_[name].size(); j++) {
281 Date d = cashflows_[name][j]->date();
282 Real t = dc.yearFraction(today, d);
283
284 if (t < defaultTime) {
285 Size k = cashflow2grid_[name][j];
286 //QL_REQUIRE(k >= 0 && k < grid_.size(), "k out of range");
287 if (k < grid_.size()) {
288 cf[ccy][k].flow_ += cashflows_[name][j]->amount();
289 cf[ccy][k].discountedFlow_
290 += cashflows_[name][j]->amount()
291 * yts(name)->discount(t);
292 }
293 }
294 else break;
295 }
296 if (defaultTime < maturityTime) {
297 for (Size k = 1; k < dates.size(); k++) {
298 Real t1 = dc.yearFraction(today, dates[k-1]);
299 Real t2 = dc.yearFraction(today, dates[k]);
300 if (defaultTime >= t1 && defaultTime < t2) {
301 cf[ccy][k].flow_
302 += recoveryRate(name) * bond.second->notional(dates[k-1]) * multiplier(name);
303 cf[ccy][k].discountedFlow_
304 += recoveryRate(name) * bond.second->notional(dates[k-1]) * multiplier(name)
305 * yts(name)->discount(defaultTime);
306 }
307 }
308 }
309 }
310 return cf;
311 }
const double multiplier(const std::string &name) const
Definition: bondbasket.cpp:178
const Currency currency(const std::string &name) const
Definition: bondbasket.cpp:192
const double recoveryRate(const std::string &name) const
Definition: bondbasket.cpp:171
const QuantLib::Handle< QuantLib::YieldTermStructure > yts(const std::string &name) const
Definition: bondbasket.cpp:185
+ Here is the call graph for this function:

◆ scenarioInterestflow()

std::map< Currency, vector< Cash > > scenarioInterestflow ( std::vector< Date >  dates)

Definition at line 314 of file bondbasket.cpp.

314 {
315 QL_REQUIRE(grid_.size() > 0, "grid not set");
316 Date today = Settings::instance().evaluationDate();
317 map<Currency,vector<Cash> > cf;
318 for (const auto & ccy : unique_currencies_)
319 cf[ccy].resize(dates.size(), Cash());
320 for (const auto & bond : qlBonds_) {
321 string name = bond.first;
322 DayCounter dc = yts(name)->dayCounter();
323 Currency ccy = currency(name);
324 Real defaultTime = pool_->getTime(name);
325 for (Size j = 0; j < interestFlows_[name].size(); j++) {
326 Date d = interestFlows_[name][j]->date();
327 Real t = dc.yearFraction(today, d);
328 if (t < defaultTime) {
329 Size k = interestflow2grid_[name][j];
330 //QL_REQUIRE(k >= 0 && k < grid_.size(), "k out of range");
331 if (k < grid_.size()) {
332 cf[ccy][k].flow_ += interestFlows_[name][j]->amount();
333 cf[ccy][k].discountedFlow_
334 += interestFlows_[name][j]->amount()
335 * yts(name)->discount(t);
336 }
337 }
338 else break;
339 }
340 }
341 return cf;
342 }
+ Here is the call graph for this function:

◆ scenarioPrincipalflow()

std::map< Currency, vector< Cash > > scenarioPrincipalflow ( std::vector< Date >  dates)

Definition at line 345 of file bondbasket.cpp.

345 {
346 QL_REQUIRE(grid_.size() > 0, "grid not set");
347 Date today = Settings::instance().evaluationDate();
348 map<Currency,vector<Cash> > cf;
349 for (const auto & ccy : unique_currencies_)
350 cf[ccy].resize(dates.size(), Cash());
351 for (const auto & bond : qlBonds_) {
352 string name = bond.first;
353 DayCounter dc = yts(name)->dayCounter();
354 Currency ccy = currency(name);
355 Real defaultTime = pool_->getTime(name);
356 Real maturityTime = dc.yearFraction(today, bond.second->maturityDate());
357 for (Size j = 0; j < notionalFlows_[name].size(); j++) {
358 Date d = notionalFlows_[name][j]->date();
359 Real t = dc.yearFraction(today, d);
360 if (t < defaultTime) {
361 Size k = notionalflow2grid_[name][j];
362 //QL_REQUIRE(k >= 0 && k < grid_.size(), "k out of range");
363 if (k < grid_.size()) {
364 cf[ccy][k].flow_ += notionalFlows_[name][j]->amount();
365 cf[ccy][k].discountedFlow_
366 += notionalFlows_[name][j]->amount()
367 * yts(name)->discount(t);
368 }
369 }
370 else break;
371 }
372 if (defaultTime < maturityTime) {
373 for (Size k = 1; k < dates.size(); k++) {
374 Real t1 = dc.yearFraction(today, dates[k-1]);
375 Real t2 = dc.yearFraction(today, dates[k]);
376 if (defaultTime >= t1 &&
377 defaultTime < t2) {
378 cf[ccy][k].flow_
379 += recoveryRate(name) * bond.second->notional(dates[k-1]) * multiplier(name);
380 cf[ccy][k].discountedFlow_
381 += recoveryRate(name) * bond.second->notional(dates[k-1]) * multiplier(name)
382 * yts(name)->discount(defaultTime);
383 }
384 }
385 }
386 }
387 return cf;
388 }
+ Here is the call graph for this function:

◆ scenarioRemainingNotional()

std::map< Currency, vector< Real > > scenarioRemainingNotional ( std::vector< Date >  dates)

Definition at line 451 of file bondbasket.cpp.

451 {
452 QL_REQUIRE(grid_.size() > 0, "grid not set");
453 Date today = Settings::instance().evaluationDate();
454 map<Currency,vector<Real> > cf;
455 for (const auto & ccy : unique_currencies_)
456 cf[ccy].resize(dates.size(), 0.0);
457 for (const auto & bond : qlBonds_) {
458 string name = bond.first;
459 DayCounter dc = yts(name)->dayCounter();
460 Currency ccy = currency(name);
461 Real defaultTime = pool_->getTime(name);
462 for (Size k = 1; k < dates.size(); k++) {
463 Real t1 = dc.yearFraction(today, dates[k]);
464 if (defaultTime >= t1) {
465 cf[ccy][k] += bond.second->notional(dates[k]) * multiplier(name) * getScalar(name, dates[k]);
466 }
467 }
468 }
469 return cf;
470 }
const double getScalar(const std::string &name, const QuantLib::Date &currentDate) const
Definition: bondbasket.cpp:28
+ Here is the call graph for this function:

◆ scenarioLossflow()

std::map< Currency, vector< Cash > > scenarioLossflow ( std::vector< Date >  dates)

Definition at line 420 of file bondbasket.cpp.

420 {
421 QL_REQUIRE(grid_.size() > 0, "grid not set");
422 Date today = Settings::instance().evaluationDate();
423 map<Currency,vector<Cash> > cf;
424 for (const auto & ccy : unique_currencies_)
425 cf[ccy].resize(dates.size(), Cash());
426 for (const auto & bond : qlBonds_) {
427 string name = bond.first;
428 DayCounter dc = yts(name)->dayCounter();
429 Currency ccy = currency(name);
430 Real defaultTime = pool_->getTime(name);
431 Real maturityTime = dc.yearFraction(today, bond.second->maturityDate());
432 if (defaultTime < maturityTime) {
433 for (Size k = 1; k < dates.size(); k++) {
434 Real t1 = dc.yearFraction(today, dates[k-1]);
435 Real t2 = dc.yearFraction(today, dates[k]);
436 if (defaultTime >= t1 &&
437 defaultTime < t2) {
438 cf[ccy][k].flow_
439 += (1.0 - recoveryRate(name)) * bond.second->notional(dates[k-1]) * multiplier(name);
440 cf[ccy][k].discountedFlow_
441 += (1.0 - recoveryRate(name)) * bond.second->notional(dates[k-1]) * multiplier(name)
442 * yts(name)->discount(defaultTime);
443 }
444 }
445 }
446 }
447 return cf;
448 }
+ Here is the call graph for this function:

◆ scenarioFeeflow()

std::map< Currency, vector< Cash > > scenarioFeeflow ( const std::vector< QuantLib::Date > &  dates)

Definition at line 390 of file bondbasket.cpp.

390 {
391 QL_REQUIRE(grid_.size() > 0, "grid not set");
392 Date today = Settings::instance().evaluationDate();
393 map<Currency,vector<Cash> > cf;
394 for (const auto & ccy : unique_currencies_)
395 cf[ccy].resize(dates.size(), Cash());
396 for (const auto & bond : qlBonds_) {
397 string name = bond.first;
398 DayCounter dc = yts(name)->dayCounter();
399 Currency ccy = currency(name);
400 Real defaultTime = pool_->getTime(name);
401 for (Size j = 0; j < feeFlows_[name].size(); j++) {
402 Date d = feeFlows_[name][j]->date();
403 Real t = dc.yearFraction(today, d);
404 if (t < defaultTime) {
405 Size k = feeflow2grid_[name][j];
406 if (k < dates.size()) {
407 cf[ccy][k].flow_ += feeFlows_[name][j]->amount();
408 cf[ccy][k].discountedFlow_
409 += feeFlows_[name][j]->amount() * yts(name)->discount(t);
410
411 }
412 }
413 else break;
414 }
415 }
416 return cf;
417 }
+ Here is the call graph for this function:

◆ fillFlowMaps()

void fillFlowMaps ( )

Definition at line 43 of file bondbasket.cpp.

43 {
44
45 cashflows_.clear();
46 interestFlows_.clear();
47 notionalFlows_.clear();
48 feeFlows_.clear();
49
50 for(auto bond : qlBonds_){
51
52 std::string name = bond.first;
53 double multi = multiplier(name);
54 vector<double> scalar = reinvestmentScalar(name);
55 Leg leg = bond.second->cashflows();
56
57 std::vector<ext::shared_ptr<QuantLib::CashFlow> > cashflows;
58 std::vector<ext::shared_ptr<QuantLib::CashFlow> > interestFlows;
59 std::vector<ext::shared_ptr<QuantLib::CashFlow> > notionalFlows;
60 std::vector<ext::shared_ptr<QuantLib::CashFlow> > feeFlows;
61
62 for (size_t j = 0; j < leg.size(); j++) {
63
64 QuantLib::ext::shared_ptr<QuantLib::CashFlow> ptrFlow = leg[j];
65
66 if(flowType(name,j) == "int"){
67
68 QuantLib::ext::shared_ptr<QuantLib::Coupon> ptrCoupon =
69 QuantLib::ext::dynamic_pointer_cast<QuantLib::Coupon>(ptrFlow);
70 QL_REQUIRE(ptrCoupon, "expected couopn type");
71
72 QuantLib::ext::shared_ptr<QuantExt::ScaledCoupon> newPtr( new QuantExt::ScaledCoupon(multi * scalar[j], ptrCoupon ));
73 interestFlows.push_back(newPtr);
74 cashflows.push_back(newPtr);
75
76 } else if(flowType(name,j) == "xnl"){
77
78 double amort = 1.0;
79 if(reinvestmentEndDate_ > ptrFlow->date())
80 amort = 0.0;
81
82 ext::shared_ptr<CashFlow>
83 flow(new SimpleCashFlow(ptrFlow->amount() * multi * scalar[j] * amort, ptrFlow->date()));
84 notionalFlows.push_back(flow);
85 cashflows.push_back(flow);
86
87 } else if (flowType(name,j) == "fee"){
88
89 ext::shared_ptr<CashFlow>
90 flow(new SimpleCashFlow(ptrFlow->amount() * multi * scalar[j], ptrFlow->date()));
91 feeFlows.push_back(flow);
92 cashflows.push_back(flow);
93
94 } else {
95 //ALOG("bond " << name << " leg " << j << " paymentDate " << leg[j]->date() << " could not be assigned");
96 }
97
98 }//leg - j
99 cashflows_[name] = cashflows;
100 notionalFlows_[name] = notionalFlows;
101 feeFlows_[name] = feeFlows;
102 interestFlows_[name] = interestFlows;
103 }//bonds - b
104 }//void BondBasket::fillFlowMaps()
+ Here is the call graph for this function:

◆ getScalar()

const double getScalar ( const std::string &  name,
const QuantLib::Date &  currentDate 
) const
private

Definition at line 28 of file bondbasket.cpp.

28 {
29 double result = -1.0;
30 for(auto& bond : qlBonds_){
31 if(bond.first == name){
32 const QuantLib::Leg& leg = bond.second->cashflows();
33 vector<Real> scalar = reinvestmentScalar(name);
34 for(size_t d = 1; d < leg.size(); d++){
35 if(leg[d-1]->date() < currentDate && leg[d]->date() >= currentDate)
36 result = scalar[d];
37 }
38 }
39 }
40 return result;
41 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ yts()

const QuantLib::Handle< QuantLib::YieldTermStructure > yts ( const std::string &  name) const
private

Definition at line 185 of file bondbasket.cpp.

185 {
186 auto it = yieldTermStructures_.find(name);
187 if(it != yieldTermStructures_.end())
188 return it->second;
189 QL_FAIL("no yieldTermStructure for bond " << name);
190 }
+ Here is the caller graph for this function:

◆ currency()

const Currency currency ( const std::string &  name) const
private

Definition at line 192 of file bondbasket.cpp.

192 {
193 auto it = currencies_.find(name);
194 if(it != currencies_.end())
195 return it->second;
196 QL_FAIL("no currency for bond " << name);
197 }
+ Here is the caller graph for this function:

◆ reinvestmentScalar()

const vector< double > reinvestmentScalar ( const std::string &  name) const
private

Definition at line 199 of file bondbasket.cpp.

199 {
200 auto it = reinvestmentScalar_.find(name);
201 if(it != reinvestmentScalar_.end())
202 return it->second;
203 QL_FAIL("no reinvestmentScalar for bond " << name);
204 }
+ Here is the caller graph for this function:

◆ flowType()

const string flowType ( const std::string &  name,
int  idx 
) const
private

Definition at line 206 of file bondbasket.cpp.

206 {
207 auto it = flowType_.find(name);
208 if(it != flowType_.end())
209 return it->second[idx];
210 QL_FAIL("no flowType for bond " << name);
211 }
+ Here is the caller graph for this function:

◆ fxIndex()

const QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex ( const std::string &  name) const
private

Definition at line 213 of file bondbasket.cpp.

213 {
214 auto it = fxIndexMap_.find(name);
215 if(it != fxIndexMap_.end())
216 return it->second;
217 QL_FAIL("no fxIndex for bond " << name);
218 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ qlBonds_

const std::map<std::string, QuantLib::ext::shared_ptr<QuantLib::Bond> > qlBonds_
private

Definition at line 139 of file bondbasket.hpp.

◆ recoveries_

const std::map<std::string, double> recoveries_
private

Definition at line 140 of file bondbasket.hpp.

◆ multipliers_

const std::map<std::string, double> multipliers_
private

Definition at line 141 of file bondbasket.hpp.

◆ yieldTermStructures_

const std::map<std::string, QuantLib::Handle<QuantLib::YieldTermStructure> > yieldTermStructures_
private

Definition at line 142 of file bondbasket.hpp.

◆ currencies_

const std::map<std::string, QuantLib::Currency> currencies_
private

Definition at line 143 of file bondbasket.hpp.

◆ pool_

const QuantLib::ext::shared_ptr<QuantLib::Pool> pool_
private

Definition at line 144 of file bondbasket.hpp.

◆ baseCcy_

const Currency baseCcy_
private

Definition at line 145 of file bondbasket.hpp.

◆ fxIndexMap_

const std::map<std::string, QuantLib::ext::shared_ptr<QuantExt::FxIndex> > fxIndexMap_
private

Definition at line 146 of file bondbasket.hpp.

◆ reinvestmentEndDate_

const Date reinvestmentEndDate_
private

Definition at line 147 of file bondbasket.hpp.

◆ reinvestmentScalar_

const std::map<std::string, std::vector<double> > reinvestmentScalar_
private

Definition at line 148 of file bondbasket.hpp.

◆ flowType_

const std::map<std::string, std::vector<std::string> > flowType_
private

Definition at line 149 of file bondbasket.hpp.

◆ unique_currencies_

std::set<QuantLib::Currency> unique_currencies_
private

Definition at line 151 of file bondbasket.hpp.

◆ grid_

std::vector<Date> grid_
private

Definition at line 152 of file bondbasket.hpp.

◆ cashflow2grid_

std::map<std::string, std::vector<int> > cashflow2grid_
private

Definition at line 154 of file bondbasket.hpp.

◆ interestflow2grid_

std::map<std::string, std::vector<int> > interestflow2grid_
private

Definition at line 155 of file bondbasket.hpp.

◆ notionalflow2grid_

std::map<std::string, std::vector<int> > notionalflow2grid_
private

Definition at line 156 of file bondbasket.hpp.

◆ feeflow2grid_

std::map<std::string, std::vector<int> > feeflow2grid_
private

Definition at line 157 of file bondbasket.hpp.

◆ cashflows_

std::map<std::string, std::vector<ext::shared_ptr<QuantLib::CashFlow> > > cashflows_
private

Definition at line 159 of file bondbasket.hpp.

◆ interestFlows_

std::map<std::string, std::vector<ext::shared_ptr<QuantLib::CashFlow> > > interestFlows_
private

Definition at line 160 of file bondbasket.hpp.

◆ notionalFlows_

std::map<std::string, std::vector<ext::shared_ptr<QuantLib::CashFlow> > > notionalFlows_
private

Definition at line 161 of file bondbasket.hpp.

◆ feeFlows_

std::map<std::string, std::vector<ext::shared_ptr<QuantLib::CashFlow> > > feeFlows_
private

Definition at line 162 of file bondbasket.hpp.