Skip to content

Add gmv aggregate#3180

Merged
texodus merged 2 commits into
masterfrom
gmv-aggregate
May 26, 2026
Merged

Add gmv aggregate#3180
texodus merged 2 commits into
masterfrom
gmv-aggregate

Conversation

@texodus
Copy link
Copy Markdown
Member

@texodus texodus commented May 25, 2026

This PR adds a new aggregate gmv ("gross market value"), which for any node in a Perspective group_by / split_by tree:

  • Leaf (full row depth): plain signed sum.
  • Parent: Σ over immediate row children of |sum(child_subtree)|.

The parent uses each child's raw signed sum, not the child's already-rolled-up gmv value. This makes parent elements ≠ Σ|child_gmv|.

This specialized aggregation will be noticeably slower than regular sum due to recursively recalculating gstate for each depth, so use it wisely.

Signed-off-by: Andrew Stein <steinlink@gmail.com>
@texodus texodus added the enhancement Feature requests or improvements label May 25, 2026
Signed-off-by: Andrew Stein <steinlink@gmail.com>
@texodus texodus merged commit 5065cde into master May 26, 2026
30 of 44 checks passed
@texodus texodus deleted the gmv-aggregate branch May 26, 2026 00:54
@texodus texodus restored the gmv-aggregate branch May 26, 2026 02:14
@texodus texodus deleted the gmv-aggregate branch May 26, 2026 02:15
@nmichaud
Copy link
Copy Markdown
Contributor

GMV = sum(abs(MV)). It's never negative. Rolling it up can be tricky depending on how you want to treat positions on the same names across multiple subgroups (ie net them or treat as separate).

@texodus
Copy link
Copy Markdown
Member Author

texodus commented May 27, 2026

@nmichaud This implementation nets by the last group_by column, for all ancestor groups/splits, which is why it is slow (it is re-grouping for every ancestor level). E.g., the net column in the test case is "symbol".

The last column's aggregate is "sum" instead of "sum abs", because this implementation is from a spec. You can create an expressions column using the abs() function to calculate this:

{
    "expressions": {
        "abs(MV)": "abs(\"MV\")"
    },
    "aggregates": {
        "abs(MV)": "gmv"
    }
}

... or y'all can change the spec (@timkpaine).

@nmichaud
Copy link
Copy Markdown
Contributor

Ok that makes sense. I wouldn't call it GMV, at least without calling out that you need to use it on an abs(x) column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature requests or improvements

Development

Successfully merging this pull request may close these issues.

2 participants