Threshold functions

Threshold functions#

class sigtech.framework.signal.library.threshold_fns.StandardThresholdFunctions

Class containing references to standard threshold functions.

IGNORE(dt, size_date, positions, allocation_ts, strategy) bool

Default threshold function, always returns True.

Parameters:
  • instrument_name – Instrument identifier.

  • dt – Reference datetime.

  • size_date – Size date for weight calculation.

  • positions – Strategy positions.

  • allocation_ts – Allocation timeseries.

  • strategy – Strategy object.

Returns:

Whether or not to rebalance the instrument given a state. Always True.

SIGNAL_CHANGE(dt, size_date, positions, allocation_ts, strategy) bool

Threshold function for signals populated at a higher frequency than they necessarily change. Only triggers a rebalance in the instrument if the signal value has changed compared to the previous value.

Parameters:
  • instrument_name – Name of the instrument.

  • dt – Reference datetime.

  • size_date – Size date.

  • positions – Positions.

  • allocation_ts – Timeseries for weight allocation.

  • strategy – Strategy object.

Returns:

Whether or not to rebalance the given instrument.

SIGNAL_CHANGE_AND_THRESHOLD_COMBINED(dt, size_date, positions, allocation_ts, strategy, rebalance_threshold) bool

Evaluates both whether the underlying signal has changed and whether the weight is currently deviated away from the target weight more than the given threshold. If either of these two checks return True, the instrument will be rebalanced.

An example of a combined threshold function where two threshold functions are evaluated one after another.

Parameters:
  • instrument_name – Instrument identifier.

  • dt – Reference datetime.

  • size_date – Size date for weight calculation.

  • positions – Strategy positions.

  • allocation_ts – Allocation timeseries.

  • strategy – Strategy object.

  • rebalance_threshold – Rebalance threshold.

Returns:

Whether or not to rebalance the given instrument.

SIGNAL_THRESHOLD(dt, size_date, positions, allocation_ts, strategy, rebalance_threshold, *args) bool

Signal threshold that returns True only when the difference between the signal weight and the effective weight is greater than a certain amount.

Parameters:
  • instrument_name – Instrument identifier.

  • dt – Reference datetime.

  • size_date – Size date for weight calculation.

  • positions – Strategy positions.

  • allocation_ts – Allocation timeseries.

  • strategy – Strategy object.

  • rebalance_threshold – Rebalance threshold.

Returns:

Whether or not to rebalance the given instrument.

SPARSE_REBALANCING(dt, size_date, positions, allocation_ts, strategy) bool

Threshold function for sparse signals. This will not trigger rebalancing to a zero weight unless there is a current position. The signal can then be primarily composed of zeros which will only be used for closing positions. Nan values can also be included in the signal and will be ignored, so they indicate holding the current position.

Parameters:
  • instrument_name – Name of the instrument.

  • dt – Reference datetime.

  • size_date – Size date.

  • positions – Positions.

  • allocation_ts – Timeseries for weight allocation.

Returns:

Whether or not to rebalance the instrument given a state.

sigtech.framework.signal.library.threshold_fns.sparse_threshold_function(instrument_name, dt, size_date, positions, allocation_ts, strategy) bool

Threshold function for sparse signals. This will not trigger rebalancing to a zero weight unless there is a current position. The signal can then be primarily composed of zeros which will only be used for closing positions. Nan values can also be included in the signal and will be ignored, so they indicate holding the current position.

Parameters:
  • instrument_name – Name of the instrument.

  • dt – Reference datetime.

  • size_date – Size date.

  • positions – Positions.

  • allocation_ts – Timeseries for weight allocation.

Returns:

Whether or not to rebalance the instrument given a state.