macrosynergy.panel.extend_history#

extend_history(df, new_xcat, cids=None, hierarchy=[], backfill=False, start=None)[source]#

Extends the history of a dataframe by creating a new xcat by combining hierarchical categories. The method prioritizes superior categories for the new xcat and supplements with inferior ones where superior category data is unavailable.

Parameters:
  • df (pd.DataFrame) – The dataframe containing categories that are to be extended.

  • new_xcat (str) – The name of the new xcat.

  • cids (List[str], optional) – The cross sections to extend. If None, all cids available for any category in ‘hierarchy’ are extended.

  • hierarchy (List[str]) – list of categories from best to worst for representation of the concept. Inferior categories are only used to extend the history of the superior ones. The new category consists of the best representation category values and inferior category values that are available prior to any superior.

  • backfill (bool, optional) – If True, the new xcat is backfilled to the start date specified by the ‘start’ parameter.

  • start (str, optional) – The start date of the new xcat. If backfill is True, this values will be backfilled up to this date.

Returns:

standardized DataFrame for the new xcat with extended history, with the columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’.

Return type:

DataFrame