arbitragelab.trading.minimum_profit

Module for signal generation for Minimum Profit Optimization Trading strategy.

Module Contents

Classes

MinimumProfitTradingRule

This class implements trading strategy from the Minimum Profit Optimization method from the paper

class MinimumProfitTradingRule(shares: numpy.array, optimal_levels: numpy.array, spread_window: int = 10)

This class implements trading strategy from the Minimum Profit Optimization method from the paper by Lin, Y.-X., McCrae, M., and Gulati, C. “Loss protection in pairs trading through minimum profit bounds: a cointegration approach”

The strategy generates a signal by when spread <= buy_level or spread => sell_level and exit from a position when |spread| <= |close_level|.

This strategy allows only one open trade at a time.

update_spread_value(latest_spread_value: float)

Adds latest spread value to self.spread_series. Once it is done - one can check entry/exit signals.

Parameters:

latest_spread_value – (float) Latest spread value.

check_entry_signal() tuple

Function which checks entry condition for a spread series based on self.entry_buy_signal, self.entry_sell_signal, self.spread_series.

Returns:

(tuple) Tuple of boolean entry flag and side (if entry flag is True).

add_trade(start_timestamp: pandas.Timestamp, side_prediction: int, uuid: uuid.UUID = None, shares: numpy.array = None)

Adds a new trade to track. Calculates trigger prices and trigger timestamp.

Parameters:
  • start_timestamp – (pd.Timestamp) Timestamp of the future label.

  • side_prediction – (int) External prediction for the future label.

  • uuid – (str) Unique identifier used to link label to tradelog action.

  • shares – (np.array) Number of shares bought and sold per asset.

update_trades(update_timestamp: pandas.Timestamp) list

Checks whether any of the thresholds are triggered and currently open trades should be closed.

Parameters:

update_timestamp – (pd.Timestamp) New timestamp to check vertical threshold.

Returns:

(list) List of closed trades.