Header menu logo FSharp.Finance.Personal

UK APR calculation

Basic example

The following example shows a loan of £500.00 taken out on 10th October 2012 and repaid in two monthly instalments:

#r "nuget:FSharp.Finance.Personal"

open FSharp.Finance.Personal
open Apr
open Calculation
open DateDay

let startDate = Date(2012, 10, 10)

let principal = 500_00L<Cent>

let transfers = [|
    { TransferType = Payment; TransferDate = Date(2012, 11, 10); Value = 270_00L<Cent> }
    { TransferType = Payment; TransferDate = Date(2012, 12, 10); Value = 270_00L<Cent> }
|]

let aprMethod = CalculationMethod.UnitedKingdom 3

let solution = Apr.calculate aprMethod principal startDate transfers
solution
Found (0.8463084539241773248233023126M, 6, 0.000001M)

This result is of an Array.Solution type. Found means that it was able to find a solution. The APR, expressed as a decimal, is returned as the first item of the tuple. The APR is more usefully shown as a percentage, which can easily be done as follows:

solution |> toPercent aprMethod
ValueSome (Percent 84.600M)

Notes

Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
namespace FSharp.Finance
namespace FSharp.Finance.Personal
module Apr from FSharp.Finance.Personal
<summary> calculating the APR according to various country-specific regulations </summary>
module Calculation from FSharp.Finance.Personal
<summary> convenience functions and options to help with calculations </summary>
module DateDay from FSharp.Finance.Personal
<summary> a .NET Framework polyfill equivalent to the DateOnly structure in .NET Core </summary>
val startDate: Date
Multiple items
[<Struct>] type Date = new: year: int * month: int * day: int -> Date val Year: int val Month: int val Day: int member AddDays: i: int -> Date member AddMonths: i: int -> Date member AddYears: i: int -> Date member ToDateTime: unit -> DateTime override ToString: unit -> string static member (-) : d1: Date * d2: Date -> TimeSpan ...
<summary> the date at the customer's location - ensure any time-zone conversion is performed before using this - as all calculations are date-only with no time component, summer time or other such time artefacts </summary>

--------------------
Date ()
new: year: int * month: int * day: int -> Date
val principal: int64<Cent>
Multiple items
module Cent from FSharp.Finance.Personal.Calculation
<summary> utility functions for base currency unit values </summary>

--------------------
[<Measure>] type Cent
<summary> the base unit of a currency (cent, penny, øre etc.) </summary>
val transfers: Transfer array
[<Struct>] type TransferType = | Advance | Payment
<summary> whether a transfer is an advance or a payment </summary>
union case TransferType.Payment: TransferType
<summary> incoming transfer </summary>
val aprMethod: CalculationMethod
[<Struct>] type CalculationMethod = | UnitedKingdom of UkPrecision: int | UsActuarial of UsPrecision: int | UnitedStatesRule
<summary> the calculation method used to determine the APR </summary>
union case CalculationMethod.UnitedKingdom: UkPrecision: int -> CalculationMethod
<summary> calculates the APR according to UK FCA rules to the stated decimal precision (note that this is two places more than the percent precision) </summary>
val solution: Solution
val calculate: method: CalculationMethod -> advanceValue: int64<Cent> -> advanceDate: Date -> transfers: Transfer array -> Solution
<summary> calculates the APR to a given precision for a single-advance transaction where the consummation date, first finance-charge earned date and advance date are all the same </summary>
val toPercent: aprMethod: CalculationMethod -> aprSolution: Solution -> Percent voption
<summary> converts an APR solution to a percentage, if possible </summary>

Type something to start searching.