Example: Writing an Absolute Difference Summation

 

This is an example of how to enter an advanced formula using the Formula Entry controls. For an example of entering a simple formula, see Example: Writing a Moving Average Function.

 

Suppose you want to add together the absolute values of the differences of the ten most recent values of a series to the current value. You could do this by performing a summation of the absolute value of a subtraction of the current value of an input field from the input field. In formula notation, it would appear as follows:

 

Sum ( Abs ( Sub ( Value , Current: Ident ( Value ) ) ) , 10 )

 

To enter this as a formula, you would use the following steps:

1.    Use the Function Definition sub-page to select the Summation function.

2.    For the "Data" parameter of the Summation, select the Absolute Value function.

3.    For the "Value" parameter of the Absolute Value, select the Subtract function.

4.    For the "Value 1" parameter of the Subtraction, create an input field called "Value".

5.    For the "Value 2" parameter of the Subtraction, we also want to use the same input field. For now, select the "Value" input field.

6.    For the "Period" parameter of the Summation, we will use the numeric constant 10. To make this function more customizable, this could be made an input field instead of a numeric constant.

 

The formula should appear as follows:

 

 Sum ( Abs ( Sub ( Value , Value ) ) , 10 )

 

This formula would add together the absolute values of the differences of the ten most recent values of a series to themselves. Unfortunately, subtracting a value from itself results in zero, so the summation and the entire formula would always return zero.

 

To indicate that the second value in the Subtraction should be the current value, we will use the Special Array Processing available from the Special sub-page. Since this processing operates on the value of a function, we will use the Identity function to return the value of the input field unmodified.

1.    Select the second "Value" in the Formula View. This should be the "Value 2" input to the Subtract function.

2.    From the Special sub-page, use the Add Level button to add an Identity function around the selection. The newly added Identity function will become the new selection.

3.    Select the Special Array Processing: Use Current Value checkbox to indicate that the current value of this function should be used in the summation.

 

The formula should now appear as follows:

 

Sum ( Abs ( Sub ( Value , Current: Ident ( Value ) ) ) , 10 )

 

This formula would add together the absolute values of the differences of the ten most recent values of a series. The difference between this formula and the previous formula is that the current value of the series is subtracted from each value.

How Did I Get Here?

This is an example of Formula Entry.