arbitragelab.cointegration_approach.engle_granger
This module implements Engle-Granger cointegration approach.
Module Contents
Classes
The class implements the construction of a mean-reverting portfolio using the two-step Engle-Granger method. |
- class EngleGrangerPortfolio
Bases:
arbitragelab.cointegration_approach.base.CointegratedPortfolio
The class implements the construction of a mean-reverting portfolio using the two-step Engle-Granger method. It also tests model residuals for unit-root (presence of cointegration).
- __slots__ = ()
- perform_eg_test(residuals: pandas.Series)
Perform Engle-Granger test on model residuals and generate test statistics and p values.
- Parameters:
residuals – (pd.Series) OLS residuals.
- fit(price_data: pandas.DataFrame, add_constant: bool = False)
Finds hedge-ratios using a two-step Engle-Granger method to form a mean-reverting portfolio. By default, the first column of price data is used as a dependent variable in OLS estimation.
This method was originally described in “Co-integration and Error Correction: Representation, Estimation, and Testing,” Econometrica, Econometric Society, vol. 55(2), pages 251-276, March 1987 by Engle, Robert F and Granger, Clive W J.
- Parameters:
price_data – (pd.DataFrame) Price data with columns containing asset prices.
add_constant – (bool) A flag to add a constant term in linear regression.
- static get_ols_hedge_ratio(price_data: pandas.DataFrame, dependent_variable: str, add_constant: bool = False) Tuple[dict, pandas.DataFrame, pandas.Series, pandas.Series]
Get OLS hedge ratio: y = beta*X.
- Parameters:
price_data – (pd.DataFrame) Data Frame with security prices.
dependent_variable – (str) Column name which represents the dependent variable (y).
add_constant – (bool) Boolean flag to add constant in regression setting.
- Returns:
(Tuple) Hedge ratios, X, and y and OLS fit residuals.
- construct_mean_reverting_portfolio(price_data: pandas.DataFrame, cointegration_vector: pandas.Series = None) pandas.Series
When cointegration vector was formed, this function is used to multiply asset prices by cointegration vector to form mean-reverting portfolio which is analyzed for possible trade signals.
- Parameters:
price_data – (pd.DataFrame) Price data with columns containing asset prices.
cointegration_vector – (pd.Series) Cointegration vector used to form a mean-reverting portfolio. If None, a cointegration vector with maximum eigenvalue from fit() method is used.
- Returns:
(pd.Series) Cointegrated portfolio dollar value.
- get_scaled_cointegration_vector(cointegration_vector: pandas.Series = None) pandas.Series
This function returns the scaled values of the cointegration vector in terms of how many units of other cointegrated assets should be bought if we buy one unit of one asset.
- Parameters:
cointegration_vector – (pd.Series) Cointegration vector used to form a mean-reverting portfolio. If None, a cointegration vector with maximum eigenvalue from fit() method is used.
- Returns:
(pd.Series) The scaled cointegration vector values.