The Looping Feature in Calculation Procedures (Managed Package)

For the managed package runtime, looping calculations take a starting point, an endpoint, and an interval. At run time, the calculation procedure runs in a loop from start to end per interval. Each run uses the same input variables, plus an index variable that you can use in the calculation.

Managed Package app icon This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see Omnistudio Help.

Calculation procedures support looping calculations starting in the Vlocity Insurance Winter '18 Major Release.

For example, you can create a looping calculation procedure for a life insurance policy. The looping calculation procedure calculates the policy value for each year from the current age of the policy holder to the policy holder's age at the end of the policy term. The calculation takes a current age (35 years), end age (65 years), and an interval of 1 to calculate on an annual basis. The calculation runs, looping 30 times. All input variables remaining constant, but the index starts at 35 and increments by one through 65. The output shows the user the value of the policy each year from the start date to the end of the term.

Index Variable

The index variable becomes available when you set Enable Looping on the Calculation Procedure Version. To add it to calculation steps, type index in a calculation step.

When a calculation procedure has looping set up and enabled, it increments index based on the looping Interval variable (whatever you've named it), from looping start until looping end. You can then use index to change the calculation on each looping pass. For example, you can add it to an Age to increment the value of Age for each loop.

Note
Note

The system-provided index variable does not show up in the list of variables. You don't need to create it.

In this example, calculation step 3 is set up to calculate the year of the policy, looping per interval (one year). Step 4 calculates the age of the policy holder, looping per interval (one), starting with the policy holder's age at the start of the policy.

The first three steps perform calculations. The first step sets AGEON(Birthdate,EffectiveDate) to startAge. The second step sets startAge + Term to endAge. The third step sets startAge + index to currentAge. The fourth step calls the currentMortality matrix, with input variables of currentAge and Gender and an output variable of currentDeathProbability.

PREVIOUS Function

You can use the PREVIOUS function to get the previous looped iteration's result. The calculation step can use this function to access a previous iteration's variable results and calculate it with other variables.

PREVIOUS accepts the following:

  • Variable name

    Usually set up as a constant of type Text

  • previousIterator

    The index of the previous iteration result set from which to get the value for the variable

  • ITERATION

    System-provided variable for accumulated results

In this example, the PREVIOUS function uses previous iterations to calculate the cash value of the policy per iteration (one).

There are two calculation steps. The first sets PREVIOUS(cashValueName,1,ITERATION) * dividendRate to intervalDividend, and the second sets PREVIOUS(cashValueName,1,ITERATION) + PREVIOUS(intervalDividendName,1,ITERATION) + PREVIOUS(cashInvestmentName,1,ITERATION) to cashValue.

Example 1: Calculation Procedure Simulation

For this example, the term = 2 (years), the start = 0 (year zero of the term), and the increment = 1 (year).

Simulation input variables: Birthdate is 12/01/1970, effectiveDate is 12/07/2017, Term is 2, Gender is Female, FaceAmount is 3000, Premium is 3000, Start is 0, and Interval is 1.

The output JSON for this simulation is:

{
   "output": [
      {
         "calculationResults": [
            {
               "index": 0,
               "intervalNumber": 0,
               "deathBenefit": 3000,
               "deathBenefitGuaranty": 3000,
               "cashValue": 0,
               "intervalDividend": 0,
               "cashInvestment": 2995.83,
               "cashInsurance": 4.17,
               "deathProbability": 0.00139,
               "currentMortality__currentDeathProbability": 0.002402,
               "currentAge": 47,
               "intervalDate": "2017-12-07",
               "endAge": 52,
               "ID": "input"
            },
            {
               "index": 1,
               "intervalNumber": 1,
               "deathBenefit": 5995.83,
               "deathBenefitGuaranty": 3000,
               "cashValue": 2995.83,
               "intervalDividend": 0,
               "cashInvestment": 2996.52,
               "cashInsurance": 3.48,
               "deathProbability": 0.00116,
               "currentMortality__currentDeathProbability": 0.002639,
               "currentAge": 48,
               "intervalDate": "2018-12-07",
               "endAge": 52,
               "ID": "input"
            },
            {
               "index": 2,
               "intervalNumber": 2,
               "deathBenefit": 8992.35,
               "deathBenefitGuaranty": 3000,
               "cashValue": 5992.35,
               "intervalDividend": 44.94,
               "cashInvestment": 2997.33,
               "cashInsurance": 2.67,
               "deathProbability": 0.00089,
               "currentMortality__currentDeathProbability": 0.002903,
               "currentAge": 49,
               "intervalDate": "2019-12-07",
               "endAge": 52,
               "ID": "input"
            }
         ],
         "aggregationResults": {}
      }
   ]
}

Example 2: Omniscript

In this example, the looping calculation procedure is added to an Omniscript as a Calculation Action.

OmniScript Calculation Action properties: Element Name is calcIllustration, Label is Calculate, Remote Class is vlocityins2.PricingMatrixCalculationService, Remote Method is calculate, Configuration Name is wholeLife, Include Inputs is checked, Pre-Transform DataRaptor Interface is WholeLife-Illustration-Pre, and Post-Transform DataRaptor Interface is WholeLife-Illustration-Post.

The looping calculation creates a list of results. You can display these results in a format of your choice. In the example below, a custom template displays the results in a table that shows the values of the policy year over year (incremented by 1).

The OmniScript displays the results in a Table of Values. The Year column has values blank, then 1 through 13. The Age column has values 48 through 61. The Guaranty Death Benefit column has the value 500000 in every cell. Protection column values start at 5120 and end at 2855. Saving column values start at -4453 and end at -2188. The first cell in the Cash Value column is blank, then the values start at -4453 and end -49716.73. Total Death Benefit values start at 500000 and end 450283.27.