dynamicGroupCumsum#

swordfish.function.dynamicGroupCumsum()#

The attribute and category of an event are fixed in most cases. In some scenarios, the category of an event, however, will change dynamically. For example, when processing real-time tick data, users may judge whether an order (attribute) is a large or a small one (category) based on the cumulative volume to analyze capital flow. As real-time data continues to flow in, trading volume keeps increasing, and thus a small order may change to a large one.

Function dynamicGroupCumsum is used in such scenarios to obtain the cumulative sum of an indicator for events of different categories.

Details are as follows:

  • If membership = prevMembership, count remains unchanged.

  • If membership ≠ prevMembership, the count of corresponding group of membership increases by cumValue, and the count of corresponding group of prevMembership decreases by preCumValue.

  • If prevMembership is a null value (the first record of each group), the count of corresponding group of membership increases by cumValue.

Parameters:
  • cumValue (Constant) – A numeric vector that records the cumulative value of the event at the current timestamp.

  • prevCumValue (Constant) – A numeric vector, of which elements can be null values (the first record of each group), indicating the cumulative value of the event at the previous timestamp of cumValue.

  • membership (Constant) – A vector of INT type, of which elements must be integers in the interval [0, groupCount), indicating tags for records at the current timestamp.

  • prevMembership (Constant) – A vector of INT type, of which elements can be null value (the first record of each group), indicating tags for records at the previous timestamp of membership.

  • groupCount (Constant) – An integer in the interval [2, 8], indicating the number of tags.

Returns:

A tuple of length groupCount. Each element is a vector of the same length as membership, which sequentially records the cumulative sum of an indicator (cumValue) for each tag.

Note

The index of the tuple matches the tags, which means that the count of tag 0 is output at index 0 of the tuple.

Return type:

Constant