arbitragelab.util.spread_modeling_helper
This module implements the Spread Modeling Helper class.
Module Contents
Classes
This class basically wraps most of the framework's most |
- class SpreadModelingHelper(sprd: pandas.Series, insample_date_range: tuple, oosample_date_range: tuple, feat_expansion: bool = True, unique_sampling: bool = True)
This class basically wraps most of the framework’s most repeatable functionality into two basic steps; - init - where the datasets given the spread are generated. - plot_model_results - given a model plot strategy results and metrics.
- get_filtering_results(ytrain: pandas.DataFrame, ypred: pandas.DataFrame, std_dev_sample: float, working_df: pandas.DataFrame, plot: bool = True, figsize: tuple = (15, 10))
Executes and if needed plots the results from all the filter combinations included in the library.
- Parameters:
ytrue – (pd.DataFrame) The ground truth data.
ypred – (pd.DataFrame) The predicted data.
std_dev_sample – (float) The range for the buy/sell threshold.
working_df – (pd.DataFrame) DataFrame with both legs of the spread.
plot – (bool) Plot the trades of each filter.
figsize – (tuple) Figure size as a tuple for plotting.
- Returns:
(tuple) All events series: unfiltered, std, corr, std_vol, corr_vol.
- get_metrics(working_df: pandas.DataFrame) pandas.DataFrame
Main handler for gathering all the financial metrics relating to each dataset slice.
- Parameters:
working_df – (pd.DataFrame) DataFrame with both legs of the spread.
- Returns:
(pd.DataFrame) DataFrame with all financial metrics.
- static convert_filter_events_to_metrics(filter_events: pandas.DataFrame) pandas.DataFrame
Convert a set of returns to financial metrics. The metrics include annual returns, annual volatility, max drawdown and Sharpe ratio.
- Parameters:
filter_events – (pd.DataFrame) Trade events tagged with a ‘side’ column with 1/0/-1 referring to long, no trade, short.
- Returns:
(pd.DataFrame) DataFrame with metrics: Returns, Volatility, Max Drawdown, Sharpe Ratio.
- plot_model_results(model, figsize=(15, 10)) matplotlib.axes._axes.Axes
Plots the regression results for the training, test and oos sets.
- Parameters:
model – (Object) ML model that has the method ‘predict’ implemented.
figsize – (tuple) Figure size for plot.
- Returns:
(Axes)
- static plot_trades(ax_object: object, events: pandas.DataFrame, title: str) matplotlib.axes._axes.Axes
Plots long/short/all trades given a set of labeled returns.
- Parameters:
ax_object – (Object) Matplotlib plotting object.
events – (pd.DataFrame) Trade DataFrame with returns and side as columns.
title – (str) Title to use for the plot.
- Returns:
(Axes)
- static plot_regression_results(ax_object: object, y_true: pandas.Series, y_pred: pandas.Series, title: str) matplotlib.axes._axes.Axes
Plots Regression results (predicted vs ground) for visual comparison.
- Parameters:
ax_object – (Object) Matplotlib plotting object.
ytrue – (pd.Series) The ground truth data.
ypred – (pd.Series) The predicted data.
title – (str) Title for plot.
- Returns:
(Axes)