Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HullWhiteBucketing Class Reference

#include <qle/models/hullwhitebucketing.hpp>

+ Inheritance diagram for HullWhiteBucketing:
+ Collaboration diagram for HullWhiteBucketing:

Public Member Functions

template<class I >
 HullWhiteBucketing (I bucketsBegin, I bucketsEnd)
 
 HullWhiteBucketing (const Real lowerBound, const Real upperBound, const Size n)
 
template<class I1 , class I2 >
void compute (I1 pdBegin, I1 pdEnd, I2 lossesBegin)
 
template<class I1 , class I2 >
void computeMultiState (I1 pBegin, I1 pEnd, I2 lossesBegin)
 
const Array & probability () const
 
const Array & averageLoss () const
 
- Public Member Functions inherited from Bucketing
template<class I >
 Bucketing (I bucketsBegin, I bucketsEnd)
 
 Bucketing (const Real lowerBound, const Real upperBound, const Size n)
 
const std::vector< Real > & upperBucketBound () const
 
Size index (const Real x) const
 
Size buckets () const
 

Private Member Functions

void init_p_A ()
 
void finalize_p_A ()
 

Private Attributes

Array p_
 
Array A_
 

Additional Inherited Members

- Protected Member Functions inherited from Bucketing
void initBuckets ()
 
- Protected Attributes inherited from Bucketing
std::vector< Real > buckets_
 
bool uniformBuckets_ = false
 
Real lowerBound_
 
Real upperBound_
 
Real h_
 

Detailed Description

Definition at line 51 of file hullwhitebucketing.hpp.

Constructor & Destructor Documentation

◆ HullWhiteBucketing() [1/2]

HullWhiteBucketing ( bucketsBegin,
bucketsEnd 
)

Definition at line 53 of file hullwhitebucketing.hpp.

53: Bucketing(bucketsBegin, bucketsEnd) {}
Bucketing(I bucketsBegin, I bucketsEnd)

◆ HullWhiteBucketing() [2/2]

HullWhiteBucketing ( const Real  lowerBound,
const Real  upperBound,
const Size  n 
)

Definition at line 54 of file hullwhitebucketing.hpp.

55 : Bucketing(lowerBound, upperBound, n) {}

Member Function Documentation

◆ compute()

void compute ( I1  pdBegin,
I1  pdEnd,
I2  lossesBegin 
)

Definition at line 81 of file hullwhitebucketing.hpp.

81 {
82 init_p_A();
83 Array A2(A_.size()), p2(p_.size());
84
85 auto it2 = lossesBegin;
86 for (auto it = pdBegin; it != pdEnd; ++it, ++it2) {
87 if (QuantLib::close_enough(*it, 0.0) || QuantLib::close_enough(*it2, 0.0))
88 continue;
89 std::fill(A2.begin(), A2.end(), 0.0);
90 std::fill(p2.begin(), p2.end(), 0.0);
91 for (Size k = 0; k < buckets_.size(); ++k) {
92 if (QuantLib::close_enough(p_[k], 0.0))
93 continue;
94 Size t = index(A_[k] / p_[k] + *it2);
95 p2[k] += p_[k] * (1.0 - (*it));
96 A2[k] += A_[k] * (1.0 - (*it));
97 p2[t] += p_[k] * (*it);
98 A2[t] += (*it) * (A_[k] + p_[k] * (*it2));
99 }
100 std::copy(A2.begin(), A2.end(), A_.begin());
101 std::copy(p2.begin(), p2.end(), p_.begin());
102 }
103
104 finalize_p_A();
105
106} // compute
std::vector< Real > buckets_
Size index(const Real x) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ computeMultiState()

void computeMultiState ( I1  pBegin,
I1  pEnd,
I2  lossesBegin 
)

Definition at line 108 of file hullwhitebucketing.hpp.

108 {
109 init_p_A();
110 Array A2(A_.size()), p2(p_.size());
111
112 auto it2 = lossesBegin;
113 for (auto it = pBegin; it != pEnd; ++it, ++it2) {
114 std::fill(A2.begin(), A2.end(), 0.0);
115 std::fill(p2.begin(), p2.end(), 0.0);
116 for (Size k = 0; k < buckets_.size(); ++k) {
117 if (QuantLib::close_enough(p_[k], 0.0))
118 continue;
119 Real q = 0.0;
120 auto it2_i = (*it2).begin();
121 for (auto it_i = (*it).begin(), itend = (*it).end(); it_i != itend; ++it_i, ++it2_i) {
122 if (QuantLib::close_enough(*it_i, 0.0) || QuantLib::close_enough(*it2_i, 0.0))
123 continue;
124 Size t = index(A_[k] / p_[k] + *it2_i);
125 p2[t] += p_[k] * (*it_i);
126 A2[t] += (*it_i) * (A_[k] + p_[k] * (*it2_i));
127 q += *it_i;
128 }
129 p2[k] += p_[k] * (1.0 - q);
130 A2[k] += A_[k] * (1.0 - q);
131 }
132 std::copy(A2.begin(), A2.end(), A_.begin());
133 std::copy(p2.begin(), p2.end(), p_.begin());
134 } // for it
135
136 finalize_p_A();
137
138} // computeMultiState
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ probability()

const Array & probability ( ) const

Definition at line 66 of file hullwhitebucketing.hpp.

66{ return p_; }
+ Here is the caller graph for this function:

◆ averageLoss()

const Array & averageLoss ( ) const

Definition at line 67 of file hullwhitebucketing.hpp.

67{ return A_; }
+ Here is the caller graph for this function:

◆ init_p_A()

void init_p_A ( )
private

Definition at line 57 of file hullwhitebucketing.cpp.

57 {
58 Size N = buckets_.size();
59 p_ = Array(N, 0);
60 A_ = Array(N, 0);
61 Size zeroIdx = index(0.0);
62 p_[zeroIdx] = 1.0;
63 A_[zeroIdx] = 0.0;
64}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalize_p_A()

void finalize_p_A ( )
private

Definition at line 66 of file hullwhitebucketing.cpp.

66 {
67 Size N = buckets_.size();
68 for (Size i = 0; i < N; ++i) {
69 if (QuantLib::close_enough(p_[i], 0.0)) {
70 // the probability for a bucket is zero => fill average with midpoint (endpoints)
71 if (i == 0) {
72 A_[i] = buckets_.front();
73 } else if (i == N - 1) {
74 A_[i] = buckets_[N - 2];
75 } else {
76 A_[i] = 0.5 * (buckets_[i - 1] + buckets_[i]);
77 }
78 } else {
79 // otherwise normalize the bucket to represent the conditional aveage for this bucket
80 A_[i] /= p_[i];
81 }
82 }
83}
+ Here is the caller graph for this function:

Member Data Documentation

◆ p_

Array p_
private

Definition at line 72 of file hullwhitebucketing.hpp.

◆ A_

Array A_
private

Definition at line 72 of file hullwhitebucketing.hpp.