macrosynergy.panel.linear_composite#

Implementation of linear_composite() function as a module.

linear_composite_cid_agg(df, xcat, cids, weights, signs, normalize_weights=True, complete_cids=True, new_cid='GLB')[source]#

Linear composite of various cids for a given xcat across all periods.

linear_composite_xcat_agg(df, xcats, weights, signs, normalize_weights=True, complete_xcats=True, new_xcat='NEW')[source]#

Linear composite of various xcats across all cids and periods

linear_composite(df, xcats, cids=None, weights=None, normalize_weights=True, signs=None, start=None, end=None, blacklist=None, complete_xcats=False, complete_cids=False, new_xcat='NEW', new_cid='GLB')[source]#

Weighted linear combinations of cross sections or categories

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

  • xcats (Union[str, List[str]]) – One or more categories to be combined. If a single category is given the linear combination is calculated across sections. This results in a single series to which a new cross-sectional identifier is assigned. If more than one category string is given the output will be a new category, i.e. a panel that is a linear combination of the categories specified.

  • cids (Optional[List[str]]) – cross-sections for which the linear combinations are calculated. Default is all cross-section available.

  • weights (Union[List[float], str, None]) – This specifies how categories or cross sections are combined. There are three principal options. The first (default) is None, in which case equal weights are given to all categories or cross sections that are available. The second case is a set of fixed coefficients, in which case these very coefficients are applied to all available categories of cross sections. Per default the coefficients are normalized so that they add up to one for each period. This can be changed with the argument normalize_weights. The third case is the assignment of a weighting category. This only applies to combinations of cross sections. In this care the weighting category is multiplied for each period with the corresponding value of main category of the same cross section. Per default the weight category values are normalized so that they add up to one for each period. This can be changed with the argument normalize_weights.

  • normalize_weights (bool) – If True (default) the weights are normalized to sum to 1. If False the weights are used as specified.

  • signs (Optional[List[float]]) – An array of consisting of +1s or -1s, of the same length as the number of categories in xcats to indicate whether the respective category should be added or subtracted from the linear combination. Not relevant when aggregating over cross-sections, i.e. when a single category is given in xcats. Default is None and all signs are set to +1.

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

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

  • complete_xcats (bool) – If True (default) combinations are only calculated for observation dates on which all xcats are available. If False a combination of the available categories is used. Not relevant when aggregating over cross-sections, i.e. when a single category is given in xcats.

  • complete_cids (bool) – If True (default) combinations are only calculated for observation dates on which all cids are available. If False a combination of the available cross-sections is used. Not relevant when aggregating over categories, i.e. when multiple categories are given in xcats.

  • new_xcat – Name of new composite xcat when aggregating over xcats for a given cid. Default is “NEW”.

  • new_cid – Name of new composite cid when aggregating over cids for a given xcat. Default is “GLB”.

Return <pd.DataFrame>:

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