Advanced signal transformations
signal.surge()
signal.surge()signal.surge(short_period, long_period, how, decay=None)Calculate the surge of a signal. The surge is calculated as the fraction between a moving
average of a short window and a moving average of a longer window. The moving average can
be exponentially weighted.
When how is 'ma', the short and long period arguments are the window sizes in number of data points.
When how is 'ewm', the short and long period arguments are the parameters sent to the Pandas ewm
function, and which decay method to use is controlled with the decay parameter.
The signal is not resampled before the surge is calculated, so the parameters specifying
the window periods specify a number of data points, and not a number of days.
- Parameters:
short_period– The parameter to use for the (exponentially weighted) moving average in the numerator.long_period– The parameter to use for the (exponentially weighted) moving average in the denominator.how– A string specifying what kind of moving average to use, either ‘ewm’ for an exponentially weighted
moving average, or ‘ma’ for a regular moving average.decay– The type of decay parameter to use in theewmfunction. It can only be set when thehow
parameter isewm, and it can be one of'com','halflife','span'and'alpha'.
See the documentation of the
Pandas ewm function for further details.
Examples
Calculate the surge in close price using an exponentially weighted mean with half-lives of 5 and 20
data points:
close_price.surge(5, 20, 'ewm', 'halflife')Calculate the surge in transactions using a regular moving average with windows 28 and 91:
TransactionVolume.surge(28, 91, 'ma')signal.momentum()
signal.momentum()signal.momentum(days, limit=10)Calculate the “momentum” of a signal, defined as its relative change versus a certain number
of days ago. This method is closely related to the relative_change function, but is specialized
for daily time series, and automatically forward fills the underlying signal to get a smooth
momentum signal without gaps.
- Parameters:
signal– The signal to transform.days– The number of days between current and prior period. For example 365 for YoY
or 91 for approximately 3 months.limit– The maximum number of days to forward fill the underlying signal.
Examples
Retrieve the 3 month price momentum of the share price:
close_price.momentum(91)To get the year-over-year change in close price (smoothed with moving average):
close_price.moving_average(90, min_periods=70).momentum(365)signal.ewm()
signal.ewm()signal.ewm(halflife=None, *, span=None)Calculate the exponentially weighted mean of the signal.
This is a wrapper around the pandas ewm method.
NaN values are removed from the time series before calling the pandas ewm function. It is therefore
recommended to ensure that the data is on a known frequency, without missing values,
before performing this operation.
- Parameters:
halflife– The number of data points over which the weight should decay to its half.span– Decay specified in terms of span.
Example
The exponentially weighted mean of the close price:
close_price.ewm(halflife=14)signal.group_normalize()
signal.group_normalize()signal.group_normalize(group_signal, transform_type='winsorized_robust')Cross-sectional normalization of the signal, applied separately for each group of companies and each date.
A separate signal, group_signal, is used to determine the groups.
The most typical use case would be to group companies by sector, using the sector_revenue() signal as the
group_signal.
- Parameters:
group_signal– The signal that determines the groups by which the signal will be normalized.transform_type– Defaults to ‘winsorized_robust’.
Seegroup_transformbelow for the available options.
A use case for normalizing data by groups is to avoid sector or country biases when comparing companies.
Typical use cases would be to normalize by sectors or by countries.
signal.group_transform()
signal.group_transform()signal.group_transform(transform_type, centering_type, centering_weight_signal, tag, screen_frequency)The group_transform operation does a cross-sectional normalization of a signal across a set of companies.
- Parameters:
transform_type– the transform to use, either'robust','winsorized_robust','standard','winsorized_standard',
'uniform','minmax'or'identity'. Defaults to'identity'.centering_type– the centering to use, either'weighted_mean','mean',
'median'or'none'. Defaults to'none', which results in a centering given by the transform_type.centering_weight_signal– the signal used as weights when specifying'weighted_mean'for
thecentering_type. Must be specified whencentering_type='weighted_mean', otherwise ignored.tag– the resource name of the tag or screen that defines the group of companies.screen_frequency– the frequency with which to evaluate the screen, if a screen is used to define the group of companies.
Defaults to'M'for monthly evaluation. Alternatives include'W'for weekly or'Q'for quarterly update of the screen.
| Transform type | Description |
|---|---|
| robust | Applies sklearn’s RobustScaler. This transform subtracts the median, and then scales the data according to the quantile range from 25th to 75th percentile. |
| winsorized_robust | - First applies sklearn’s RobustScaler, which subtracts the mean and then the data according to the quantile range from 25th to 75th percentile. - Then soft-clipping is performed at ±3 standard deviations, by applying the tanh function. The number of standard deviations can be customized by specifying stdev_lim. |
| standard | Applies sklearn’s StandardScaler, which subtracts the mean and then scales to unit variance. |
| winsorized_standard | - Optionally, outliers can be removed at the very beginning, by setting the parameter q_remove to the fraction of the data that should be removed at both ends. E.g. q_remove=0.01 will remove the first and the last percentiles. By default, this step is not applied. - Then applies sklearn’s StandardScaler, which subtracts the mean and then scales to unit variance. - Finally soft-clipping is performed at ±3 standard deviations, by applying the tanh function. The number of standard deviations can be customized by specifying stdev_lim. |
| uniform | Transforms the data to percentiles using sklearn’s QuantileTransformer. By default a uniform distribution is produced (evenly spread between 0 and 1). Alternatively, a normal distribution can be obtained by specifying output_distribution='normal'. |
| minmax | Scales the data linearly to the range [-1, 1]. |
| identity | No transform, which means that only centering is applied. Rarely used in practice. |
Examples
When doing a group transform, you must specify which group of companies should be used. This is done
in the following way, using the ID of a company tag:
Market_Cap_mUSD.group_transform(
'winsorized_robust',
tag='tags/user:2a46627e-4e03-49f2-808e-d6fdadebbc61')It can also be done using the ID of a company screen. In this case, the set of companies included in
the group will be updated periodically based on the criteria of the screen. By default the screen is
updated monthly, but this can changed with the screen_frequency parameter, for instance set to
quarterly update:
Market_Cap_mUSD.group_transform(
'winsorized_robust',
tag='screens/1265',
screen_frequency='Q')Apply the uniform transform:
Market_Cap_mUSD.group_transform(
'uniform',
tag='tags/user:2a46627e-4e03-49f2-808e-d6fdadebbc61')