Re: What does this forward curve primitive function do?
Posted by
Peter Caspers-4 on
Mar 16, 2017; 7:52pm
URL: http://quantlib.414.s1.nabble.com/What-does-this-forward-curve-primitive-function-do-tp18145p18146.html
Hi Ted,
In zeroYieldImpl(Time t) the integral from 0 to t over the instantaneous forward rate is computed (to get the zero yield times t at t), in your example this would be the integral from 0 to t2, not from t2 to t3.
The integration uses the primitive function (i.e. the function F with F(x0)=0 and whose derivative is the interpolating function) provided by the interpolation. In your case it seems to be LinearInterpolation. Now the interpolation could in general use a numerical integration scheme, but in the case of a linear interpolation it is of course much more efficient to code the primitive function directly, which is done in the second code snippet you posted (the primitiveConst_ values are precomputed in the update() method).
Best
Peter
I have an object for InterpolatedForwardCurve and I try to calculate implied discount rate. The implementation calls InterpolatedForwardCurve<T>::zeroYieldImpl.
The source code for
InterpolatedForwardCurve<T>::zeroYieldImpl:
template <class T>
Rate InterpolatedForwardCurve<T>::zeroYieldImpl(Time t) const {
if (t == 0.0)
return forwardImpl(0.0);
Real integral;
if (t <= this->times_.back()) {
integral = this->interpolation_.primitive(t, true);
} else {
// flat fwd extrapolation
integral = this->interpolation_.primitive(this->times_.back(), true)
+ this->data_.back()*(t - this->times_.back());
}
return integral/t;
}
My code runs into integral = this->interpolation_.primitive(t, true);
The implementation for the primitive function is:
Real primitive(Real x) const {
Size i = this->locate(x);
Real dx = x-this->xBegin_[i];
return primitiveConst_[i] +
dx*(this->yBegin_[i] + 0.5*dx*s_[i]);
}
Let's say my curve defines for {t1, t2, t3, t4}. I try to calculate discount rate at t2.
Q1: I think the code is trying to do numerical integration from t2 to t3. Am I correct?
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites,
Slashdot.org!
http://sdm.link/slashdot_______________________________________________QuantLib-users mailing list
[hidden email]https://lists.sourceforge.net/lists/listinfo/quantlib-users
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org!
http://sdm.link/slashdot_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users