-
Notifications
You must be signed in to change notification settings - Fork 0
03 Modules Signals Signals Module
Łukasz Rafał Czarnacki edited this page Mar 9, 2026
·
2 revisions
Source package: src/trade_lab/signals
Source files:
base.pysignals.pytemporal.pyexternal.py
This page covers both true signals and the ExternalSignal helper that is re-exported from trade_lab.signals.
Signals take a DataFrame with OHLCV data and append new columns.
You can chain signals together by passing one signal as source to another.
BaseSignal is the parent class for all signals.
- Stores optional upstream signal in
source. - Stores
lag(how many bars to shift output columns backward). - Raises
ValueErroriflag < 0.
- If
sourceexists, computes the source first and returns its output DataFrame. - If no source, returns the input
dfunchanged. - Purpose: make signal chaining consistent.
- Public method used to run a signal.
- Calls subclass
_compute(df)to create raw signal columns. - If
lag > 0, shifts each raw output column bylagbars. - Renames lagged outputs with suffix
_lag{lag}. - Returns the updated DataFrame.
- Returns final output column names.
- If
lag == 0, names are raw names. - If
lag > 0, adds_lag{lag}suffix.
- Must be implemented in each concrete signal.
- Should write data into
_raw_output_columns.
- Must be implemented in each concrete signal.
- Should visualize signal outputs.
- Must return raw column names created by
_compute. - Used by
computefor lag renaming/shifting.
OHLC creates log-normalized features from standard OHLC columns.
- Calls
get_data(df)to resolve optional source chain. - Uses previous close:
Close(t-1). - Creates four columns:
signal__log_return_opensignal__log_return_highsignal__log_return_lowsignal__log_return_close
- Formula for each price
P:log(P(t) / Close(t-1)).
HeikinAshi computes Heikin-Ashi bars and then log-normalizes them.
- Calls
get_data(df). - Computes HA Open/High/Low/Close from input OHLC.
- Saves raw HA bars internally for plotting.
- Creates normalized output columns:
signal__ha_opensignal__ha_highsignal__ha_lowsignal__ha_close
CyclicalTemporalSignal encodes calendar time as sine/cosine features.
- Works from
df.index(must be datetime-like). - Does not accept a source signal.
- Creates
signal__<component>_p<period>_sinandsignal__<component>_p<period>_cos.
ExternalSignal is a convenience wrapper for ML workflows. Despite the import path, it subclasses BaseIndicator, not BaseSignal.
- Reads an existing column already present in the DataFrame.
- Optionally applies a normalization callback.
- Writes the result as
indicator__<name>__lag_0(plus_lagNsuffix when lagged). - Integrates cleanly with
MLStrategy,FeatureMatrix, and feature auto-discovery.
- It does not accept upstream
sourcesignals. - It does not implement
to_signal_strength()forStandardStrategy. - Use it for ML features such as VIX, rates, macro series, or sentiment data that you merged yourself before calling TradeLab.
__init__(column, name=None, normalization=None, lag=0)
-
column: required source column in the DataFrame -
name: optional friendly output name -
normalization: optionalCallable[[pd.Series], pd.Series] -
lag: handled by the base indicator implementation
- Always call
compute(df)(not_compute) in normal usage. -
laghelps prevent look-ahead leakage in feature engineering. - Chaining works for signals that use
source; temporal signal is intentionally independent. -
ExternalSignalis ML-only and expects its input column to already exist indf.
- Section Home
- Signals
- Signals Module
- Signals Usage Examples
- Indicators
- Indicators: Base API
- Indicators: Moving Averages
- Indicators: Oscillators
- Indicators: Volume
- Indicators: Trend/Volatility
- Indicators: Statistical/Kernels
- Strategies
- Risk Management
- Position Sizing
- Machine Learning