| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2008 Roland Stamm |
| 5 | Copyright (C) 2009 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 | /*! \file cdsoption.hpp |
| 22 | \brief CDS option |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_cds_option_hpp |
| 26 | #define quantlib_cds_option_hpp |
| 27 | |
| 28 | #include <ql/option.hpp> |
| 29 | #include <ql/instruments/creditdefaultswap.hpp> |
| 30 | |
| 31 | namespace QuantLib { |
| 32 | |
| 33 | class Quote; |
| 34 | class YieldTermStructure; |
| 35 | |
| 36 | //! CDS option |
| 37 | /*! The side of the swaption is set by choosing the side of the CDS. |
| 38 | A receiver CDS option is a right to buy an underlying CDS |
| 39 | selling protection and receiving a coupon. A payer CDS option |
| 40 | is a right to buy an underlying CDS buying protection and |
| 41 | paying coupon. |
| 42 | */ |
| 43 | class CdsOption : public Option { |
| 44 | public: |
| 45 | class arguments; |
| 46 | class results; |
| 47 | class engine; |
| 48 | CdsOption(const ext::shared_ptr<CreditDefaultSwap>& swap, |
| 49 | const ext::shared_ptr<Exercise>& exercise, |
| 50 | bool knocksOut = true); |
| 51 | |
| 52 | //! \name Instrument interface |
| 53 | //@{ |
| 54 | bool isExpired() const override; |
| 55 | void setupArguments(PricingEngine::arguments*) const override; |
| 56 | //@} |
| 57 | //! \name Inspectors |
| 58 | //@{ |
| 59 | const ext::shared_ptr<CreditDefaultSwap>& underlyingSwap() const { |
| 60 | return swap_; |
| 61 | } |
| 62 | //@} |
| 63 | //! \name Calculations |
| 64 | //@{ |
| 65 | Rate atmRate() const; |
| 66 | Real riskyAnnuity() const; |
| 67 | Volatility impliedVolatility( |
| 68 | Real price, |
| 69 | const Handle<YieldTermStructure>& termStructure, |
| 70 | const Handle<DefaultProbabilityTermStructure>&, |
| 71 | Real recoveryRate, |
| 72 | Real accuracy = 1.e-4, |
| 73 | Size maxEvaluations = 100, |
| 74 | Volatility minVol = 1.0e-7, |
| 75 | Volatility maxVol = 4.0) const; |
| 76 | //@} |
| 77 | |
| 78 | private: |
| 79 | ext::shared_ptr<CreditDefaultSwap> swap_; |
| 80 | bool knocksOut_; |
| 81 | |
| 82 | mutable Real riskyAnnuity_; |
| 83 | void setupExpired() const override; |
| 84 | void fetchResults(const PricingEngine::results*) const override; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | //! %Arguments for CDS-option calculation |
| 89 | class CdsOption::arguments : public CreditDefaultSwap::arguments, |
| 90 | public Option::arguments { |
| 91 | public: |
| 92 | arguments() = default; |
| 93 | |
| 94 | ext::shared_ptr<CreditDefaultSwap> swap; |
| 95 | bool knocksOut; |
| 96 | void validate() const override; |
| 97 | }; |
| 98 | |
| 99 | //! %Results from CDS-option calculation |
| 100 | class CdsOption::results : public Option::results { |
| 101 | public: |
| 102 | Real riskyAnnuity; |
| 103 | void reset() override; |
| 104 | }; |
| 105 | |
| 106 | //! base class for swaption engines |
| 107 | class CdsOption::engine |
| 108 | : public GenericEngine<CdsOption::arguments, CdsOption::results> {}; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | #endif |
| 113 | |