Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cbomcengine.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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 qle/pricingengines/cbomcengine.hpp
20 \brief Monte Carlo pricing engine for the cashflow CDO instrument
21 */
22
23#pragma once
24
26
27#include <ql/experimental/credit/distribution.hpp>
28#include <ql/experimental/credit/randomdefaultmodel.hpp>
29#include <ql/math/distributions/bivariatenormaldistribution.hpp>
30#include <ql/math/distributions/normaldistribution.hpp>
31
32namespace QuantExt {
33using namespace QuantLib;
34using namespace std;
35
36//--------------------------------------------------------------------------
37//! CBO engine, Monte Carlo for the sample payoff
38/*!
39 This class implements the waterfall structures and Monte Carlo pricing
40 of the cash flow CBO.
41
42 For more information refer to the detailed QuantExt documentation.
43
44 \ingroup engines
45
46 \todo Return distributions as additional engine results
47 */
49public:
51 /*!
52 Random default model for generating samples of default
53 times for the portfolio of names
54 */
55 QuantLib::ext::shared_ptr<RandomDefaultModel> rdm,
56 //! Number of Monte Carlo samples
57 Size samples = 1000,
58 //! Discretization for resulting distributions
59 Size bins = 20,
60 //! npvError tolerance
61 double errorTolerance = 1.0e-6,
62 //! Periods from valuation date for which to return loss distributions
63 std::vector<QuantLib::Period> lossDistributionPeriods = std::vector<QuantLib::Period>())
64 : rdm_(rdm), samples_(samples), bins_(bins), errorTolerance_(errorTolerance),
65 lossDistributionPeriods_(lossDistributionPeriods) {}
66 void calculate() const override;
67
68private:
69 //! interest waterfall
70 void interestWaterfall(Size sampleIndex, Size dateIndex, const vector<Date>& dates,
71 map<Currency, vector<Cash>>& basketFlow, map<Currency, Cash>& trancheFlow,
72 map<Currency, vector<vector<Real>>>& balance, map<Currency, Real>& interest,
73 map<Currency, Real>& interestAcc, Real cureAmount) const;
74 //! icoc interest waterfall
75 void icocInterestWaterfall(Size i, // sample index
76 Size j, // date index
77 Size k, // tranche index
78 const vector<Date>& dates, map<Currency, vector<Cash>>& iFlows,
79 vector<map<Currency, Cash>>& tranches,
80 vector<map<Currency, vector<vector<Real>>>>& balances, Real cureAmount) const;
81
82 //! pricipal waterfall
83 void principalWaterfall(Size sampleIndex, Size dateIndex, const vector<Date>& dates,
84 map<Currency, vector<Cash>>& basketFlow, map<Currency, Cash>& trancheFlow,
85 map<Currency, vector<vector<Real>>>& balance, map<Currency, Real>& interest) const;
86 //! icoc cure amount
87 Real icocCureAmount(Size sampleIndex, Size dateIndex, Size trancheNo, Real basketNotional, Real basketInterest,
88 vector<map<Currency, vector<vector<Real>>>>& trancheBalances, vector<Real> trancheInterestRates,
89 Real icRatios, Real ocRatios) const;
90
91 //! Return dates on the CBO schedule that are closest to the requested \p lossDistributionPeriods
92 std::map<QuantLib::Date, std::string> getLossDistributionDates(const QuantLib::Date& valuationDate) const;
93
94 QuantLib::ext::shared_ptr<RandomDefaultModel> rdm_;
96 Size bins_;
98
99 //! Periods from valuation date for which to return loss distributions
100 std::vector<QuantLib::Period> lossDistributionPeriods_;
101};
102
103} // namespace QuantExt
collateralized bond obligation pricing engine
CBO base engine.
Definition: cboengine.hpp:36
CBO engine, Monte Carlo for the sample payoff.
Definition: cbomcengine.hpp:48
std::map< QuantLib::Date, std::string > getLossDistributionDates(const QuantLib::Date &valuationDate) const
Return dates on the CBO schedule that are closest to the requested lossDistributionPeriods.
MonteCarloCBOEngine(QuantLib::ext::shared_ptr< RandomDefaultModel > rdm, Size samples=1000, Size bins=20, double errorTolerance=1.0e-6, std::vector< QuantLib::Period > lossDistributionPeriods=std::vector< QuantLib::Period >())
Definition: cbomcengine.hpp:50
void calculate() const override
void interestWaterfall(Size sampleIndex, Size dateIndex, const vector< Date > &dates, map< Currency, vector< Cash > > &basketFlow, map< Currency, Cash > &trancheFlow, map< Currency, vector< vector< Real > > > &balance, map< Currency, Real > &interest, map< Currency, Real > &interestAcc, Real cureAmount) const
interest waterfall
Definition: cbomcengine.cpp:30
QuantLib::ext::shared_ptr< RandomDefaultModel > rdm_
Definition: cbomcengine.hpp:94
void principalWaterfall(Size sampleIndex, Size dateIndex, const vector< Date > &dates, map< Currency, vector< Cash > > &basketFlow, map< Currency, Cash > &trancheFlow, map< Currency, vector< vector< Real > > > &balance, map< Currency, Real > &interest) const
pricipal waterfall
std::vector< QuantLib::Period > lossDistributionPeriods_
Periods from valuation date for which to return loss distributions.
Real icocCureAmount(Size sampleIndex, Size dateIndex, Size trancheNo, Real basketNotional, Real basketInterest, vector< map< Currency, vector< vector< Real > > > > &trancheBalances, vector< Real > trancheInterestRates, Real icRatios, Real ocRatios) const
icoc cure amount
void icocInterestWaterfall(Size i, Size j, Size k, const vector< Date > &dates, map< Currency, vector< Cash > > &iFlows, vector< map< Currency, Cash > > &tranches, vector< map< Currency, vector< vector< Real > > > > &balances, Real cureAmount) const
icoc interest waterfall
Definition: cbomcengine.cpp:72