macrosynergy.panel.panel_ewm_sum#

Fast exponential moving sum of quantamental panels on a business-day grid.

panel_ewm_sum(df, xcats=None, cids=None, halflife=5, start=None, end=None, blacklist=None, postfix=None)[source]#

Exponentially weighted moving sum of one or more category panels, computed on a dense business-day grid.

Unlike macrosynergy.management.utils.math.ewm_sum() (which returns ewm().mean() scaled by cumulative weights), this uses the pandas ewm(halflife).sum() definition directly. Each series is reindexed to a business-day grid, so halflife is measured in business days.

The input is expected to be dense on that grid: a standardised panel should have an observation on every business day between a series’ first and last release, apart from blacklisted ranges. A NaN (whether explicit in value or an implicit gap in the business-day grid) inside a series’ observed span therefore signals a data-quality problem and raises a ValueError rather than being silently filled. The leading and trailing regions outside each series’ first/last observation are excluded from the output.

Parameters:
  • df (DataFrame) – standardized QuantamentalDataFrame with columns ‘cid’, ‘xcat’, ‘real_date’, ‘value’.

  • xcats (List[str]) – categories to transform. Default is all categories in df.

  • cids (List[str]) – cross-sections to transform. Default is all cross-sections in df.

  • halflife (int | float | List) – EWM half-life in business days. A list produces one output category per value.

  • start (str) – date bounds (ISO). Default None uses the range in df.

  • end (str) – date bounds (ISO). Default None uses the range in df.

  • blacklist (dict) – cross-sections with date ranges to exclude. Blacklisted ranges are the one allowed source of gaps: they are excluded from the moving sum and absent from the output, and never trigger the interior-gap check.

  • postfix (str | List[str]) – output category suffix. Default None -> f"{h}DXMS" per half-life. A single string is allowed only for a scalar halflife; a list must match its length.

Returns:

standardized QuantamentalDataFrame with columns ‘real_date’, ‘cid’, ‘xcat’, ‘value’; new categories named {xcat}_{h}DXMS (or {xcat}_{postfix}).

Return type:

DataFrame

Raises:

ValueError – if a series contains a NaN (explicit or an implicit business-day gap) within its observed span, i.e. between its first and last observation and outside any blacklisted range.