credit.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2010 Roland Lichters
5  Copyright (C) 2014 Jose Aparicio
6 
7  This file is part of QuantLib, a free-software/open-source library
8  for financial quantitative analysts and developers - http://quantlib.org/
9 
10  QuantLib is free software: you can redistribute it and/or modify it
11  under the terms of the QuantLib license. You should have received a
12  copy of the license along with this program; if not, please email
13  <quantlib-dev@lists.sf.net>. The license is also available online at
14  <http://quantlib.org/license.shtml>.
15 
16  This program is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  FOR A PARTICULAR PURPOSE. See the license for more details.
19 */
20 
21 #ifndef qla_credit_hpp
22 #define qla_credit_hpp
23 
24 #include <qlo/baseinstruments.hpp>
28 #include <qlo/schedule.hpp>
29 #include <qlo/pricingengines.hpp>
30 #include <qlo/quote.hpp>
31 
32 #include <ql/handle.hpp>
33 #include <ql/time/daycounter.hpp>
34 #include <ql/time/schedule.hpp>
35 #include <ql/time/businessdayconvention.hpp>
36 #include <ql/types.hpp>
37 #include <ql/instruments/creditdefaultswap.hpp>
38 #include <ql/termstructures/credit/defaultprobabilityhelpers.hpp>
39 #include <ql/currency.hpp>
40 #include <ql/experimental/credit/issuer.hpp>
41 #include <ql/experimental/credit/recoveryratequote.hpp>
42 
43 namespace QuantLib {
44  class Quote;
45  class Date;
46  class Basket;
47 }
48 
49 namespace QuantLibAddin {
50 
55  class Issuer
56  : public ObjectHandler::LibraryObject<QuantLib::Issuer> {
57  public:
58  Issuer(
59  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
60  const boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& dfts,
61  const boost::shared_ptr<QuantLib::DefaultEventSet>& evtSet,
62  bool permanent
63  );
64  };
65 
67  : public ObjectHandler::LibraryObject<QuantLib::DefaultEventSet> {
68  public:
70  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
71  const std::string& eventType,
72  const QuantLib::Date& eventDate,
73  const QuantLib::Currency& cur,
74  QuantLib::Seniority sen,
75  const QuantLib::Date& settleDate,
76  QuantLib::Real settledRecovery,
77  bool permanent
78  );
79  };
80 
81  // To do, implement a Seniority inspector in credit.xml
82  class RecoveryRateQuote : public Quote {
83  public:
84  RecoveryRateQuote(const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
85  QuantLib::Seniority sen,
86  QuantLib::Real value,
87  bool permanent);
88  QuantLib::Real setValue(QuantLib::Real value);
89  private:
90  boost::shared_ptr<QuantLib::RecoveryRateQuote> recoveryQuote_;
91  };
92 
93  //class CreditDefaultSwap : public Instrument {
94  //public:
95  // CreditDefaultSwap(
96  // const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
97  // QuantLib::Protection::Side side,
98  // QuantLib::Real notional,
99  // QuantLib::Rate upfront,
100  // QuantLib::Rate spread,
101  // const boost::shared_ptr<QuantLib::Schedule>& schedule,
102  // QuantLib::BusinessDayConvention paymentConvention,
103  // const QuantLib::DayCounter& dayCounter,
104  // bool settlesAccrual,
105  // bool paysAtDefaultTime,
106  // const QuantLib::Date& protectionStart,
107  // const QuantLib::Date& upfrontDate,
108  // bool permanent);
109  //};
110 
112  public:
114  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
116  QuantLib::Real recoveryRate,
118  bool permanent);
119  };
120 
121 
123  : public ObjectHandler::LibraryObject<QuantLib::DefaultProbabilityHelper> {
124  protected:
125  OH_LIB_CTOR(DefaultProbabilityHelper, QuantLib::DefaultProbabilityHelper);
126  };
127 
129  public:
131  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
133  const QuantLib::Period& period,
134  QuantLib::Natural settlementDays,
135  const QuantLib::Calendar& calendar,
136  QuantLib::Frequency frequency,
137  QuantLib::BusinessDayConvention paymentConvention,
138  QuantLib::DateGeneration::Rule rule,
139  const QuantLib::DayCounter& dayCounter,
140  QuantLib::Real recoveryRate,
142  bool settlesAccrual,
143  bool paysAtDefaultTime,
144  bool permanent);
145  };
146 
148  public:
150  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
152  QuantLib::Rate runningSpread,
153  const QuantLib::Period& period,
154  QuantLib::Natural settlementDays,
155  const QuantLib::Calendar& calendar,
156  QuantLib::Frequency frequency,
157  QuantLib::BusinessDayConvention paymentConvention,
158  QuantLib::DateGeneration::Rule rule,
159  const QuantLib::DayCounter& dayCounter,
160  QuantLib::Real recoveryRate,
162  QuantLib::Natural upfrontSettlementDays,
163  bool settlesAccrual,
164  bool paysAtDefaultTime,
165  bool permanent);
166  };
167 
169  : public DefaultProbabilityTermStructure {
170  public:
172  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
173  const std::vector<QuantLib::Date>& dates,
174  const std::vector<QuantLib::Rate>& hazardRates,
175  const QuantLib::DayCounter& dayCounter,
176  bool permanent);
177  const std::vector<QuantLib::Time>& times() const;
178  const std::vector<QuantLib::Date>& dates() const;
179  const std::vector<QuantLib::Real>& data() const;
180  };
181 
182  // Bootstrapped piecewise flat hazard rate curve
183  // traits = hazard rates
184  // To do: add a Registry Manager factory once the number of options in
185  // the combination of interpolation traits and algorithm grows.
186  class PiecewiseHazardRateCurve : public DefaultProbabilityTermStructure {
187  public:
189  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
190  const std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityHelper> >& helpers,
191  const QuantLib::DayCounter& dayCounter,
192  const QuantLib::Calendar& calendar,
193  const std::string& interpolator,
194  QuantLib::Real accuracy,
195  bool permanent);
196 
197  const std::vector<QuantLib::Date>& dates() const;
198  const std::vector<QuantLib::Real>& data() const;
199  /*
200  const std::vector<QuantLib::Time>& times() const;
201  const std::vector<QuantLib::Date>& dates() const;
202  const std::vector<QuantLib::Real>& data() const;
203 
204  const std::vector<QuantLib::Real>& improvements(
205  InterpolatedYieldCurve::Traits traits,
206  InterpolatedYieldCurve::Interpolator interpolator) const;
207 
208  QuantLib::Size iterations(
209  InterpolatedYieldCurve::Traits traits,
210  InterpolatedYieldCurve::Interpolator interpolator) const;
211 
212  const std::vector<QuantLib::Time>& jumpTimes(
213  InterpolatedYieldCurve::Traits traits,
214  InterpolatedYieldCurve::Interpolator interpolator) const;
215 
216  const std::vector<QuantLib::Date>& jumpDates(
217  InterpolatedYieldCurve::Traits traits,
218  InterpolatedYieldCurve::Interpolator interpolator) const;
219  */
220  };
221 
222  // no jump dates and jumps, traits = Discount, interpolator = LogLinear
223  class PiecewiseFlatForwardCurve : public YieldTermStructure {
224  public:
226  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
227  const QuantLib::Date& referenceDate,
228  const std::vector<boost::shared_ptr<QuantLib::RateHelper> >& qlrhs,
229  const QuantLib::DayCounter& dayCounter,
230  QuantLib::Real accuracy,
231  bool permanent);
232  /*
233  const std::vector<QuantLib::Time>& times(
234  InterpolatedYieldCurve::Traits traits,
235  InterpolatedYieldCurve::Interpolator interpolator) const;
236 
237  const std::vector<QuantLib::Date>& dates(
238  InterpolatedYieldCurve::Traits traits,
239  InterpolatedYieldCurve::Interpolator interpolator) const;
240 
241  const std::vector<QuantLib::Real>& data(
242  InterpolatedYieldCurve::Traits traits,
243  InterpolatedYieldCurve::Interpolator interpolator) const;
244 
245  const std::vector<QuantLib::Real>& improvements(
246  InterpolatedYieldCurve::Traits traits,
247  InterpolatedYieldCurve::Interpolator interpolator) const;
248 
249  QuantLib::Size iterations(
250  InterpolatedYieldCurve::Traits traits,
251  InterpolatedYieldCurve::Interpolator interpolator) const;
252  */
253  };
254 
255  class RiskyFixedBond : public Instrument {
256  public:
258  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
259  std::string name,
260  QuantLib::Currency ccy,
261  QuantLib::Real recoveryRate,
263  defaultTS,
264  const boost::shared_ptr<QuantLib::Schedule>& schedule,
265  QuantLib::Real rate,
266  QuantLib::DayCounter dayCounter,
267  QuantLib::BusinessDayConvention paymentConvention,
268  QuantLib::Real notionals,
270  QuantLib::Date npvDate,
271  bool permanent);
272  };
273 
274 
275 
276  class SyntheticCDO : public Instrument {
277  public:
278  SyntheticCDO(
279  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
280  const boost::shared_ptr<QuantLib::Basket>& bskt,
281  QuantLib::Protection::Side side,
282  const boost::shared_ptr<QuantLib::Schedule>& schedule,
283  QuantLib::Rate upfront,
284  QuantLib::Rate spread,
285  const QuantLib::DayCounter& dayCounter,
286  QuantLib::BusinessDayConvention paymentConvention,
287  bool permanent);
288  };
289 
290 
292  public:
294  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
296  bool permanent);
297  };
298 
299  class NthToDefault : public Instrument {
300  public:
301  NthToDefault(
302  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
303  const boost::shared_ptr<QuantLib::Basket>& bskt,
304  QuantLib::Size order,
305  QuantLib::Protection::Side side,
306  const boost::shared_ptr<QuantLib::Schedule>& schedule,
307  QuantLib::Rate upfront,
308  QuantLib::Rate spread,
309  const QuantLib::DayCounter& dayCounter,
310  QuantLib::Real notional,
311  bool paysAccrual,
312  bool permanent);
313  };
314 
315 
317  public:
319  const boost::shared_ptr<ObjectHandler::ValueObject>& properties,
320  const QuantLib::Period& step,
322  bool permanent);
323  };
324 
325 
326 
327 }
328 
329 #endif
Definition: basketlossmodels.hpp:32
DefaultEventSet(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const std::string &eventType, const QuantLib::Date &eventDate, const QuantLib::Currency &cur, QuantLib::Seniority sen, const QuantLib::Date &settleDate, QuantLib::Real settledRecovery, bool permanent)
MidPointCdsEngine(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > &, QuantLib::Real recoveryRate, const QuantLib::Handle< QuantLib::YieldTermStructure > &, bool permanent)
RiskyFixedBond(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, std::string name, QuantLib::Currency ccy, QuantLib::Real recoveryRate, QuantLib::Handle< QuantLib::DefaultProbabilityTermStructure > defaultTS, const boost::shared_ptr< QuantLib::Schedule > &schedule, QuantLib::Real rate, QuantLib::DayCounter dayCounter, QuantLib::BusinessDayConvention paymentConvention, QuantLib::Real notionals, QuantLib::Handle< QuantLib::YieldTermStructure > yieldTS, QuantLib::Date npvDate, bool permanent)
UpfrontCdsHelper(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Handle< QuantLib::Quote > &quote, QuantLib::Rate runningSpread, const QuantLib::Period &period, QuantLib::Natural settlementDays, const QuantLib::Calendar &calendar, QuantLib::Frequency frequency, QuantLib::BusinessDayConvention paymentConvention, QuantLib::DateGeneration::Rule rule, const QuantLib::DayCounter &dayCounter, QuantLib::Real recoveryRate, const QuantLib::Handle< QuantLib::YieldTermStructure > &yieldTS, QuantLib::Natural upfrontSettlementDays, bool settlesAccrual, bool paysAtDefaultTime, bool permanent)
Definition: credit.hpp:55
Definition: credit.hpp:291
Definition: credit.hpp:299
PiecewiseFlatForwardCurve(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Date &referenceDate, const std::vector< boost::shared_ptr< QuantLib::RateHelper > > &qlrhs, const QuantLib::DayCounter &dayCounter, QuantLib::Real accuracy, bool permanent)
Definition: credit.hpp:111
Definition: credit.hpp:186
const std::vector< QuantLib::Real > & data() const
Definition: credit.hpp:128
const std::vector< QuantLib::Date > & dates() const
Definition: credit.hpp:168
Issuer(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const boost::shared_ptr< QuantLib::DefaultProbabilityTermStructure > &dfts, const boost::shared_ptr< QuantLib::DefaultEventSet > &evtSet, bool permanent)
NthToDefault(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const boost::shared_ptr< QuantLib::Basket > &bskt, QuantLib::Size order, QuantLib::Protection::Side side, const boost::shared_ptr< QuantLib::Schedule > &schedule, QuantLib::Rate upfront, QuantLib::Rate spread, const QuantLib::DayCounter &dayCounter, QuantLib::Real notional, bool paysAccrual, bool permanent)
SpreadCdsHelper(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Handle< QuantLib::Quote > &quote, const QuantLib::Period &period, QuantLib::Natural settlementDays, const QuantLib::Calendar &calendar, QuantLib::Frequency frequency, QuantLib::BusinessDayConvention paymentConvention, QuantLib::DateGeneration::Rule rule, const QuantLib::DayCounter &dayCounter, QuantLib::Real recoveryRate, const QuantLib::Handle< QuantLib::YieldTermStructure > &yieldTS, bool settlesAccrual, bool paysAtDefaultTime, bool permanent)
const std::vector< QuantLib::Time > & times() const
Definition: baseinstruments.hpp:34
QuantLib::Real setValue(QuantLib::Real value)
const std::vector< QuantLib::Real > & data() const
Definition: abcd.hpp:38
SyntheticCDO(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const boost::shared_ptr< QuantLib::Basket > &bskt, QuantLib::Protection::Side side, const boost::shared_ptr< QuantLib::Schedule > &schedule, QuantLib::Rate upfront, QuantLib::Rate spread, const QuantLib::DayCounter &dayCounter, QuantLib::BusinessDayConvention paymentConvention, bool permanent)
OH_LIB_CTOR(DefaultProbabilityHelper, QuantLib::DefaultProbabilityHelper)
Definition: credit.hpp:276
Definition: credit.hpp:316
Definition: credit.hpp:122
Definition: credit.hpp:66
const std::vector< QuantLib::Date > & dates() const
RecoveryRateQuote(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, QuantLib::Seniority sen, QuantLib::Real value, bool permanent)
MidPointCDOEngine(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Handle< QuantLib::YieldTermStructure > &, bool permanent)
HazardRateCurve(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const std::vector< QuantLib::Date > &dates, const std::vector< QuantLib::Rate > &hazardRates, const QuantLib::DayCounter &dayCounter, bool permanent)
Definition: abcd.hpp:30
PiecewiseHazardRateCurve(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const std::vector< boost::shared_ptr< QuantLib::DefaultProbabilityHelper > > &helpers, const QuantLib::DayCounter &dayCounter, const QuantLib::Calendar &calendar, const std::string &interpolator, QuantLib::Real accuracy, bool permanent)
Definition: credit.hpp:255
Definition: credit.hpp:147
Definition: credit.hpp:82
IntegralNtdEngine(const boost::shared_ptr< ObjectHandler::ValueObject > &properties, const QuantLib::Period &step, const QuantLib::Handle< QuantLib::YieldTermStructure > &, bool permanent)
Definition: pricingengines.hpp:60