Saturday, May 28, 2022

Some Thoughts on Prophet (Part 2)

One of my favorite functionalities in Prophet is "parameterized extended formula". Although this technical term sounds a bit complex, the concept is in fact pretty straight forward - we can just relate to something we learned in the secondary school, i.e. "f(x)" (functions).

How parameterized extended formulas work is similar to self-defined function in Excel VBA. Say we have a function with multiple elements, e.g. f(x, y, z). When we input x = 2, y = 3 and z = 4 to this function, we may get a value of 10 directly. The same function can be used for different combinations of x, y and z - i.e. we can REUSE the function and make our calculation models more efficient.

We can use parameterized extended formulas for various areas, such as converting annual decrement rates to monthly rates. Instead of replicating similar formulas for death, TPD and CI separately, we can create a parameterized extended formula that can be used for death, TPD and CI at the same time:

  1. Create an extended formula that contain (say) 3 elements, say I call it as EXT_FORMULA.
  2. Create different extended formula for death, TPD and CI. Just one line code, #EXT_FORMULA(x, y, z) (it's hash-E-X-T-underscore-F-O-R-M-U-L-A). Say the extended formula for death is DTH_INPUT.
  3. To get the value from EXT_FORMULA, we need to specify the variable that carries values of elements, such as DTH_INPUT.QX (QX is a public variable under EXT_FORMULA).

Another reason I love using parameterized extended formula is it allows multiple outputs from the same extended formulas. For example, in case we have two separate public variables for male and female, we can define two public variables within the same parameterized extended formula, i.e. we can directly get the values from the variable by specifying (say) DTH_INPUT.QX_M and DTH_INPUT.QX_F.

You can also have numeric and text public variables at the same time. Both numeric and text public variables may appear as array variables if needed.


Further reading:

No comments:

Post a Comment

Get Inspiration for New Problems

In my last post and debut podcast, I talked about why strong foundations matter for coming up with smart, workable solutions in business. Bu...