27#include <ql/math/array.hpp>
28#include <ql/math/comparison.hpp>
36 template <
class I>
Bucketing(I bucketsBegin, I bucketsEnd);
39 Bucketing(
const Real lowerBound,
const Real upperBound,
const Size n);
41 Size
index(
const Real x)
const;
58 template <
class I1,
class I2>
void compute(I1 pdBegin, I1 pdEnd, I2 lossesBegin);
64 template <
class I1,
class I2>
void computeMultiState(I1 pBegin, I1 pEnd, I2 lossesBegin);
77template <
class I>
Bucketing::Bucketing(I bucketsBegin, I bucketsEnd) : buckets_(bucketsBegin, bucketsEnd) {
83 Array A2(
A_.size()), p2(
p_.size());
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))
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))
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));
100 std::copy(A2.begin(), A2.end(),
A_.begin());
101 std::copy(p2.begin(), p2.end(),
p_.begin());
110 Array A2(
A_.size()), p2(
p_.size());
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))
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))
125 p2[t] +=
p_[k] * (*it_i);
126 A2[t] += (*it_i) * (
A_[k] +
p_[k] * (*it2_i));
129 p2[k] +=
p_[k] * (1.0 - q);
130 A2[k] +=
A_[k] * (1.0 - q);
132 std::copy(A2.begin(), A2.end(),
A_.begin());
133 std::copy(p2.begin(), p2.end(),
p_.begin());
Bucketing(I bucketsBegin, I bucketsEnd)
std::vector< Real > buckets_
Size index(const Real x) const
const std::vector< Real > & upperBucketBound() const
HullWhiteBucketing(I bucketsBegin, I bucketsEnd)
void computeMultiState(I1 pBegin, I1 pEnd, I2 lossesBegin)
const Array & probability() const
void compute(I1 pdBegin, I1 pdEnd, I2 lossesBegin)
const Array & averageLoss() const
HullWhiteBucketing(const Real lowerBound, const Real upperBound, const Size n)