arbitragelab.trading.multi_coint
Module for signal generation for Multivariate Cointegration Trading strategy.
Module Contents
Classes
This class implements trading strategy from the Multivariate Cointegration method from the paper |
- class MultivariateCointegrationTradingRule(coint_vec: numpy.array, nlags: int = 30, dollar_invest: float = 10000000.0)
This class implements trading strategy from the Multivariate Cointegration method from the paper by Galenko, A., Popova, E. and Popova, I. in “Trading in the presence of cointegration”
The strategy generates a signal - number of shares to go long and short per each asset, based on the cointegration vector from the MultivariateCointegration class.
It’s advised to re-estimate the cointegration vector (i.e. re-run the MultivariateCointegration) each month or more frequently, if the data has higher than daily granularity.
The strategy rebalances the portfolio of assets with each new entry, meaning that the position opened at time t should be closed at time t+1, and the new trade should be opened.
This strategy allows only one open trade at a time.
- update_price_values(latest_price_values: pandas.Series)
Adds latest price values of assets to self.price_series.
- Parameters:
latest_price_values – (pd.Series) Latest price values.
- static calc_log_price(price_df: pandas.DataFrame) pandas.DataFrame
Calculate the log price of each asset for position size calculation.
- Parameters:
price_df – (pd.DataFrame) Dataframe that contains the raw asset price.
- Returns:
(pd.DataFrame) Log prices of the assets.
- get_signal() tuple
Function which calculates the number of shares to trade in the current timestamp based on the price changes, dollar investment, and cointegration vector from the MultivariateCointegration class.
- Returns:
(np.array, np.array, np.array, np.array) The number of shares to trade; the notional values of positions.
- add_trade(start_timestamp: pandas.Timestamp, pos_shares: numpy.array, neg_shares: numpy.array, uuid: uuid.UUID = None)
Adds a new trade to track.
- Parameters:
start_timestamp – (pd.Timestamp) Timestamp of the future label.
pos_shares – (np.array) Number of shares bought per asset.
neg_shares – (np.array) Number of shares sold per asset.
uuid – (str) Unique identifier used to link label to tradelog action.
- update_trades(update_timestamp: pandas.Timestamp) list
Closes previously opened trade and updates list of closed trades.
- Parameters:
update_timestamp – (pd.Timestamp) New timestamp to check vertical threshold.
- Returns:
(list) List of closed trades.