### Example 3.13

I will replicate the Survival model specified in Example 3.13 on page 65 of the reference book.The ultimate rates of mortality are defined using Makeham's law, which specifies this formula for the force of mortality:

This has values set for the parameters of A=0.00022, B=0.0000027 and c=1.124.

The model has a select period of 2 years, with the force of mortality defined as:

We can then convert these equations to those for probability of survival. The ultimate rates are defined by:

The select rates are defined by:

### F# Code

The code below shows two simple functions to calculate the ultimate and select survival probabilities. A slightly more complex function is then shown to calculate lx, given an age and the select period.1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: |
/// tpx generated by Makehams formula let makeham_tpx A B c x t = exp(-A*t - B*c**x*(c**t - 1.0)/log(c)) /// tpx select generated for book let sel_tpx A B c x t = exp(0.9**(2.0-t)*((1.0-0.9**t)*A/log(0.9)+(c**t-0.9**t)*B*c**x/log(0.9/c))) /// lx dervied from formulas using parameters from book let rec lx_book x s = let A = 0.00022 let B = 0.0000027 let c = 1.124 // use curried functions let u_tpx = makeham_tpx A B c let s_tpx = sel_tpx A B c // ultimate is just to taks the value at 20 and apply tpx let l20 = 100000.0 if s>1 then l20 * (u_tpx 20.0 (x-20.0)) elif s=0 then //this needs to get the ultimate rate from 2 years older and divide by tpx (lx_book (x+2.0) 2) / (s_tpx x 2.0) else //this needs to get the select lx for one year younger and the apply 1 year of select tpx (lx_book (x-1.0) 0) * (s_tpx (x-1.0) 1.0) |

- it is recursive and so needs
to be added after the**rec****let** - there are three local values used for
.**A**and**B**, only available within the function**c** - we create "curried" functions to do the computations, by simply referencing the other function, but providing values for the first three parameters
- the last few lines show the use of recursion to re-use the function

### Using FCell

We could just run the code in a Console application or a Windows application. We could also run the code as script, using F# Interactive.We will instead us FCell to allow us to run the code and display the results in Excel. We first create a DLL containing the above functions. We can then open Excel and select this DLL as a UDF source for FCell. We can then use these functions in Excel:

This can then be used to create the grid of lx values as shown on page 66 of the book:

I would also motivate just about every person to save this web page for any favorite assistance to assist posted the appearance. family survival course review

ReplyDelete