Introducing QuantLib: Interest Rate Conversions

For those of you who read the last installment of my series on QuantLib, you are now familiar with QuantLib’s InterestRate class. In this post, I’ll provide an example of  how to compare interest rates that have different compounding periods and/or payment frequencies.

Here is the code:

BOOST_AUTO_TEST_CASE(testInterestRateConversions) {

//annual/effective rate
Rate annualRate = .05;

//5% rate compounded annually
InterestRate effectiveRate(annualRate, ActualActual(), Compounded, Annual);
std::cout << “Rate with annual compounding is: ” << effectiveRate.rate() << std::endl;

//what is the equivalent semi-annual one year rate?
InterestRate semiAnnualCompoundingOneYearRate = effectiveRate.equivalentRate(Compounded, Semiannual, 1);
std::cout << “Equivalent one year semi-annually compounded rate is: ” << semiAnnualCompoundingOneYearRate.rate() << std::endl;

//what is the equivalent 1 year rate if compounded continuously?
InterestRate continuousOneYearRate = effectiveRate.equivalentRate(Continuous, Annual, 1);
std::cout << “Equivalent one year continuously compounded rate is: ” << continuousOneYearRate.rate() << std::endl;

The output of this code when run is:

Rate with annual compounding is: 0.05
Equivalent one year semi-annually compounded rate is: 0.0493902
Equivalent one year continuously compounded rate is: 0.0487902

Let me take you through the example. It calculates the the equivalent rates required to match the interest generated by a 5% annual rate, compounded annually, first with semi-annual compounding then with continuous compounding.  Semi-annual compounding means the interest paid in the first 6 month period is rolled over, with the principal, into the next 6 month period. Since there are two compounding periods, the equivalent rate is lower. That is, a 4.93% annual rate, compounded semi-annually pays the same amount of interest as a 5% rate, compounded annually. Similarly, if interest is paid on a continuous compounding basis, then the interest rate need only be 4.87% to generate the same amount of interest as the 5% annual rate, compounded annually. Generally speaking, then, the more compounding periods, the lower the equivalent interest relative to the effective rate, typically expressed as an annual rate, compounded annually.

Now that you understand the nuances of comparing interest rates with the same duration and different compounding periods, you’re ready to dive into my next topic- the term structure of interest rates. An interest rate term structure, or yield curve, depicts the difference in the market rate of interest on short term loans versus the market rate for longer term loans or cash flows. Typically, long term rates are higher than short-term rates. There are many theories which attempt to explain this phenomenon, but that is beyond the scope of this post.

Suffice it to say that QuantLib provides excellent support for constructing and manipulating yield curves through the YieldTermStructure class. In my next post, I’ll demonstrate how to construct a YieldTermStructure instance and use it to price a fixed-rate bond.  As I stated in my previous post, this is a more realistic and flexible way of pricing bonds than the more academic bond pricing example that you’ve seen already.

As always, thanks for reading my blog and be sure to check back soon!


About Mick Hittesdorf

Analytics Platform Manager
This entry was posted in QuantLib and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s