Welcome back. In my last post I showed how to calculate the future value of a loan, that is the amount owed when the loan is due assuming a one year term at a 5% annual rate compounded annually. The code is repeated below:
Let’s go through this code and highlight some of the key statements. First and most important is the class that represents the loan, FixedRateCoupon. The FixedRateCoupon class models a payment where the dollar amount due at the payment date is specified at the inception of the loan. Our simple loan has one payment, the premium plus the interest, which is owed the lender when the loan is due. I aliased the FixedRateCoupon class with a typedef to create a Loan abstraction that, hopefully, makes subsequent code more intuitive.
The next several lines just define the loan’s term, premium and interest rate using specialized QuantLib data types, such as Natural and Real. In the next two lines, today’s date is established and the payment date is calculated with respect to today’s date.
In the following line, an instance of the Loan class is declared, given the loan parameters previously defined. The ActualActual() argument is the ‘day count’ convention for the loan. I’ll cover day count conventions in a future post, but suffice it to say that different types of loans are priced using different day count conventions.
Finally, the final payment is calculated by adding the interest due on the loan, obtained with the accruedAmount() method, to the loan principal. As is probably obvious, the argument to accruedAmount() is the date that the loan matures and the loan repayment is due.
I hope that the code makes sense. If you have any questions about anything that I haven’t covered, I encourage you to consult the QuantLib documentation.
Rather than jump into the calculation of present value and interest rates as I had originally planned, I will instead defer those topics to my next post. Thanks for visiting my blog and feel free to leave a comment or question.