### Yearly Benefits

We first consider the yearly value of a benefits of 1 payable at the end of the year of death. This can be calculated using a recursive formula:We will use the Survival Model described in the previous post. We will use a discount rate of 5%. We will assume that death is certain if you reach age 129, i.e. the probability of death is 1. This gives this code:

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
/// px generated for book referencing Makehams formula let rec book_px x = let A = 0.00022 let B = 0.0000027 let c = 1.124 //calculate result makeham_tpx A B c x 1.0 /// Ax generated for book let rec book_Ax x = // calculate components let px = book_px x let qx = 1.0 - px let v = 1.0/1.05 //calculate result if x<129.0 then v*qx + v*px*book_Ax(x+1.0) else v |

Note however that this will be very slow at young ages as all older ages will need to be calculated. A standard approach to deal with this performance issue is to use "memoization". A number of examples of this can be found on the F# Snippets site. We will use the snippet provide by Tomas Petricek.

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: |
open System.Collections.Generic /// The function creates a function that calls the argument 'f' /// only once and stores the result in a mutable dictionary (cache) /// Repeated calls to the resulting function return cached values. let memoize f = // Create (mutable) cache that is used for storing results of // for function arguments that were already calculated. let cache = new Dictionary<_, _>() (fun x -> // The returned function first performs a cache lookup let succ, v = cache.TryGetValue(x) if succ then v else // If value was not found, calculate & cache it let v = f(x) cache.Add(x, v) v) /// memoized version of Ax let rec mem_Ax = memoize (fun x -> // calculate components let px = book_px x let qx = 1.0 - px let v = 1.0/1.05 //calculate result if x<129.0 then v*qx + v*px*mem_Ax(x+1.0)) else v |

These correspond to the results on page 83 of the book.

### Monthly Benefits

Now we can do the same for monthly benefits, which can also be calculated using a recursive formula:We use the same Survival Model with a discount rate of 5% and assuming death is certain if you reach age 129. This gives this code:

1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
/// monthly px generated for book referencing Makehams formula let rec book_px12 x = let A = 0.00022 let B = 0.0000027 let c = 1.124 //calculate result makeham_tpx A B c x (1.0/12.0) /// monthly Ax generated for book let rec book_Ax12 x = // calculate components let px12 = book_px12 x let qx12 = 1.0 - px12 let v12 = (1.0/1.05)**(1.0/12.0) //calculate result if x<129.0 then v12*qx12 + v12*px12*book_Ax12(x+1.0/12.0) else v12 |

These correspond to the results on page 84 of the book.

## No comments:

## Post a Comment