| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2014 Jose Aparicio |
| 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 | #ifndef quantlib_correl_term_structure_hpp |
| 21 | #define quantlib_correl_term_structure_hpp |
| 22 | |
| 23 | #include <ql/termstructure.hpp> |
| 24 | |
| 25 | namespace QuantLib { |
| 26 | |
| 27 | // pretty much like the volatility TS, here the correlation range is |
| 28 | // obviously known in advance and theres no reference to a strike. |
| 29 | |
| 30 | /*! Abstract interface, derived correlations TS might have elements with |
| 31 | arbitrary dimensions.\par |
| 32 | In principle there might be several extrapolation dimensions, at this |
| 33 | level we do not know how many or the nature of those dimensions (time, |
| 34 | strike...) |
| 35 | Equally we ignore at this level if the correlation is a number, |
| 36 | matrix. Rather than including an arbitrary size matrix this data |
| 37 | structure is deferred in the hierarchy to enable potential optimizations |
| 38 | on the data nature. |
| 39 | */ |
| 40 | class CorrelationTermStructure : public TermStructure { |
| 41 | public: |
| 42 | /*! \name Constructors |
| 43 | See the TermStructure documentation for issues regarding |
| 44 | constructors. |
| 45 | */ |
| 46 | //@{ |
| 47 | //! default constructor |
| 48 | /*! \warning term structures initialized by means of this |
| 49 | constructor must manage their own reference date |
| 50 | by overriding the referenceDate() method. |
| 51 | */ |
| 52 | CorrelationTermStructure(const Calendar& cal, |
| 53 | BusinessDayConvention bdc, |
| 54 | const DayCounter& dc = DayCounter()); |
| 55 | //! initialize with a fixed reference date |
| 56 | CorrelationTermStructure(const Date& referenceDate, |
| 57 | const Calendar& cal, |
| 58 | BusinessDayConvention bdc, |
| 59 | const DayCounter& dc = DayCounter()); |
| 60 | //! calculate the reference date based on the global evaluation date |
| 61 | CorrelationTermStructure(Natural settlementDays, |
| 62 | const Calendar& cal, |
| 63 | BusinessDayConvention bdc, |
| 64 | const DayCounter& dc = DayCounter()); |
| 65 | //@} |
| 66 | BusinessDayConvention businessDayConvention() const; |
| 67 | //! period/date conversion |
| 68 | Date dateFromTenor(const Period&) const; |
| 69 | //! The size of the squared correlation. |
| 70 | virtual Size correlationSize() const = 0; |
| 71 | private: |
| 72 | BusinessDayConvention bdc_; |
| 73 | }; |
| 74 | |
| 75 | // inline definitions |
| 76 | inline BusinessDayConvention |
| 77 | CorrelationTermStructure::businessDayConvention() const { |
| 78 | return bdc_; |
| 79 | } |
| 80 | |
| 81 | inline Date |
| 82 | CorrelationTermStructure::dateFromTenor(const Period& p) const { |
| 83 | // swaption style, still holds here. |
| 84 | return calendar().advance(date: referenceDate(), |
| 85 | period: p, |
| 86 | convention: businessDayConvention()); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | #endif |
| 91 | |