The fixed income market is a significant part of the financial industry, with pension funds and institutional funds allocating significant money to it due to its predictable income stream. Fixed income investments involve a contractually defined exchange between two parties, with cash flows assigned based on interest rates and the time of cash exchanges. There are various types of investments vehicles, including money market funds, bonds, and certificates of deposit (CD).
These investments offer a relatively safe investment opportunity with known and predictable returns. Compared to the stock market, fixed income investments are easier to analyze due to their contract that guarantees the return for a specified period. However, there are risks associated with fixed income investments, such as the default of the issuing institution and the rate of return not coping with inflation.
Analyzing fixed income investments is not as easy as it seems, and money managers need reliable software to determine the best among various fixed income investments. Fixed income investments pose complex risks influenced by the future economic environment, necessitating careful consideration of these risks, with high-quality software aiding investors in addressing these external factors.
Fixed income investments involve a well-defined interest rate, principal, compound interest, continuous compounding, and present value. The interest rate represents the return of investment in percentage points for a given period, while principal is the original investment value. Compound interest accrues over time and is added to principal through regular payments. Continuous compounding increases the effect of compound interest, and present value is a powerful tool for comparing two cash flow streams when scheduled with an interest rate.
Interest rates determine financial institution's payment for holding a cash deposit over time. Let's calculate future deposit value based on interest rate and initial deposit value. The mathematic equation can be used to calculate interest rates for a single period, involving future value and deposit present value.
The following source code,SimpleIntRate class is an example that calculates single period interest rates:
// SimpleIntRate.h
#ifndef __Fin__SimpleIntRate__
#define __Fin__SimpleIntRate__
#include <iostream>
class SimpleIntRate
{
public:
SimpleIntRate (double rate);
SimpleIntRate (const SimpleIntRate & v);
SimpleIntRate & operator = (const SimpleIntRate & v);
~SimpleIntRate ();
double singlePeriod (double value);
private:
double m_rate;
};
inline double SimpleIntRate::singlePeriod (double value)
{
return value * (1 + this->m_rate);
}
#endif /* defined(__Fin__simpleInterestRate__) */
The SimpleIntRate class defines constructor, destructor, copy constructor, and assignment operator, ensuring a well-defined interface. This object-oriented design principle simplifies maintenance and avoids costly mistakes. Creating your own versions of these member functions ensures desired behavior, rather than relying on compiler writers' decisions. This increased organization in C++ classes pays off in the long run.
SimpleIntRate (double rate);
The default constructor is automatically added to a class, allowing object creation even if not included. However, it is not included if another constructor requires arguments, like SimpleIntRate, which requires a valid argument.
SimpleIntRate (const SimpleIntRate & v);
The copy constructor is a method that creates copies of an existing object of the same class, essential when adding objects to containers like vectors, maps, and multimaps in the STL.
double singlePeriod (double value);
The action that returns the future value of a deposit after a single period is contained in the singlePeriod member function. This can relate to either one month or one year of interest, depending on the terms of the loan or the supplied parameters.
inline double SimpleIntRate::singlePeriod (double value)
{
double f = value * (1 + this->m_rate);
return f;
}
The SimpleIntRate class uses the double type for precision instead of float. It has a single member variable, m_rate, which stores the current interest rate. Unlike the original code, you don't need to input the interest rate every time you call the singlePeriod member function; just provide it as a parameter when creating a new instance of SimpleIntRate.
In C++, the inline keyword suggests that a member function should be directly embedded in the calling code. This means there's no performance penalty for function calls, as the compiler substitutes the function's content directly. It's like a more powerful macro with the benefits of function calls. High-performance C++ code often uses inline member functions for even better performance. This flexibility sets C++ apart from other languages.
// SimpleIntRate.cpp
#include "SimpleIntRate.h"
SimpleIntRate::SimpleIntRate(double rate)
: m_rate(rate)
{
}
SimpleIntRate::~SimpleIntRate()
{
}
SimpleIntRate::SimpleIntRate(const SimpleIntRate &v)
: m_rate(v.m_rate)
{
}
SimpleIntRate &SimpleIntRate::operator=(const SimpleIntRate &v)
{
if (&v != this)
{
this->m_rate = v.m_rate;
}
return *this;
}
//
// main.cpp
#include "SimpleIntRate.h"
#include <iostream>
int main(void)
{
double rate = 0.08;
double inv = 10000;
SimpleIntRate fvInv(rate);
double result = fvInv.singlePeriod(inv);
std::cout << "The future value of an investment of "<<inv
<<" at an "<<rate*100
<<"% interest rate is "<<result
<<" after a single period";
return 0;
}
You could get the following result;
The future value of an investment of 10000 at an 8% interest rate is 10800 after a single period
Simple interest rates can analyze single-period cash flows, but compound interest is crucial for financial operations with multiple periods, such as loans, calculating the principal value's compound interest over N time periods.
Interest can be calculated as a discrete or continuous compounding process, with discrete compounding occurring at regular intervals. The formula for discrete compounded interest rate is , where P is present value, V is future value, R is interest rate.
Continuous compounding calculation assumes payments are made continuously over time, determining the future value of a financial application. The formula is , where V is the desired future value, P is the present value, R is the interest rate, and N is the number of periods.
//
// compoundInterestRate.h
#ifndef __Fin__CompoundIntRateCalculator__
#define __Fin__CompoundIntRateCalculator__
class compoundInterestRate {
public:
compoundInterestRate(double rate);
compoundInterestRate(const compoundInterestRate &v);
compoundInterestRate &operator =(const compoundInterestRate &v);
~compoundInterestRate();
double discretCompounding(double value, int numPeriods);
double continuCompounding(double value, int numPeriods);
private:
double m_rate;
};
#endif /* defined(__Fin__compoundInterestRate__) */
The mathematical functions pow and exp from the standard C++ library are used by the two member functions, discretCompounding and continuCompounding, to compute the provided formulas. The power function and the exponential function can be quickly calculated with the help of these two functions.
Include the cmath header file before using any mathematical function from the standard library.
//
// compoundInterestRate.cpp
#include "compoundInterestRate.h"
#include <cmath>
compoundInterestRate::compoundInterestRate(double rate)
: m_rate(rate)
{
}
compoundInterestRate::~compoundInterestRate()
{
}
compoundInterestRate::compoundInterestRate(const compoundInterestRate &v)
: m_rate(v.m_rate)
{
}
compoundInterestRate &compoundInterestRate::operator =(const compoundInterestRate &v)
{
if (this != &v)
{
this->m_rate = v.m_rate;
}
return *this;
}
double compoundInterestRate::discretCompounding(double value, int numPeriods)
{
return value * pow(1 + m_rate, numPeriods);
}
double compoundInterestRate::continuCompounding(double value, int numPeriods)
{
return value * exp(m_rate * numPeriods);
}
//
// main.cpp
#include "compoundInterestRate.h"
#include <iostream>
// the main function receives parameters passed to the program
int main(void)
{
double rate = 0.05;
double inv = 1000;
int num_periods = 4;
compoundInterestRate cIR(rate);
double dcrtRes = cIR.discretCompounding(inv, num_periods);
double contRes = cIR.continuCompounding(inv, num_periods);
std::cout << " FV with discrete compounding : " << dcrtRes << std::endl;
std::cout << " FV with continuous compounding : " << contRes << std::endl;
return 0;
}
You could get the following result;
FV with discrete compounding is 1215.51
FV with continuous compounding is 1221.4
Continuous compounding yields a slightly higher value compared to discrete compounding.
Fixed income investments are based on the cash flow between two parties, which should be equal in value. This is achieved through the concept of present value, where the present value of a future payment is discounted by the interest rate applied to that same value. The principle of value compounding, which states that money in one's pocket today is more valuable than the same money received in the future, can be quantified using this knowledge. The formula for determining the present value of a future payment is .
The equation for PV involves discounting a future value FV, calculating the interest rate R, and dividing the present value by the number of periods between the two, resembling the calculation of compound interest rate.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include "Cashflow.h"
#include <iostream>
#include <cstdlib>
int main(int argc, const char* argv[])
{
double rate = atof(argv[1]);
int period = 1;
Cashflow cf(rate);
for(int p=2;p<argc;p++)
{
double cashflow=atof(argv[p]);
cf.addCashflow(period++,cashflow);
}
std::cout << " PV : " << cf.presentValue() << std::endl;
return 0;
}
//
// Cashflow.h
#ifndef __Fin__Cashflow__
#define __Fin__Cashflow__
#include <vector>
class Cashflow {
public:
Cashflow(double rate);
Cashflow(const Cashflow &v);
Cashflow &operator =(const Cashflow &v);
~Cashflow();
void addCashflow(int period, double cashflow);
double presentValue();
private:
std::vector<double> m_cashflow;
std::vector<int> m_periods;
double m_rate;
double presentValue(int period, double cashflow);
};
#endif /* defined(__Fin__Cashflow__) */
//
// Cashflow.cpp
#include "Cashflow.h"
#include <cmath>
#include <iostream>
Cashflow::Cashflow(double rate)
: m_rate(rate)
{
}
Cashflow::Cashflow(const Cashflow &v)
: m_rate(v.m_rate)
{
}
Cashflow::~Cashflow()
{
}
Cashflow &Cashflow::operator =(const Cashflow &v)
{
if (this != &v)
{
this->m_cashflow = v.m_cashflow;
this->m_periods = v.m_periods;
this->m_rate = v.m_rate;
}
return *this;
}
void Cashflow::addCashflow(int period, double cashflow)
{
m_periods.push_back(period);
m_cashflow.push_back(cashflow);
}
double Cashflow::presentValue(int period, double cashflow)
{
return cashflow / pow(1+m_rate, period);
}
double Cashflow::presentValue()
{
double total = 0;
for (int i=0; i<m_cashflow.size(); ++i)
{
total += presentValue(m_periods[i], m_cashflow[i]);
}
return total;
}
You could run and get the PV of cashflow as following;
./Cashflow 0.08 200 300 500 -1000
PV : 104.273
The code calculates the PV for cash flow components and sequences, validating fixed income instruments like loans by comparing time period-payment values. The PV should add to zero or close to zero.
Bonds are a common fixed income instrument used by corporations and governments to attract long-term investments, offering guaranteed periodic coupon payments and maturing between 5 and 30 years.
In the context of bonds, coupon and principal are key terms:
Principal: This is the face value or par value of the bond, which is the amount the issuer agrees to pay back to the bondholder at maturity. For example, if you buy a bond with a principal of $1,000, you will receive $1,000 back when the bond matures¹.
Coupon: This refers to the annual interest rate paid on the bond, expressed as a percentage of the principal. For instance, if a bond has a principal of $1,000 and a coupon rate of 5%, it will pay $50 in interest each year².
Bonds deposit the principal value at the beginning of the term, often repaid at maturity. Investors receive a constant coupon value between the initial investment and maturity, determining the bond's interest rate.
The term "coupon / principal" refers to the ratio of the annual interest payment (coupon) to the face value (principal) of a bond. This ratio is often used to express the bond's coupon rate as a percentage.
For example, if a bond has a principal (face value) of $1,000 and a coupon (annual interest payment) of $50, the coupon rate would be:
This means the bond pays 5% of its principal as interest each year.
Here’s a simple example of a bond calculator that calculates the price of a bond given its principal, coupon rate, and time to maturity:
#include <iostream>
#include <cmath>
class Bond {
private:
double principal;
double couponRate;
int yearsToMaturity;
public:
Bond(double principal, double couponRate, int yearsToMaturity) {
this->principal = principal;
this->couponRate = couponRate;
this->yearsToMaturity = yearsToMaturity;
}
double calculatePrice(double marketRate) {
double price = 0.0;
for (int i = 1; i <= yearsToMaturity; ++i) {
price += (principal * couponRate) / std::pow(1 + marketRate, i);
}
price += principal / std::pow(1 + marketRate, yearsToMaturity);
return price;
}
};
int main() {
double principal = 1000.0;
double couponRate = 0.05; // 5%
int yearsToMaturity = 10;
double marketRate = 0.04; // 4%
Bond myBond(principal, couponRate, yearsToMaturity);
double bondPrice = myBond.calculatePrice(marketRate);
std::cout << "The price of the bond is: $" << bondPrice << std::endl;
return 0;
}
This code defines a Bond class with methods to calculate the bond price based on the given market interest rate. The main function demonstrates how to use this class.
The result is as following:
The price of the bond is: $1081.11