Best practices of velocity variables and custom variables in transaction scenarios

Updated at:

In transaction scenarios, you must specify a risk control threshold for the recent transaction amount within the same account. If a transaction fails and the transaction amount is accumulated, the recent transaction amount becomes large, and false positives may occur. To address the issue, divide the recent transaction amount into two parts: the amount of recent successful transactions and the amount of the current transaction. The division can be implemented in the decision engine by using a velocity variable and a custom variable.

1. Create events

  1. In the left-side navigation pane, choose Decision Engine > Event Management > Custom Event Management.

  2. Create the following events:

    1. TransactionEvent: A TransactionEvent event is the primary event and is used to check whether the recent transaction amount exceeds the risk control threshold. The event reads the amount of recent successful transactions.

    2. CumulativeEvent: A CumulativeEvent event is used only for cumulative calculation of a velocity variable. The event writes the amount of recent successful transactions.

    The accountId and trnxAmt fields are used by the two events. The accountId field specifies the ID of the account, and the trnxAmt field specifies the transaction amount.

2. Create a velocity variable

  1. On the Variable Center page, choose Variable Management > Velocity Variable.

  2. Create a velocity variable named AmountIn90Days for CumulativeEvent and enable the velocity variable. AmountIn90Days indicates the amount of successful transactions in the last 90 days within the same account.

    1. Write Event: Select CumulativeEvent.

    2. Variable Type: Select Summation.

    3. Variable Name: Enter AmountIn90Days.

    4. Time Window: Specify 90 days.

    5. Main object: Select accountId.

    6. Cumulative object: Select trnxAmt.

3. Create a custom variable

  1. On the Variable Center page, choose Variable Management > Derived Variable.

  2. Create a custom variable named CurrentCumulativeAmount. CurrentCumulativeAmount indicates the recent transaction amount.

    • Associated Event: Select TransactionEvent.

    • Variable Name: Enter CurrentCumulativeAmount.

    • Variable Type: Select Float.

    • Outlier: Specify a custom value. You can also retain the default value -1.

    • Expression: Specify @trnxAmt + @AmountIn90Days.

  3. Click Test to complete the test and then click Confirm.

4. Create a policy

  1. In the left-side navigation pane, choose Policy Center > Policy Management.

  2. Create a policy for TransactionEvent.

  3. For Conditional Content, specify Derived Variable/CurrentCumulativeAmount, Greater than or equal to, and 1000. For Variable, specify Constant and highRisk. For Output Variable, specify curTrnxAmt and CurrentCumulativeAmount. If the value of the CurrentCumulativeAmount variable is greater than or equal to 1000, the highRisk tag and the value of the CurrentCumulativeAmount variable are returned.

5. Call the two events

  1. The two events are called in the following scenarios:

  2. 1. TransactionEvent: This event is called every time a transaction occurs. You must pass values to the accountID and trnxAmt fields. Then, the system reads the value of the velocity variable and checks whether the value of the CurrentCumulativeAmount variable exceeds the risk control threshold in real time.

  3. 2. CumulativeEvent: This event is called only after the system confirms that the transaction is successful. You must pass values to the accountID and trnxAmt fields. Then, the system writes the value of the trnxAmt field into the velocity variable and performs the asynchronous cumulative calculation.

6. Verify the policy

Simulate the call scenarios.

  1. Simulate a successful transaction to call CumulativeEvent. Example:

    {"eventCode":"de_example001","accountId":"test001","trnxAmt":"1000"}

    In this case, the value of the AmountIn90Days variable is 1000.

  2. Simulate a transaction to call TransactionEvent. Example:

    {"eventCode":"de_example002","accountId":"test001","trnxAmt":"90"}

    In this case, the value of the CurrentCumulativeAmount variable is 1090, which is greater than 1000. The value is calculated by using the following formula: 1000 + 90.

    Check whether the policy is hit and the results meet your expectations.

    {
        "Message": "OK",
        "RequestId": "99BF******C20C",
        "Data": {
            "extend": "{\"curTrnxAmt\":1090.0}",
            "tags": "highRisk"
        },
        "Code": 200
    }