Events Module
Convert continuous signals to discrete entry/exit events.
events
Convert continuous signals into discrete entry events.
signal_to_events(df, sig_col='sig', mode='transitions')
Convert continuous signals into discrete entry events (Long/Short).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing signal column |
required |
sig_col
|
str
|
Name of signal column (expected values: +1 for long, -1 for short, 0 for neutral) |
'sig'
|
mode
|
(transitions, levels)
|
'transitions': Fire events only on state changes (enter_long, enter_short) 'levels': Fire events on all long/short signals |
'transitions'
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys: - 'enter_long': numpy array of integer indices where long entries occur - 'enter_short': numpy array of integer indices where short entries occur - 'exit_long': numpy array of integer indices where long exits occur (optional) - 'exit_short': numpy array of integer indices where short exits occur (optional) |
Notes
Transitions are defined as: - enter_long: previous signal <= 0 and current signal > 0 - enter_short: previous signal >= 0 and current signal < 0 - exit_long: previous signal > 0 and current signal <= 0 - exit_short: previous signal < 0 and current signal >= 0