macrosynergy.panel.make_relative_value#

Implementation of make_relative_value() function as a module. The function is used to calculate values for indicators relative to a basket of cross sections.

make_relative_value(df, xcats, cids=None, start=None, end=None, blacklist=None, basket=None, complete_cross=False, rel_meth='subtract', rel_xcats=None, rel_reference='mean', exclude_own_cid=False, postfix='R')[source]#

For each category specified in the panel, relative values are calculated by either subtracting or dividing by the cross-sectional mean 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.

  • cids (List[str]) – cross sections for which relative values are calculated. Default is all cross section available for the respective category.

  • 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]) – cross sections to be used for the relative value benchmark. The default is every cross section in the cids argument that is available in the DataFrame over the respective time-period. However, the basket can be reduced to a valid subset of the available cross sections.

  • complete_cross (bool) – boolean parameter that determines whether each category is required to have the full set of cross sections held by the basket parameter for a relative value calculation to occur. If set to True, the category will be excluded from the output if cross sections are missing. Default is False. If False, the mean, for the relative value, will use the subset that is available for that category. For instance, if basket = [‘AUD’, ‘CAD’, ‘GBP’, ‘NZD’] but available cids = [‘GBP’, ‘NZD’], the basket will be implicitly updated to basket = [‘GBP’, ‘NZD’] for that respective category.

  • 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.

  • rel_reference (str) – reference point for the relative value calculation. Default is ‘mean’. Alternative is ‘median’.

  • exclude_own_cid (bool) – if True, the cross section itself is excluded from the relative value calculation. Only applicable if rel_reference is mean. Default is False.

  • 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 ‘R’

Returns:

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

Return type:

DataFrame