Quantcast

What does this forward curve primitive function do?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What does this forward curve primitive function do?

Student T

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?
Q2: What numerical integration technique is it using? I can't relate the code with the techniques defined in wikipedia for numerical integration.



------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What does this forward curve primitive function do?

Peter Caspers-4
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

On 16 Mar 2017, at 14:42, Ted Wong <[hidden email]> wrote:


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?
Q2: What numerical integration technique is it using? I can't relate the code with the techniques defined in wikipedia for numerical integration.


------------------------------------------------------------------------------
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
Loading...