Discrete blocks

Discrete blocks

Value Bucket block

The Value Bucket block can be used to store multiple pairs of numeric values which can be retrieved as needed. Each pair consists of a KEY which the user can use to locate a specific pair, and a VALUE which is the actual numeric value of interest to the user. The Value Bucket block operates in the following manner:

  1. A discrete event message received through the store port triggers the Value Bucket block.

  2. When triggered, the Value Bucket block adds to its internal hash table (see: Internal data collection for more information about hash tables) a new entry consisting of a KEY and a VALUE.

  3. After the addition of the new entry, the Value Bucket block will look at the input message, and search through its internal hash table to locate the entry whose key value matches the input lookup port.

  4. Once it finds the correct entry, it outputs the entry's value through the val output port.

  5. Afterwards, it passes on the original message unchanged through its out port.

  6. Optionally, you can also set up the Value Bucket block to empty its internal hash table and reset its value to a NaN (Not A Number) when a discrete event message triggers the reset port.

Example Count the traded quantity above the open price for a contract

Formulas

The Value Bucket block uses the Fields Formula Editor to specify the values for the storeKey and storeVal ports.

Internal data collection

The Value Bucket block's internal hash table can be conceptualized as a simple table with two columns: KEY and VALUE. In the following example, suppose that the Value Bucket block is triggered by a discrete event message every time a trade occurs in a given instrument. When triggered, the Value Bucket will extract and use the Trade Price as the KEY; and the Trade Quantity as the VALUE of each new entry. A user might create such table to maintain and use the running volume at different prices during a trading session.

  1. Suppose that the Value Bucket block already has three entries in its internal hash table, as shown in the following illustration.

  2. Suppose that a new trade occurs at Price 1290 25, for a Quantity of 3. A discrete event message containing this information will trigger the Value Bucket block. When triggered, the block will extract and add a new entry to its internal hash table using the Trade price and the Trade Quantity.

  3. Suppose that the user specifies the Hole input as 1289 50. The block will search through its internal hash table to locate the entry whose KEY value matches the input Hole value. Afterwards, it will output the VALUE of the corresponding entry as 7.

Block properties

To customize the block, update the Block Properties.

Property Description
Name Name to display beneath the block on the ADL canvas
Mode

Occasionally, two entries in the hash table will end up with the same KEYs. In this case, the Value Bucket will resolve the conflict through one of the three methods chosen by the user:

  • Sum: Sum the values of the two conflicting entries and consolidate them into a single entry
  • Average: Take the average of the values of the two conflicting entries and consolidate them into a single entry
  • Last: Retain the recent entry and discard the older one
Formulas

Equations used to calculate the value of the entry's key and value pair

The edit link opens the Fields Formula Editor.