Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
correlationtermstructure.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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/termstructures/correlationtermstructure.hpp
20 \brief Term structure of correlations
21*/
22
23#ifndef quantext_correlation_term_structure_hpp
24#define quantext_correlation_term_structure_hpp
25
26#include <ql/math/comparison.hpp>
27#include <ql/quote.hpp>
28#include <ql/termstructure.hpp>
29
30namespace QuantExt {
31using namespace QuantLib;
32
33//! Correlation term structure
34/*! This abstract class defines the interface of concrete
35 correlation term structures which will be derived from this one.
36
37 \ingroup termstructures
38*/
39class CorrelationTermStructure : public TermStructure {
40public:
41 //! \name Constructors
42 //@{
43 CorrelationTermStructure(const DayCounter& dc = DayCounter());
44 CorrelationTermStructure(const Date& referenceDate, const Calendar& cal = Calendar(),
45 const DayCounter& dc = DayCounter());
46 CorrelationTermStructure(Natural settlementDays, const Calendar& cal, const DayCounter& dc = DayCounter());
47 //@}
48
49 //! \name Correlations
50 //@{
51 Real correlation(Time t, Real strike = Null<Real>(), bool extrapolate = false) const;
52 Real correlation(const Date& d, Real strike = Null<Real>(), bool extrapolate = false) const;
53 //@}
54
55 //! The minimum time for which the curve can return values
56 virtual Time minTime() const;
57
58protected:
59 /*! \name Calculations
60 This method must be implemented in derived classes to
61 perform the actual calculations.
62 */
63 //@{
64 //! Correlation calculation
65 virtual Real correlationImpl(Time t, Real strike) const = 0;
66 //@}
67
68 //! Extra time range check for minimum time, then calls TermStructure::checkRange
69 virtual void checkRange(Time t, Real strike, bool extrapolate) const;
70};
71
72//! Wrapper class that inverts the correlation
74public:
75 NegativeCorrelationTermStructure(const Handle<CorrelationTermStructure>& c);
76 Date maxDate() const override { return c_->maxDate(); }
77 const Date& referenceDate() const override { return c_->referenceDate(); }
78 Calendar calendar() const override { return c_->calendar(); }
79 Natural settlementDays() const override { return c_->settlementDays(); }
80
81private:
82 virtual Real correlationImpl(Time t, Real strike) const override;
83 Handle<CorrelationTermStructure> c_;
84};
85
86//! Wrapper class that extracts a value at a given time from the term structure
87class CorrelationValue : public Observer, public Quote {
88public:
89 CorrelationValue(const Handle<CorrelationTermStructure>& correlation, const Time t,
90 const Real strike = Null<Real>());
91 Real value() const override;
92 bool isValid() const override;
93 void update() override;
94
95private:
96 Handle<CorrelationTermStructure> correlation_;
97 const Time t_;
98 const Real strike_;
99};
100
101} // namespace QuantExt
102
103#endif
virtual Time minTime() const
The minimum time for which the curve can return values.
virtual Real correlationImpl(Time t, Real strike) const =0
Correlation calculation.
Real correlation(Time t, Real strike=Null< Real >(), bool extrapolate=false) const
virtual void checkRange(Time t, Real strike, bool extrapolate) const
Extra time range check for minimum time, then calls TermStructure::checkRange.
Wrapper class that extracts a value at a given time from the term structure.
Handle< CorrelationTermStructure > correlation_
Wrapper class that inverts the correlation.
virtual Real correlationImpl(Time t, Real strike) const override
Correlation calculation.