arbitragelab.time_series_approach.quantile_time_series
This module implements the quantile time series approach described in “A Machine Learning based Pairs Trading Investment Strategy” (pages 37-43) by Simão Moraes Sarmento and Nuno Horta.
Module Contents
Classes
The strategy which implements a quantile-based time series approach in mean-reversion trading. First, we define |
- class QuantileTimeSeriesTradingStrategy(long_quantile: float = 0.9, short_quantile: float = 0.1)
The strategy which implements a quantile-based time series approach in mean-reversion trading. First, we define top quantile of positive spread (y) differences and bottom quantile of negative spread differences. Secondly, we use time series spread prediction y_hat (it can be user-specified prediction, ARIMA, ANN, RNN, etc.) We enter a position if y_hat - y <= bottom quantile or y_hat - y >= top quantile.
This strategy is described in “A Machine Learning based Pairs Trading Investment Strategy” (pages 37-43) by Simão Moraes Sarmento and Nuno Horta.
- fit_thresholds(spread_series: pandas.Series)
Define quantile-based long/short difference thresholds from spread series.
- Parameters:
spread_series – (pd.Series) Spread series used to fit thresholds.
- plot_thresholds()
Plot KDE-plots of positive and negative differences vs long/short thresholds.
- Returns:
(plt.axes) The KDE plot.
- get_allocation(predicted_difference: float, exit_threshold: float = 0) int
Get target allocation (-1, 0, 1) based on current spread value, predicted value, and exit threshold. -1/1 means either to open a new short/long position or stay in a long/short trade (if the position has been already opened). 0 means exit the position.
- Parameters:
predicted_difference – (float) Spread predicted value - current spread value
exit_threshold – (float) Difference between predicted and current value threshold to close the trade.
- Returns:
(int) Trade signal: -1 (short), 0 (exit current position/stay in cash), 1(long).