QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
hazardratestructure.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Jose Aparicio
5 Copyright (C) 2008 Chris Kenyon
6 Copyright (C) 2008 Roland Lichters
7 Copyright (C) 2008 StatPro Italia srl
8 Copyright (C) 2009 Ferdinando Ametrano
9
10 This file is part of QuantLib, a free-software/open-source library
11 for financial quantitative analysts and developers - http://quantlib.org/
12
13 QuantLib is free software: you can redistribute it and/or modify it
14 under the terms of the QuantLib license. You should have received a
15 copy of the license along with this program; if not, please email
16 <quantlib-dev@lists.sf.net>. The license is also available online at
17 <http://quantlib.org/license.shtml>.
18
19 This program is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 FOR A PARTICULAR PURPOSE. See the license for more details.
22*/
23
26#include <utility>
27
28namespace QuantLib {
29
30 namespace {
31
32 template <class F>
33 struct remapper {
36 remapper(F f, Time T) : f(std::move(f)), T(T) {}
37 // This remaps [-1,1] to [0,T]. No differential included.
38 Real operator()(Real x) const {
39 const Real arg = (x+1.0)*T/2.0;
40 return f(arg);
41 }
42 };
43
44 template <class F>
45 remapper<F> remap(const F& f, Time T) {
46 return remapper<F>(f,T);
47 }
48
49 }
50
52 const DayCounter& dc,
53 const std::vector<Handle<Quote> >& jumps,
54 const std::vector<Date>& jumpDates)
55 : DefaultProbabilityTermStructure(dc, jumps, jumpDates) {}
56
58 const Date& refDate,
59 const Calendar& cal,
60 const DayCounter& dc,
61 const std::vector<Handle<Quote> >& jumps,
62 const std::vector<Date>& jumpDates)
63 : DefaultProbabilityTermStructure(refDate, cal, dc, jumps, jumpDates) {}
64
66 Natural settlDays,
67 const Calendar& cal,
68 const DayCounter& dc,
69 const std::vector<Handle<Quote> >& jumps,
70 const std::vector<Date>& jumpDates)
71 : DefaultProbabilityTermStructure(settlDays, cal, dc, jumps, jumpDates) {}
72
74 QL_FAIL("hazardRateImpl() must be implemented by a class derived from HazardRateStructure");
75 }
76
78 static GaussChebyshevIntegration integral(48);
79 // the Gauss-Chebyshev quadratures integrate over [-1,1],
80 // hence the remapping (and the Jacobian term t/2)
81 return std::exp(-integral(remap([&](Time tau){ return hazardRateImpl(tau); }, t)) * t/2.0);
82 }
83
84}
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Default probability term structure.
Shared handle to an observable.
Definition: handle.hpp:41
Real hazardRateImpl(Time) const override
hazard rate calculation
HazardRateStructure(const DayCounter &dayCounter=DayCounter(), const std::vector< Handle< Quote > > &jumps={}, const std::vector< Date > &jumpDates={})
Probability survivalProbabilityImpl(Time) const override
const DefaultType & t
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Integral of a 1-dimensional function using the Gauss quadratures.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Probability
probability
Definition: types.hpp:82
hazard-rate term structure
Definition: any.hpp:35
STL namespace.
Real F
Definition: sabr.cpp:200