arbitragelab.time_series_approach.h_strategy

This module implements the strategy described in Bogomolov, T. (2013). Pairs trading based on statistical variability of the spread process. Quantitative Finance, 13(9): 1411–1430.

Module Contents

Classes

HConstruction

This class implements a statistical arbitrage strategy described in the following publication:

HSelection

This class implements a pairs selection strategy described in the following publication:

class HConstruction(series: pandas.Series, threshold: float, method: str = 'Kagi')

This class implements a statistical arbitrage strategy described in the following publication: Bogomolov, T. (2013). Pairs trading based on statistical variability of the spread process. Quantitative Finance, 13(9): 1411–1430.

h_inversion() int

Calculates H-inversion statistic, which counts the number of times the series changes its direction for the selected threshold.

Returns:

(int) The value of the H-inversion.

h_distances(p: int = 1) float

Calculates the sum of vertical distances between local maximums and minimums to the power p.

Parameters:

p – (int) The number of powers when calculating the distance.

Returns:

(float) The sum of vertical distances between local maximums and minimums.

h_volatility(p: int = 1) float

Calculates H-volatility statistic of order p, which is a measure of the variability of the series for the selected threshold.

Parameters:

p – (int) The order of H-volatility.

Returns:

(float) The value of the H-volatility.

extend_series(series: pandas.Series)

Extends the original series used as input during initialization and and rebuilds the H-construction on the extended series.

Parameters:

series – (pd.Series) A time series for extending the original series used as input during initialization. The dimensions should be n x 1.

get_signals(method: str = 'contrarian') pandas.Series

Gets the signals at each timestamp based on the method described in the paper.

Parameters:

method – (str) The method used to determine the signals. The options are [“contrarian”, “momentum”].

Returns:

(pd.Series) The time series contains the signals at each timestamp.

class HSelection(data: pandas.DataFrame, method: str = 'Kagi')

This class implements a pairs selection strategy described in the following publication: Bogomolov, T. (2013). Pairs trading based on statistical variability of the spread process. Quantitative Finance, 13(9): 1411–1430.

select(minimum_length: int = None)

Calculates H-inversion statistic for the spread series formed by each possible pair, and stores the results.

Parameters:

minimum_length – (int) Minimum length of consistent index required for the selected pair to do H-construction.

get_pairs(num: int, method: str = 'highest', allow_repeat: bool = False) list

Gets top N pairs with the highest/lowest H-inversion.

Parameters:
  • num – (int) The number of pairs that the user wants to get.

  • method – (str) The method used to select pairs. The options are [“highest”, “lowest”].

  • allow_repeat – (bool) Whether the user allows the same asset to appear repeatedly in different pairs.

Returns:

(list) The list contains the informations of the top N pairs. Each element in the list will contains three things: [H-inversion statistic, Threshold of the H-construction, Tuple contains the column names of two selected assets].