Sunday, 24 November 2013

Annuities - Limited Term

Yearly Annuities Limited

An yearly annuity for n years can be either due or in arrears. If it is "due", then it has an initial payment of 1 and last payment after (n-1) years. If it is "in arrears", then the first payment is after 1 year and the last is after n years.

The annuity due can be calculated using a very similar recursive approach as in the previous post:
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
open System.Collections.Generic
/// memoized version of annuity due for n years
let rec mem_ladxn = memoize (fun x n ->
    // calculate components
    let px = book_px x
    let v = 1.0/1.05
    //calculate result
    if n>1.0 then 1.0 + v*px*(mem_ladxn (x+1.0) (n-1.0)) else 1.0)

The annuity in arrears for n years can be calculated by subtracting 1 from the annuity in advance for n+1 years.

Quarterly Annuities Limited

An quarterly annuity for n years can be calculated very similarly to a yearly annuity. It seems simplest also to use a similar approach for the annuity in arrears:
 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
open System.Collections.Generic
/// memoized version of annuity due quarterly for n years
let rec mem_ladxn4 = memoize (fun x n ->
    // calculate components
    let px4 = book_px4 x
    let v4 = (1.0/1.05)**(1.0/4.0)
    //calculate result
    if n>0.25 then 0.25 + v4*px4*(mem_ladxn4 (x+0.25) (n-0.25)) else 0.25)
/// memoized version of annuity due quarterly for n years
let rec mem_laxn4 = memoize (fun x n ->
    // calculate components
    let px4 = book_px4 x
    let v4 = (1.0/1.05)**(1.0/4.0)
    //calculate result
    if n>0.25 then 0.25*v4*px4 + v4*px4*(mem_laxn4 (x+0.25) (n-0.25)) else 0.25*v4*px4)

We can then use FCell to present the results of these calculations:


These are the same results as on page 123 of the book.