1
$\begingroup$

I want to port some QuantLib-Swig dependent code written in Python to C++ with QuanLib-1.17. However some YieldTermStructure classes (PiecewiseLogCubicDiscount, PiecewiseLinearZero and PiecewiseCubicZero) are not present in QuantLib-1.17.

I found some yield curve examples that seems to cover those classes' functionalities. However, I want to know can't I find the equivalent of these classes in QuantLib-1.17 C++?

$\endgroup$

1 Answer 1

1
$\begingroup$

I found the reason why there are no specific versions of those classes by discussing with the developer of QuantLib. He stated that

those classes are instances of a single PiecewiseYieldCurve class template in C++, but need to be exported as separate classes to Python where there are no templates.

I implemented a function template calculateCurve and also implemented a main function to show calls to calculateCurve:

template<class T, class I, template<class C> class B>
ext::shared_ptr<YieldTermStructure>
calculateCurve(Date &settlementDate,
               std::vector<ext::shared_ptr<RateHelper>> rateHelpers,
               DayCounter dayCounter,
               const I &interpolator = I())
{
    auto termStructure = ext::shared_ptr<YieldTermStructure>(new PiecewiseYieldCurve<T, I, B>(settlementDate,
                                                                                              rateHelpers,
                                                                                              dayCounter,
                                                                                              interpolator));
    return termStructure;
}



int main()
{
    ext::shared_ptr<Quote> rate(new SimpleQuote(0.0019121));
    ext::shared_ptr<RateHelper> rateHelper(new DepositRateHelper(
            Handle<Quote>(rate),
            Period(0, Days),
            2,
            TARGET(),
            Following,
            true,
            ActualActual()
    ));
    std::vector<ext::shared_ptr<RateHelper>> rateHelpers{rateHelper};

    Date settlementDate = Date(01, January, 2017);
    DayCounter dayCounter = Actual360();

    // PiecewiseLogCubicDiscount
    auto result = calculateCurve<Discount, LogCubic, IterativeBootstrap>(
            settlementDate,
            rateHelpers,
            dayCounter,
            LogCubic(CubicInterpolation::Spline));

    // PiecewiseCubicZero
    result = calculateCurve<ZeroYield, Cubic, IterativeBootstrap>(
            settlementDate,
            rateHelpers,
            dayCounter,
            Cubic(CubicInterpolation::Spline));

    // PiecewiseLinearZero
    result = calculateCurve<ZeroYield, Linear, IterativeBootstrap>(
            settlementDate,
            rateHelpers,
            dayCounter);

    return 0;
}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.