| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2012, 2013 Grzegorz Andruszkiewicz |
| 5 | |
| 6 | This file is part of QuantLib, a free-software/open-source library |
| 7 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 8 | |
| 9 | QuantLib is free software: you can redistribute it and/or modify it |
| 10 | under the terms of the QuantLib license. You should have received a |
| 11 | copy of the license along with this program; if not, please email |
| 12 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 13 | <http://quantlib.org/license.shtml>. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 18 | */ |
| 19 | |
| 20 | /*! \file catbond.hpp |
| 21 | \brief cat bond class |
| 22 | */ |
| 23 | |
| 24 | #ifndef quantlib_catbond_hpp |
| 25 | #define quantlib_catbond_hpp |
| 26 | |
| 27 | #include <ql/experimental/catbonds/catrisk.hpp> |
| 28 | #include <ql/experimental/catbonds/riskynotional.hpp> |
| 29 | #include <ql/indexes/iborindex.hpp> |
| 30 | #include <ql/instruments/bond.hpp> |
| 31 | #include <ql/time/dategenerationrule.hpp> |
| 32 | #include <ql/time/schedule.hpp> |
| 33 | #include <utility> |
| 34 | |
| 35 | namespace QuantLib { |
| 36 | |
| 37 | class CatBond : public Bond |
| 38 | { |
| 39 | public: |
| 40 | class arguments; |
| 41 | class results; |
| 42 | class engine; |
| 43 | |
| 44 | CatBond(Natural settlementDays, |
| 45 | const Calendar& calendar, |
| 46 | const Date& issueDate, |
| 47 | ext::shared_ptr<NotionalRisk> notionalRisk) |
| 48 | : Bond(settlementDays, calendar, issueDate), notionalRisk_(std::move(notionalRisk)) {} |
| 49 | ~CatBond() override = default; |
| 50 | |
| 51 | void setupArguments(PricingEngine::arguments*) const override; |
| 52 | void fetchResults(const PricingEngine::results*) const override; |
| 53 | |
| 54 | Real lossProbability() const { return lossProbability_; } |
| 55 | Real expectedLoss() const { return expectedLoss_; } |
| 56 | Real exhaustionProbability() const { return exhaustionProbability_; } |
| 57 | |
| 58 | protected: |
| 59 | ext::shared_ptr<NotionalRisk> notionalRisk_; |
| 60 | |
| 61 | mutable Real lossProbability_; |
| 62 | mutable Real exhaustionProbability_; |
| 63 | mutable Real expectedLoss_; |
| 64 | }; |
| 65 | |
| 66 | class CatBond::arguments : public Bond::arguments { |
| 67 | public: |
| 68 | Date startDate; |
| 69 | ext::shared_ptr<NotionalRisk> notionalRisk; |
| 70 | void validate() const override; |
| 71 | }; |
| 72 | |
| 73 | //! results for a cat bond calculation |
| 74 | class CatBond::results : public Bond::results { |
| 75 | public: |
| 76 | Real lossProbability; |
| 77 | Real exhaustionProbability; |
| 78 | Real expectedLoss; |
| 79 | }; |
| 80 | |
| 81 | //! base class for cat bond engine |
| 82 | class CatBond::engine |
| 83 | : public GenericEngine<CatBond::arguments, |
| 84 | CatBond::results> {}; |
| 85 | |
| 86 | |
| 87 | //! floating-rate cat bond (possibly capped and/or floored) |
| 88 | /*! \ingroup instruments |
| 89 | |
| 90 | \test calculations are tested by checking results against |
| 91 | cached values. |
| 92 | */ |
| 93 | class FloatingCatBond : public CatBond { |
| 94 | public: |
| 95 | FloatingCatBond(Natural settlementDays, |
| 96 | Real faceAmount, |
| 97 | const Schedule& schedule, |
| 98 | const ext::shared_ptr<IborIndex>& iborIndex, |
| 99 | const DayCounter& accrualDayCounter, |
| 100 | const ext::shared_ptr<NotionalRisk>& notionalRisk, |
| 101 | BusinessDayConvention paymentConvention = Following, |
| 102 | Natural fixingDays = Null<Natural>(), |
| 103 | const std::vector<Real>& gearings = std::vector<Real>(1, 1.0), |
| 104 | const std::vector<Spread>& spreads = std::vector<Spread>(1, 0.0), |
| 105 | const std::vector<Rate>& caps = std::vector<Rate>(), |
| 106 | const std::vector<Rate>& floors = std::vector<Rate>(), |
| 107 | bool inArrears = false, |
| 108 | Real redemption = 100.0, |
| 109 | const Date& issueDate = Date()); |
| 110 | |
| 111 | FloatingCatBond(Natural settlementDays, |
| 112 | Real faceAmount, |
| 113 | const Date& startDate, |
| 114 | const Date& maturityDate, |
| 115 | Frequency couponFrequency, |
| 116 | const Calendar& calendar, |
| 117 | const ext::shared_ptr<IborIndex>& iborIndex, |
| 118 | const DayCounter& accrualDayCounter, |
| 119 | const ext::shared_ptr<NotionalRisk>& notionalRisk, |
| 120 | BusinessDayConvention accrualConvention = Following, |
| 121 | BusinessDayConvention paymentConvention = Following, |
| 122 | Natural fixingDays = Null<Natural>(), |
| 123 | const std::vector<Real>& gearings = std::vector<Real>(1, 1.0), |
| 124 | const std::vector<Spread>& spreads = std::vector<Spread>(1, 0.0), |
| 125 | const std::vector<Rate>& caps = std::vector<Rate>(), |
| 126 | const std::vector<Rate>& floors = std::vector<Rate>(), |
| 127 | bool inArrears = false, |
| 128 | Real redemption = 100.0, |
| 129 | const Date& issueDate = Date(), |
| 130 | const Date& stubDate = Date(), |
| 131 | DateGeneration::Rule rule = DateGeneration::Backward, |
| 132 | bool endOfMonth = false); |
| 133 | }; |
| 134 | |
| 135 | } |
| 136 | |
| 137 | #endif |
| 138 | |