Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
generatordefaulttermstructure.cpp
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 generatordefaultprobabilitytermstructure.cpp
20 \brief Default curve implied from a single generator matrix
21 \ingroup termstructures
22*/
23
27
28namespace QuantExt {
29
31 Size initialState,
32 const Date& referenceDate,
33 const Calendar& cal,
34 const DayCounter& dc)
35 : SurvivalProbabilityStructure(referenceDate, cal, dc), initialState_(initialState),
36 transitionMatrix_(matrixType == MatrixType::Transition ? matrix : Matrix()),
37 generator_(matrixType == MatrixType::Generator ? matrix : Matrix()) {
38
39 QL_REQUIRE(matrix.rows() == matrix.columns(), "input matrix is not square");
40
41 // compute/check the generator
42 if (matrixType == MatrixType::Transition) {
46 }
48}
49
51 QL_REQUIRE(t >= 0.0, "non-negative time required");
52 Matrix Q = QuantExt::Expm(generator_ * t);
53 QL_REQUIRE(initialState_ < Q.rows(),
54 "initial state " << initialState_ << " out of range [0," << Q.rows() - 1 << "]");
55 Size lastState = Q.columns() - 1;
56 return 1.0 - Q[initialState_][lastState];
57}
58
59} // namespace QuantExt
GeneratorDefaultProbabilityTermStructure(MatrixType matrixType, Matrix matrix, Size initialState, const Date &referenceDate, const Calendar &cal=NullCalendar(), const DayCounter &dc=Actual365Fixed())
Constructor using a single (annual!) transition matrix or a generator matrix.
Default curve implied from a single generator matrix.
matrix functions
QuantLib::Matrix Expm(const QuantLib::Matrix &m)
void checkTransitionMatrix(const Matrix &t)
check if the matrix is a transition matrix, i.e. row sums are 1 and entries are non-negative
void checkGeneratorMatrix(const Matrix &g)
check if the matrix is a generator matirx, i.e. row sums are 0 and non-diagonal elements are non-nega...
Matrix generator(const Matrix &t, const Real horizon)
void sanitiseTransitionMatrix(Matrix &m)
utility functions for transition matrices and generators