macrosynergy.panel.return_beta#

Functions for calculating the hedge ratios of a panel of returns with respect to a single return.

date_alignment(unhedged_return, benchmark_return)[source]#

Method used to align the two Series over the same timestamps: the sample data for the endogenous & exogenous variables must match throughout the re-estimation calculation.

Parameters:
  • unhedged_return (Series) – the return series of the asset that is being hedged.

  • benchmark_return (Series) – the return series of the asset being used to hedge against the main asset.

Return <pd.Timestamp, pd.Timestamp>:

the shared start and end date across the two series.

Return type:

Tuple[Timestamp, Timestamp]

hedge_calculator(unhedged_return, benchmark_return, rdates, cross_section, meth='ols', min_obs=24, max_obs=1000)[source]#

Calculate the hedge ratios for each cross-section in the panel being hedged. It is worth noting that the sample of data used for calculating the hedge ratio will increase according to the dates parameter: each date represents an additional number of timestamps where the numeracy of dates added to the sample is instructed by the “refreq” parameter.

Parameters:
  • unhedged_return (Series) – the return series of the asset that is being hedged.

  • benchmark_return (Series) – the return series of the asset being used to hedge against the main asset.

  • rdates (List[Timestamp]) – the dates controlling the frequency of re-estimation.

  • cross_section (str) – cross-section responsible for the “benchmark_return” series.

  • meth (str) – method to estimate hedge ratio. At present the only method is OLS regression (‘ols’).

  • min_obs (int) – a hedge ratio will only be computed if the number of days has surpassed the integer held by the parameter.

  • max_obs (int) – the maximum number of latest observations allowed in order to estimate a hedge ratio. The default value is 1000.

Return <pd.DataFrame>:

returns a dataframe of the hedge ratios for the respective cross-section.

Return type:

DataFrame

adjusted_returns(benchmark_return, df_hedge, dfw)[source]#

Method used to compute the hedge ratio returns on the hedging asset which will subsequently be subtracted from the returns of the position contracts to calculate the adjusted returns (adjusted for the hedged position) across all cross-sections in the panel. For instance, if using US Equity to hedge Australia FX: AUD_FXXR_NSA_H = AUD_FXXR_NSA - HR_AUD * USD_EQXR_NSA.

Parameters:
  • benchmark_return (Series) – the return series of the asset being used to hedge against the main asset.

  • df_hedge (DataFrame) – standardised dataframe with the hedge ratios.

  • dfw (DataFrame) – pivoted dataframe of the relevant returns.

Return <pd.DataFrame>:

standardised dataframe of adjusted returns.

Return type:

DataFrame

return_beta(df, xcat=None, cids=None, benchmark_return=None, start=None, end=None, blacklist=None, meth='ols', oos=True, refreq='M', min_obs=24, max_obs=1000, hedged_returns=False, ratio_name='_HR', hr_name='H')[source]#

Estimate sensitivities (betas) of return category with respect to single return.

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

  • xcat (str) – return category based on the type of positions that are to be hedged. N.B.: Each cross-section of this category uses the same hedge asset/basket.

  • cids (List[str]) – cross-sections of the returns for which hedge ratios are to be calculated. Default is all that are available in the dataframe.

  • benchmark_return (str) – ticker of return of the hedge asset or basket. This is a single series, e.g. U.S. equity index returns (“USD_EQXR_NSA”).

  • start (str) – earliest date in ISO format. Default is None: earliest date in df is used.

  • end (str) – latest date in ISO format. Default is None: latest date in df is used.

  • blacklist (dict) – cross-sections with date ranges that should be excluded from the sample of data used for estimating hedge ratios. The estimated ratios during blacklist periods will be set equal to the last valid estimate.

  • oos (bool) – if True (default) hedge ratios are calculated out-of-sample, i.e. for the period following the estimation period at the given re-estimation frequency.

  • refreq (str) – re-estimation frequency. This is period after which hedge ratios are re-estimated. The re-estimation is conducted at the end of the period and used as hedge ratio for all days of the following period. Re-estimation can have weekly, monthly, and quarterly frequency with the notations ‘W’, ‘M’, and ‘Q’ respectively. The default frequency is monthly.

  • min_obs (int) – the minimum number of observations required in order to estimate a hedge ratio. The default value is 24 days. The permissible minimum is 10.

  • max_obs (int) – the maximum number of latest observations allowed in order to estimate a hedge ratio. The default value is 1000.

  • meth (str) – method used to estimate hedge ratio. At present the only method is OLS regression (‘ols’).

  • hedged_returns (bool) – If True the function appends the hedged returns to the dataframe of hedge ratios. Default is False.

  • ratio_name (str) – hedge ratio label that will be appended to the category name. The default is “_HR”. For instance, ‘xcat’ + “_HR”.

  • hr_name (str) – label used to distinguish the hedged returns in the DataFrame. The label is appended to the category being hedged. The default is “H”.

Return <QuantamentalDataFrame>:

DataFrame with hedge ratio estimates that update at the chosen re-estimation frequency. Additionally, the dataframe can include the hedged returns if the parameter benchmark_return has been set to True.

N.B.: A return beta is the estimated sensitivity of the main return with respect to the asset used for hedging. The ratio is recorded for the period after the estimation sample up until the next re-estimation date.

Return type:

QuantamentalDataFrame

beta_display(df_hedge, subplots=False, hr_name='H')[source]#

Method used to visualise the hedging ratios across the panel: assumes a single category is used to hedge the primary asset.

Parameters:
  • df_hedge (DataFrame) – DataFrame with hedge ratios.

  • subplots (bool) – matplotlib parameter to determine if each hedging series is displayed on separate subplots.

  • hr_name (str) – label used to distinguish the hedged returns in the DataFrame. Comparable to return_beta() method, the default is “H”.