Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
basecorrelationquote.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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/quotes/basecorrelationquote.hpp
20 \brief wrapper around base correlation term structure for given detachment point
21*/
22
23#ifndef quantext_basecorrelation_quote_hpp
24#define quantext_basecorrelation_quote_hpp
25
26#include <ql/errors.hpp>
28#include <ql/handle.hpp>
29#include <ql/quote.hpp>
30#include <ql/types.hpp>
31
32namespace QuantExt {
33
34//! market element whose value depends on two other market element
35/*! \test the correctness of the returned values is tested by
36 checking them against numerical calculations.
37*/
38class BaseCorrelationQuote : public Quote, public Observer {
39public:
40 BaseCorrelationQuote(const Handle<QuantExt::BaseCorrelationTermStructure>& bcts, Period term, Real lossLevel,
41 bool extrapolate);
42 //! \name inspectors
43 //@{
44 Handle<QuantExt::BaseCorrelationTermStructure> termStructure() const { return bcts_; }
45 Period term() const { return term_; }
46 Real lossLevel() const { return lossLevel_; }
47 bool extrapolate() const { return extrapolate_; }
48 //@}
49 //! \name Quote interface
50 //@{
51 Real value() const override;
52 bool isValid() const override;
53 //@}
54 //! \name Observer interface
55 //@{
56 void update() override;
57 //@}
58private:
59 Handle<QuantExt::BaseCorrelationTermStructure> bcts_;
60 Period term_;
63};
64
65// inline definitions
66
67
68inline BaseCorrelationQuote::BaseCorrelationQuote(const Handle<QuantExt::BaseCorrelationTermStructure>& bcts,
69 Period term, Real lossLevel, bool extrapolate)
70 : bcts_(bcts), term_(term), lossLevel_(lossLevel), extrapolate_(extrapolate) {
71 QL_REQUIRE(lossLevel > 0.0 && lossLevel <= 1.0, "lossLevel " << lossLevel << " out of range");
72 registerWith(bcts_);
73}
74
75inline Real BaseCorrelationQuote::value() const {
76 QL_ENSURE(isValid(), "invalid BaseCorrelationQuote");
77 Date ref = bcts_->referenceDate();
78 Real c = bcts_->correlation(ref + term_, lossLevel_, extrapolate_);
79 // FIXME this should be handled in the input correlation term structure
80 return std::min(1.0 - QL_EPSILON, std::max(QL_EPSILON, c));
81}
82
83inline bool BaseCorrelationQuote::isValid() const {
84 return !bcts_.empty();
85}
86
87inline void BaseCorrelationQuote::update() { notifyObservers(); }
88
89} // namespace QuantExt
90
91#endif
abstract base correlation structure and an 2d-interpolated base correlation structure
market element whose value depends on two other market element
Handle< QuantExt::BaseCorrelationTermStructure > bcts_
Handle< QuantExt::BaseCorrelationTermStructure > termStructure() const
BaseCorrelationQuote(const Handle< QuantExt::BaseCorrelationTermStructure > &bcts, Period term, Real lossLevel, bool extrapolate)