Combining signals

This section contains functions which combine multiple signals into a new signal. They can be used when you have different signals which work for different entities, and you want to create a single signal which works for all the relevant entities.

signal.combine_first(other, extend_only=False)

Update null elements with value from the same location in other. This is a wrapper around the pandas combine_first() method.

Parameters:
  • other – Signal to use for filling null values.

  • extend_only – If True, null values are only replaced after the last non-null value.

Example:

Combine FactSet actual sales with FactSet consensus sales (note though that fs_metric() achieves the same thing and is recommended):

fs_actual('sales').combine_first(fs_consensus('sales'))
concat(signals)

Concatenate multiple signals iterating across the columns.

This function combines multiple signals into a single signal by concatenating them along the columns. This is particularly useful for handling missing data for certain dates gracefully, as the concatenated result can then be aggregated using methods like .sum(), .mean(), etc., which skip missing data instead of producing missing results.

Parameters:

signals (List[Signal]) – A list of signals to concatenate.

Example:

Instead of using arithmetic operations that may produce missing data when signals have missing data:

# May produce missing data when data is missing
signal1 + signal2
signal1 - signal2

# Use concat to handle missing data gracefully
concat([signal1, signal2]).sum()
concat([signal1, -signal2]).sum()
fallback(signals, pre_extend, post_extend)

For each entity, use the first signal which has values.

The signals given to the fallback function are evaluated in order, and for each entity, the first signal that has a non-NaN value for the entity is selected.

To determine if a signal has values for an entity, the evaluation period is extended in both directions.

Parameters:
  • signals (List[Signal]) – A list of signals. The signals are evaluated in order, and for each entity, the first signal that has a non-NaN value for the entity is selected.

  • pre_extend (int) – Number of days to pre-extend the evaluation period with, to determine if an entity has a value for a signal. Default value is 10*365.

  • post_extend (int) – Number of days to post-extend the evaluation period with, to determine if an entity has a value for a signal. Default value is 10*365.

Example:

To retrieve FactSet Estimates sales, and fallback to FactSet Fundamentals if the company is not covered by the former:

fallback([fs_actual('sales'), fs_fundamental('sales')])
entity_type_switch(mapping)

Evaluate different sub-signals based on the type of the evaluation entities.

This can be useful when you have different signals for different entity types, but you need to express them as a single signal, such as in dashboards with multiple entity types.

Parameters:

mapping (Mapping[str,Signal]) – A map of entity type to signal. The entity type should be specified with the format namespace.entity_type unless the entity type is in the global namespace, in which case only entity_type is needed.

Example:

Signal that when evaluated for a company returns FactSet company sales and when evaluated for a brand returns brand_sales (assuming this signal exists):

entity_type_switch({'company': fs_actual('sales'), 'ns.brand': brand_sales})