User:Devon McCormick/ExceltoJRosetta/ACCRINTM

From J Wiki
Jump to navigation Jump to search

How to calculate accrued interest paid at maturity of a security, the way the Excel function ACCRINTM does.

For example:

$10000 par, 10% interest, Actual/365, issue date 4/1/2008, maturity 6/15/2008

  1000*0.10*365%~2-~/\todayno 0 100 100#:"(1 0) 20080401 20080615
20.5479

So, we could define accrintm explicitly:

require 'dates'
accrintm=: 3 : 0
   'par int dcf issue maturity'=. y
   par*int*dcf%~2-~/\todayno 0 100 100#:"(1 0) issue,maturity
)

   accrintm 1000 0.10 365 20080401 20080615
20.5479

Or, tacitly:

   accrintm=: [: */(2{.]),(2{]) %~ 2-~/\ [: todayno 0 100 100 (#:"1 0) _2{.]
   accrintm 1000 0.10 365 20080401 20080615
20.5479