Guide 07 Year fractions and day counts

Dates

Day counts with the conventions of the Matlab Financial Toolbox, on the Date type of the standard library Dates.

yearfracdaysactExcel
using FinancialToolbox, Dates
start, stop = Date(1996, 10, 12), Date(1998, 1, 10)
daysact(start, stop)
455

yearfrac takes the convention as an integer basis, from 0 to 7:

conventions = ["ACT/ACT", "30/360 SIA", "ACT/360", "ACT/365", "30/360 PSA", "30/360 ISDA", "30E/360", "ACT/365 JPN"]
[conventions[basis + 1] => yearfrac(start, stop, basis) for basis in 0:7]
8-element Vector{Pair{String, Float64}}:
     "ACT/ACT" => 1.2465753424657535
  "30/360 SIA" => 1.2444444444444445
     "ACT/360" => 1.2638888888888888
     "ACT/365" => 1.2465753424657535
  "30/360 PSA" => 1.2444444444444445
 "30/360 ISDA" => 1.2444444444444445
     "30E/360" => 1.2444444444444445
 "ACT/365 JPN" => 1.2465753424657535

Excel stores dates as serial numbers, converted by fromExcelNumberToDate:

fromExcelNumberToDate(45000)
2023-03-15