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

Piecewise Constant Helper2. More...

#include <qle/models/piecewiseconstanthelper.hpp>

+ Inheritance diagram for PiecewiseConstantHelper2:
+ Collaboration diagram for PiecewiseConstantHelper2:

Public Member Functions

 PiecewiseConstantHelper2 (const Array &t, const QuantLib::ext::shared_ptr< PseudoParameter > &y)
 
 PiecewiseConstantHelper2 (const Array &t, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
 
 PiecewiseConstantHelper2 (const std::vector< Date > &dates, const Handle< YieldTermStructure > &yts, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
 
const Array & t () const
 
const QuantLib::ext::shared_ptr< Parameter > p () const
 
void update () const
 
Real y (const Time t) const
 
Real exp_m_int_y (const Time t) const
 exp(int_0^t -y(s)) ds More...
 
Real int_exp_m_int_y (const Time t) const
 int_0^t exp(int_0^s -y(u) du) ds More...
 
Real direct (const Real x) const
 
Real inverse (const Real y) const
 

Protected Attributes

const Array t_
 
const QuantLib::ext::shared_ptr< PseudoParametery_
 

Private Attributes

const Real zeroCutoff_
 
std::vector< Real > b_
 
std::vector< Real > c_
 

Detailed Description

Piecewise Constant Helper2.

Definition at line 92 of file piecewiseconstanthelper.hpp.

Constructor & Destructor Documentation

◆ PiecewiseConstantHelper2() [1/3]

PiecewiseConstantHelper2 ( const Array &  t,
const QuantLib::ext::shared_ptr< PseudoParameter > &  y 
)

Definition at line 88 of file piecewiseconstanthelper.cpp.

89 : zeroCutoff_(1.0E-6), t_(t), y_(p) {}
const QuantLib::ext::shared_ptr< PseudoParameter > y_
const QuantLib::ext::shared_ptr< Parameter > p() const

◆ PiecewiseConstantHelper2() [2/3]

PiecewiseConstantHelper2 ( const Array &  t,
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint = QuantLib::ext::make_shared< QuantLib::NoConstraint >() 
)

◆ PiecewiseConstantHelper2() [3/3]

PiecewiseConstantHelper2 ( const std::vector< Date > &  dates,
const Handle< YieldTermStructure > &  yts,
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint = QuantLib::ext::make_shared< QuantLib::NoConstraint >() 
)

Member Function Documentation

◆ t()

const Array & t ( ) const

Definition at line 193 of file piecewiseconstanthelper.hpp.

193{ return t_; }
+ Here is the caller graph for this function:

◆ p()

const QuantLib::ext::shared_ptr< Parameter > p ( ) const

Definition at line 195 of file piecewiseconstanthelper.hpp.

195{ return y_; }
+ Here is the caller graph for this function:

◆ update()

void update ( ) const

Definition at line 201 of file piecewiseconstanthelper.hpp.

201 {
202 Real sum = 0.0, sum2 = 0.0;
203 b_.resize(t_.size());
204 c_.resize(t_.size());
205 for (Size i = 0; i < t_.size(); ++i) {
206 Real t0 = (i == 0 ? 0.0 : t_[i - 1]);
207 sum += direct(y_->params()[i]) * (t_[i] - t0);
208 b_[i] = sum;
209 Real b2Tmp = (i == 0 ? 0.0 : b_[i - 1]);
210 if (std::fabs(direct(y_->params()[i])) < zeroCutoff_) {
211 sum2 += (t_[i] - t0) * std::exp(-b2Tmp);
212 } else {
213 sum2 += (std::exp(-b2Tmp) - std::exp(-b2Tmp - direct(y_->params()[i]) * (t_[i] - t0))) /
214 direct(y_->params()[i]);
215 }
216 c_[i] = sum2;
217 }
218}
Real sum(const Cash &c, const Cash &d)
Definition: bondbasket.cpp:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ y()

Real y ( const Time  t) const

this returns the transformed value

Definition at line 276 of file piecewiseconstanthelper.hpp.

276 {
277 return direct(QL_PIECEWISE_FUNCTION(t_, y_->params(), t));
278}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exp_m_int_y()

Real exp_m_int_y ( const Time  t) const

exp(int_0^t -y(s)) ds

Definition at line 300 of file piecewiseconstanthelper.hpp.

300 {
301 if (t < 0.0)
302 return 1.0;
303 Size i = std::upper_bound(t_.begin(), t_.end(), t) - t_.begin();
304 Real res = 0.0;
305 if (i >= 1)
306 res += b_[std::min(i - 1, b_.size() - 1)];
307 Real a = y_->params()[std::min(i, y_->size() - 1)];
308 res += a * (t - (i == 0 ? 0.0 : t_[i - 1]));
309 return std::exp(-res);
310}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ int_exp_m_int_y()

Real int_exp_m_int_y ( const Time  t) const

int_0^t exp(int_0^s -y(u) du) ds

Definition at line 312 of file piecewiseconstanthelper.hpp.

312 {
313 if (t < 0.0)
314 return 0.0;
315 Size i = std::upper_bound(t_.begin(), t_.end(), t) - t_.begin();
316 Real res = 0.0;
317 if (i >= 1)
318 res += c_[std::min(i - 1, c_.size() - 1)];
319 Real a = direct(y_->params()[std::min(i, y_->size() - 1)]);
320 Real t0 = (i == 0 ? 0.0 : t_[i - 1]);
321 Real b2Tmp = (i == 0 ? 0.0 : b_[i - 1]);
322 if (std::fabs(a) < zeroCutoff_) {
323 res += std::exp(-b2Tmp) * (t - t0);
324 } else {
325 res += (std::exp(-b2Tmp) - std::exp(-b2Tmp - a * (t - t0))) / a;
326 }
327 return res;
328}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ direct()

Real direct ( const Real  x) const

Definition at line 197 of file piecewiseconstanthelper.hpp.

197{ return x; }
+ Here is the caller graph for this function:

◆ inverse()

Real inverse ( const Real  y) const

Definition at line 199 of file piecewiseconstanthelper.hpp.

199{ return y; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ zeroCutoff_

const Real zeroCutoff_
private

Definition at line 113 of file piecewiseconstanthelper.hpp.

◆ t_

const Array t_
protected

Definition at line 116 of file piecewiseconstanthelper.hpp.

◆ y_

const QuantLib::ext::shared_ptr<PseudoParameter> y_
protected

y are the raw values in the sense of parameter transformation

Definition at line 118 of file piecewiseconstanthelper.hpp.

◆ b_

std::vector<Real> b_
mutableprivate

Definition at line 121 of file piecewiseconstanthelper.hpp.

◆ c_

std::vector<Real> c_
private

Definition at line 121 of file piecewiseconstanthelper.hpp.