Finance functions

You're viewing an older version of this page (#341). View the current version.

View versions (2)

Interface

#include <codecogs/finance/banking/accruedinterest.h>

using namespace Finance::Banking;

Returns the accrued interest for a security that pays interest at maturity.

The function is based on the following equation:

Accrued = par*rate*frac{A}{D}
(1)

Where

  • par is the par value of the security (if not specified, \1,000 is assumed),
  • rate is the security's annual coupon rate
  • A is the days from the issue date to maturity, and
  • D is the number of days in a year, depending on the year basis.

This function differs from its Excel cousin in that it performs a more accurate calculation of securities using the Actual/Actual day count basis, when WorkLikeExcel=false. Specifically, it accurately determines if the settlement date falls in a leap year (Excel thinks that every 4th year is a leap year, see isLeapYear), and we also check if the 'leap day'; on the 29th Feb falls between the maturity and settlement dates. Only when these two conditions are satisfied is the year assumed to have 366 days. In insances when the settlement to maturity span several years, and one or more of these years is a leap years, then the average of the year lengths is used.

See totalReceived for details of an ongoing very minor bug to the calculations using yb_Act when replicating Excel's behaviour. The following example illustrates the difference with this function:

accruedInterest(date(1995,5,2), date(1996,3,5), 738, 0.057, yb_Act, true) -> 35.39980328
ACCRINTM('2/5/1995', '5/3/1996', 738 0.057, 1) -> 35.448230

If rate or par is less than or equal to 0, or the issue date is greater than the maturity date, the function will return a value of -1.

Example 1

#include <iostream>
#include <codecogs/finance/banking/accruedinterest.h>

int main()
{ 
  std::cout << Finance::Banking::accruedInterest(Units::Date::date(1998,4,1), Units::Date::date(1998,6,15), 0.1, 1000, Finance::Banking::yb_Act365);
  return 0;
}

Output:

20.5479

Parameters

issue
is the issue date when
Blank

the security is issued to the buyer in Julian date form

Parameters

maturity
is security's maturity date, expressed as a serial
Blank

Julian date number

Parameters

rate
is the coupon rate of the security
par
is the value of the security (defaults to \1,000 if omitted)
basis
is the day count basis, where:
Blank

\copydoc YearBasis

Parameters

WorkLikeExcel
emulates Excel's "wrong" calculation of Actual/actual; see documentation for details....
GPL Licence — free for non commercial use. See Licence details.