arbitragelab.cointegration_approach.multi_coint
This module generates a cointegration vector for mean-reversion trading of three or more cointegrated assets.
Module Contents
Classes
| This class optimizes bounds for mean-reversion trading of a spread consisting of three and more assets. | 
- class MultivariateCointegration
- This class optimizes bounds for mean-reversion trading of a spread consisting of three and more assets. - The implementation is based on the method described by Galenko, A., Popova, E. and Popova, I. in “Trading in the presence of cointegration” - property asset_df: pandas.DataFrame
- Property that gives read-only access to the in-sample asset price dataframe. - Returns:
- (pd.DataFrame) Dataframe of asset prices. 
 
 - set_train_dataset(price_df: pandas.DataFrame)
- Provide price series for model to calculate the cointegration coefficient and beta. - Parameters:
- price_df – (pd.DataFrame) Price series dataframe which contains both series. 
 
 - fillna_inplace(nan_method: str = 'ffill', order: int = 3)
- Replace the class attribute dataframes with imputed training dataframe. - Parameters:
- nan_method – (str) Missing value imputation method. If “ffill” then use front-fill; if “spline” then use cubic spline. 
- order – (int) Polynomial order for spline function. 
 
 
 - static calc_log_price(price_df: pandas.DataFrame) pandas.DataFrame
- Calculate the log price of each asset for cointegration coefficient calculation. - Parameters:
- price_df – (pd.DataFrame) Dataframe that contains the raw asset price. 
- Returns:
- (pd.DataFrame) Log prices of the assets. 
 
 - static calc_price_diff(price_df: pandas.DataFrame) pandas.DataFrame
- Calculate the price difference of day t and day t-1 of each asset. - Parameters:
- price_df – (pd.DataFrame) Dataframe that contains the raw asset price. 
- Returns:
- (pd.DataFrame) Log prices of the assets. 
 
 - fit(log_price: pandas.DataFrame, sig_level: str = '95%', suppress_warnings: bool = False) numpy.array
- Use Johansen test to retrieve the cointegration vector. - Parameters:
- log_price – (pd.DataFrame) Log price dataframe used to derive cointegration vector. 
- sig_level – (str) Cointegration test significance level. Possible options are “90%”, “95%”, and “99%”. 
- suppress_warnings – (bool) Boolean flag to suppress the cointegration warning message. 
 
- Returns:
- (np.array) The cointegration vector, b. 
 
 - get_coint_vec() Tuple[pandas.DataFrame, Ellipsis]
- Generate contegration vector to generate trading signals. - Returns:
- (np.array) The cointegration vector, b. 
 
 - static summary(returns_df: pandas.DataFrame) pandas.DataFrame
- Statistics of the trading strategy returns. - The statistics include: mean, standard deviation, skewness, kurtosis, Sharpe ratio, Sortino ratio, final cumulative returns, percentage of up days and down days, max returns, and min returns. - Parameters:
- returns_df – (pd.DataFrame) Daily percentage returns dataframe. 
- Returns:
- (pd.DataFrame) Trading strategy returns statistics dataframe. 
 
 - static plot_returns(returns: pandas.DataFrame, figw: float = 15.0, figh: float = 15.0, title: str = 'Returns', start_date: pandas.Timestamp | None = None, end_date: pandas.Timestamp | None = None) matplotlib.pyplot.Figure
- Plot the equity curve only. - Parameters:
- returns – (pd.DataFrame) Daily returns dataframe. 
- figw – (float) Figure width. 
- figh – (float) Figure height. 
- title – (str) Figure title. 
- start_date – (pd.Timestamp) Start point of the plot. 
- end_date – (pd.Timestamp) End point of the plot. 
 
- Returns:
- (plt.Figure) A single equity curve plot.