macrosynergy.panel.make_relative_category#

Module implementing the make_relative_category() function, which calculates indicator values relative to a set of categories. Designed with sectoral equity returns in mind, this function can be extended to other data types with a similar structure. Unlike make_relative_value(), which computes values relative to a cross-sectional mean for a given category, make_relative_category() returns values relative to an average across categories.

make_relative_category(df, xcats=None, cids=None, start=None, end=None, blacklist=None, basket=None, complete_set=False, rel_meth='subtract', rel_xcats=None, postfix='RC')[source]#

For each cross section specified in the panel, relative values are calculated by either subtracting or dividing by the average across categories at each real_date.

Parameters:
  • df (DataFrame) – standardized JPMaQS DataFrame with the necessary columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’.

  • xcats (List[str]) – all extended categories for which relative values are to be calculated. The user must provide the set of categories to be used in the calculation.

  • cids (List[str]) – cross sections for which relative values are calculated.

  • start (str) – earliest date in ISO format. Default is None and earliest date for which the respective category is available is used.

  • end (str) – latest date in ISO format. Default is None and latest date for which the respective category is available is used.

  • blacklist (dict) – cross sections with date ranges that should be excluded from the output.

  • basket (List[str]) – categories to be used for the relative value benchmark. The default is every category in the DataFrame that is available over the time-period. However, the basket parameter can specify a subset of the available categories.

  • complete_set (bool) – boolean parameter that determines whether each cross-section is required to have the full set of extended categories in the basket for a relative value calculation to occur. If set to True, the cross-section will be excluded from the output if some desired categories are missing. Default is False. If False, the mean, for the relative value, will use the subset of categories available for that cross-section.

  • rel_meth (str) – method for calculating relative value. Default is ‘subtract’. Alternative is ‘divide’.

  • rel_xcats (List[str]) – extended category name of the relative values. Will displace the original category names: xcat + postfix. The order should reflect the order of the passed categories.

  • postfix (str) – acronym to be appended to ‘xcat’ string to give the name for relative value category. Only applies if rel_xcats is None. Default is ‘RC’ relative category

Returns:

standardized DataFrame with the relative values, with the columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’.

Return type:

DataFrame