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

Piecewise Constant Helper 3. More...

#include <qle/models/piecewiseconstanthelper.hpp>

+ Inheritance diagram for PiecewiseConstantHelper3:
+ Collaboration diagram for PiecewiseConstantHelper3:

Public Member Functions

 PiecewiseConstantHelper3 (const Array &t1, const Array &t2, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint1=QuantLib::ext::make_shared< QuantLib::NoConstraint >(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint2=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
 
 PiecewiseConstantHelper3 (const std::vector< Date > &dates1, const std::vector< Date > &dates2, const Handle< YieldTermStructure > &yts, const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint1=QuantLib::ext::make_shared< QuantLib::NoConstraint >(), const QuantLib::ext::shared_ptr< QuantLib::Constraint > &constraint2=QuantLib::ext::make_shared< QuantLib::NoConstraint >())
 
const Array & t1 () const
 
const Array & t2 () const
 
const Array & tUnion () const
 
const QuantLib::ext::shared_ptr< Parameter > p1 () const
 
const QuantLib::ext::shared_ptr< Parameter > p2 () const
 
void update () const
 
Real y1 (const Time t) const
 
Real y2 (const Time t) const
 
Real int_y1_sqr_exp_2_int_y2 (const Time t) const
 int_0^t y1^2(s) exp(2*int_0^s y2(u) du) ds More...
 
Real direct1 (const Real x) const
 
Real inverse1 (const Real y) const
 
Real direct2 (const Real x) const
 
Real inverse2 (const Real y) const
 

Protected Attributes

const Array t1_
 
const Array t2_
 
Array tUnion_
 
const QuantLib::ext::shared_ptr< PseudoParametery1_
 
const QuantLib::ext::shared_ptr< PseudoParametery2_
 
Array y1Union_
 
Array y2Union_
 

Private Attributes

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

Detailed Description

Piecewise Constant Helper 3.

Definition at line 127 of file piecewiseconstanthelper.hpp.

Constructor & Destructor Documentation

◆ PiecewiseConstantHelper3() [1/2]

PiecewiseConstantHelper3 ( const Array &  t1,
const Array &  t2,
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint1 = QuantLib::ext::make_shared< QuantLib::NoConstraint >(),
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint2 = QuantLib::ext::make_shared< QuantLib::NoConstraint >() 
)

◆ PiecewiseConstantHelper3() [2/2]

PiecewiseConstantHelper3 ( const std::vector< Date > &  dates1,
const std::vector< Date > &  dates2,
const Handle< YieldTermStructure > &  yts,
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint1 = QuantLib::ext::make_shared< QuantLib::NoConstraint >(),
const QuantLib::ext::shared_ptr< QuantLib::Constraint > &  constraint2 = QuantLib::ext::make_shared< QuantLib::NoConstraint >() 
)

Member Function Documentation

◆ t1()

const Array & t1 ( ) const

Definition at line 220 of file piecewiseconstanthelper.hpp.

+ Here is the caller graph for this function:

◆ t2()

const Array & t2 ( ) const

Definition at line 221 of file piecewiseconstanthelper.hpp.

◆ tUnion()

const Array & tUnion ( ) const

Definition at line 222 of file piecewiseconstanthelper.hpp.

+ Here is the caller graph for this function:

◆ p1()

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

Definition at line 224 of file piecewiseconstanthelper.hpp.

224{ return y1_; }
const QuantLib::ext::shared_ptr< PseudoParameter > y1_
+ Here is the caller graph for this function:

◆ p2()

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

Definition at line 226 of file piecewiseconstanthelper.hpp.

226{ return y2_; }
const QuantLib::ext::shared_ptr< PseudoParameter > y2_
+ Here is the caller graph for this function:

◆ update()

void update ( ) const

Definition at line 236 of file piecewiseconstanthelper.hpp.

236 {
237 std::vector<Real> tTmp(t1_.begin(), t1_.end());
238 tTmp.insert(tTmp.end(), t2_.begin(), t2_.end());
239 std::sort(tTmp.begin(), tTmp.end());
240 std::vector<Real>::const_iterator end =
241 std::unique(tTmp.begin(), tTmp.end(), [](const Real x, const Real y) { return QuantLib::close_enough(x, y); });
242 tTmp.resize(end - tTmp.begin());
243 tUnion_ = Array(tTmp.begin(), tTmp.end());
244 y1Union_ = Array(tUnion_.size() + 1);
245 y2Union_ = Array(tUnion_.size() + 1);
246 for (Size i = 0; i < tUnion_.size() + 1; ++i) {
247 // choose a safe t for y1 and y2 evaluation
248 Real t = (i == tUnion_.size() ? (tUnion_.size() == 0 ? 1.0 : tUnion_.back() + 1.0)
249 : (0.5 * (tUnion_[i] + (i > 0 ? tUnion_[i - 1] : 0.0))));
250 y1Union_[i] = QL_PIECEWISE_FUNCTION(t1_, y1_->params(), t);
251 y2Union_[i] = QL_PIECEWISE_FUNCTION(t2_, y2_->params(), t);
252 }
253 Real sum = 0.0, sum2 = 0.0;
254 b_.resize(tUnion_.size());
255 c_.resize(tUnion_.size());
256 for (Size i = 0; i < tUnion_.size(); ++i) {
257 Real t0 = (i == 0 ? 0.0 : tUnion_[i - 1]);
258 sum += direct2(y2Union_[i]) * (tUnion_[i] - t0);
259 b_[i] = sum;
260 Real b2Tmp = (i == 0 ? 0.0 : b_[i - 1]);
261 if (std::fabs(direct2(y2Union_[i])) < zeroCutoff_) {
262 sum2 += direct1(y1Union_[i]) * direct1(y1Union_[i]) * (tUnion_[i] - t0) * std::exp(2.0 * b2Tmp);
263 } else {
264 sum2 += direct1(y1Union_[i]) * direct1(y1Union_[i]) *
265 (std::exp(2.0 * b2Tmp + 2.0 * direct2(y2Union_[i]) * (tUnion_[i] - t0)) - std::exp(2.0 * b2Tmp)) /
266 (2.0 * direct2(y2Union_[i]));
267 }
268 c_[i] = sum2;
269 }
270}
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:

◆ y1()

Real y1 ( const Time  t) const

this returns the transformed value

Definition at line 280 of file piecewiseconstanthelper.hpp.

280 {
281 return direct1(QL_PIECEWISE_FUNCTION(t1_, y1_->params(), t));
282}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ y2()

Real y2 ( const Time  t) const

this returns the transformed value

Definition at line 284 of file piecewiseconstanthelper.hpp.

284 {
285 return direct2(QL_PIECEWISE_FUNCTION(t2_, y2_->params(), t));
286}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ int_y1_sqr_exp_2_int_y2()

Real int_y1_sqr_exp_2_int_y2 ( const Time  t) const

int_0^t y1^2(s) exp(2*int_0^s y2(u) du) ds

Definition at line 330 of file piecewiseconstanthelper.hpp.

330 {
331 if (t < 0.0)
332 return 0.0;
333 Size i = std::upper_bound(tUnion_.begin(), tUnion_.end(), t) - tUnion_.begin();
334 Real res = 0.0;
335 if (i >= 1)
336 res += c_[std::min(i - 1, c_.size() - 1)];
337 Real a = direct2(y2Union_[std::min(i, y2Union_.size() - 1)]);
338 Real b = direct1(y1Union_[std::min(i, y1Union_.size() - 1)]);
339 Real t0 = (i == 0 ? 0.0 : tUnion_[i - 1]);
340 Real b2Tmp = (i == 0 ? 0.0 : b_[i - 1]);
341 if (std::fabs(a) < zeroCutoff_) {
342 res += b * b * std::exp(2.0 * b2Tmp) * (t - t0);
343 } else {
344 res += b * b * (std::exp(2.0 * b2Tmp + 2.0 * a * (t - t0)) - std::exp(2.0 * b2Tmp)) / (2.0 * a);
345 }
346 return res;
347}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ direct1()

Real direct1 ( const Real  x) const

Definition at line 228 of file piecewiseconstanthelper.hpp.

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

◆ inverse1()

Real inverse1 ( const Real  y) const

Definition at line 230 of file piecewiseconstanthelper.hpp.

230{ return std::sqrt(y); }
+ Here is the caller graph for this function:

◆ direct2()

Real direct2 ( const Real  x) const

Definition at line 232 of file piecewiseconstanthelper.hpp.

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

◆ inverse2()

Real inverse2 ( const Real  y) const

Definition at line 234 of file piecewiseconstanthelper.hpp.

234{ return y; }

Member Data Documentation

◆ zeroCutoff_

const Real zeroCutoff_
private

Definition at line 157 of file piecewiseconstanthelper.hpp.

◆ t1_

const Array t1_
protected

Definition at line 160 of file piecewiseconstanthelper.hpp.

◆ t2_

const Array t2_
protected

Definition at line 160 of file piecewiseconstanthelper.hpp.

◆ tUnion_

Array tUnion_
mutableprotected

Definition at line 161 of file piecewiseconstanthelper.hpp.

◆ y1_

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

y1, y2 are the raw values in the sense of parameter transformation

Definition at line 163 of file piecewiseconstanthelper.hpp.

◆ y2_

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

Definition at line 163 of file piecewiseconstanthelper.hpp.

◆ y1Union_

Array y1Union_
mutableprotected

Definition at line 164 of file piecewiseconstanthelper.hpp.

◆ y2Union_

Array y2Union_
protected

Definition at line 164 of file piecewiseconstanthelper.hpp.

◆ b_

std::vector<Real> b_
mutableprivate

Definition at line 167 of file piecewiseconstanthelper.hpp.

◆ c_

std::vector<Real> c_
private

Definition at line 167 of file piecewiseconstanthelper.hpp.