Signal
Signal#
-
class sigtech.framework.signal.signal_object.Signal
The signal class creates a signal object that uses the same
.history()
API as the framework.Keyword arguments:
start_date
: minimum date output time series.end_date
: maximum date output time series.function
: the function object that will produce the output.function_name
: function address for database persistence.underliers
: A dictionary where keys correspond to the inputs of the function argument and value to the name of the object. This object can be of any type with output of timeseries, dataframe or dictionary, e.g. instruments, strategies or other signal objects.
Example: Creates signal object that has a history that is half the SPXT Index.
def func(ts, n): return ts / n example_signal_obj = Signal( signal_function=func, underliers={'ts': 'SPXT INDEX'}, params={'n': 2} )
-
start_date: Optional[datetime.date]
-
end_date: Optional[datetime.date]
-
start_dt: Optional[datetime.datetime]
-
end_dt: Optional[datetime.datetime]
-
function: Optional[collections.abc.Callable]
-
function_name: Optional[str]
-
underliers: Optional[dict]
-
params: Optional[dict]
-
args: Optional[list]
-
cache_history: Optional[bool]
-
additional_dependencies: Optional[list]
-
ticker: Optional[str]
-
db_ticker: Optional[str]
-
db_sector: Optional[str]
-
data_source_all: Optional[list[str]]
-
has_preloaded_history(field=None, data_point=None)
Called by the Dependencies framework - arguments not used
-
property dependency_type
Dependency Type
-
property history_fields: list[str]
Fields for this signal.
-
property supplementary_fields
Enable the definition of additional fields.
-
property prime_history_field: str
The main history field returned by default.
-
property data_point
Field used when retrieving history.
-
property data_source
Data source of the signal.
-
history()
Return the signal history. The history is first built if the signal was not already calculated.
- Returns
Signal history.
-
intraday_history(period: datetime.timedelta, start_dt=None, end_dt=None, timezone=None)
Return the signal history. The history is first built if the signal was not already calculated.
- Parameters
period – period of history requested
start_dt – filter the output by datetime range
end_dt – filter the output by datetime range
timezone – set the timezone of the returned series to this value
- Returns
Signal history.
-
truncate(var, intraday=False)
Set start and end date for historical outputs of time series, dataframes or dictionaries.
- Parameters
var – Input history.
intraday – bool - is var an intra-day time series
- Returns
Truncated history.
-
get_underlying_names(filter_signals=False)
Return the names of signal underliers.
- Parameters
filter_signals – If True, signals are filtered out (default is False).
- Returns
List of underlier identifiers.
-
get_underlying_data()
Return a DataFrame of underliers.
-
map_underliers()
Return a dict of underliers.
-
get_dependents()
Return the set of dependents.
-
update(underliers=None, params=None, del_underliers=None, del_params=None, **kwargs)
Update the signal object.
- Parameters
underliers – Dict of underliers to add.
params – Dict of parameters to add.
del_underliers – Dict of underliers to remove.
del_params – Dict of parameters to remove.
-
clone(name=None)
Clone the signal object.
- Parameters
name – Ticker identifier of the cloned signal.
- Returns
Signal object.
-
deep_clone()
Clone the signal object (deep copy).
-
insert()
Update all dependents and return a new signal object.
-
replace_with(node)
Update all dependents given a new node.
- Parameters
node – Input node.
-
explode_initial_data()
Serialise the signal object.
-
clear_history()
Clear the signal history.
-
clear_calc_history()
Clear the signal and underliers history.
-
set_calendar(calendar_name)
Set the signal object calendar.
- Parameters
calendar_name – Calendar identifier.
-
check_signal_parameters()
Validate the signal parameters.
-
check_all_signal_inputs()
Validate the signal inputs.
-
store_signal_diagnoistics(df, df_name)
Store the serialised signal items.
- Parameters
df – Input data.
df_name – Storage name.
-
print_code(lines=None, imports=None, underlier_set=None)
Code print method.
- Parameters
lines – List of code lines.
imports – List of imports.
underlier_set – Set of underliers.
-
create_operator_signal(other, signal_function, input_names=None)
Create a signal operator.
- Parameters
other – Signal object.
signal_function – Signal operation identifier.
input_names – List of input identifiers.
- Returns
Signal object.
-
available_data_providers(entitled_only=True) Optional[List[str]]
Available data providers for this object. Bool to return entitled providers only
-
property cache_name: str
Cache name of this object.
-
property class_name
Class name of this object.
-
property class_short_name
Short name of the object class.
-
clear_cached_data()
Clear all the cached data of the object.
-
clone_object(params=None)
Return a clone of the object with amended parameters.
- Parameters
params – Optional dictionary of parameters to override.
- Returns
New object.
-
compute_dependencies(root_dependency: Optional[sigtech.framework.internal.infra.mu.graph.registry.factory.Dependency] = None)
Compute these dependencies - triggers MDS requests
-
static convert_dtypes(clz)
Class decorator to convert classes’ BaseType into variable annotations (PEP-526), and to generate __aliases__ based on BaseType.db_name when required.
-
data_dict()
Return the object attributes in a dict.
-
dependencies(input_dependency: Optional[sigtech.framework.internal.infra.mu.graph.registry.factory.Dependency] = None, valuation_currency: Optional[str] = None, use_start: bool = True) list[sigtech.framework.internal.infra.mu.graph.registry.factory.Dependency]
Returns a list of Dependency
- Parameters
input_dependency – A Dependency object representing the root of the dependency tree to be returned.
valuation_currency – If supplied, include the dependencies required to output the data in this currency.
use_start – If False, return only dependencies required to calculate an earliest start date - self.start_date will be None in this case.
- Returns
List of Dependency objects representing the current level in the dependency tree.
-
property env: sigtech.framework.config.config.ConfiguredEnvironment
Return the configured environment.
-
env_date_change(old_env_dt: datetime.datetime, new_env_dt: datetime.datetime, live_data_update=None)
Routine called after the environment date is changed.
- Parameters
old_env_dt – Old datetime (tz aware).
new_env_dt – New datetime (tz aware).
live_data_update – Live streaming data associated with the environment date change.
-
ewma(ts)
EWMA operator.
- Parameters
window – Size of the window.
ts – Input timeseries.
- Returns
pandas Series or DataFrame.
-
finalize_for_comparison()
Method to call to ensure all data dict values are finalized prior to doing object comparisons.
-
classmethod from_dictionary(dct: dict[str, Any], cache: bool = True, identifier: Optional[sigtech.framework.infra.data_adapter.identifier.Identifier] = None, env: Optional[sigtech.framework.config.config.ConfiguredEnvironment] = None, **kwargs)
Factory method to create object using data dictionary
-
classmethod get_names(sort_by_group: Optional[bool] = False, include_db: Optional[bool] = True, include_local: Optional[bool] = True, include_children: Optional[bool] = False, ignore_unmapped: Optional[bool] = True) list[str]
Return an ordered list of object names associated with the class.
- Parameters
sort_by_group – If set, the list is first ordered by sector/group, if applies, e.g. commodity or index futures (default is False).
include_db – If set, include objects available from the database (default is True).
include_local – If set, include objects available in the local environment (default is True).
include_children – If set, include objects available from child classes (default is False).
ignore_unmapped – If set, ignore errors due to unmapped database objects (default is True).
- Returns
List of object names.
-
property identifier: sigtech.framework.infra.data_adapter.identifier.Identifier
Return the object identifier.
-
info() dict
Return a dictionary with useful object information.
-
property input_parameters
Values of initial input parameters entered when creating the instance.
-
property internal_id
Ticker - i.e. part of name determining content of the class. For types with saved reference data - ticker will be
self._ticker
. For software types - ticker should be calculated.
-
property is_unmapped
Check if the object is not mapped.
-
property live_supported: bool
Flag for live supported objects.
-
ma(ts)
Rolling average operator.
- Parameters
window – Size of the window.
ts – Input timeseries.
- Returns
pandas Series or DataFrame.
-
macd(short_window: int = 12, long_window: int = 26) pandas.core.series.Series
Moving Average Convergence Divergence Indicator.
See
macd()
for details.- Parameters
ts – Close price timeseries.
short_window – Short moving average periods.
long_window – Long moving average periods.
- Returns
Series of indicator values.
-
property name
Primary name by which the
FrameworkObject
is identified. If reference information (or e.g. corresponding time series) are stored in the DB, then this name will be used.
-
normalize_weights() pandas.core.frame.DataFrame
Normalise weights to have 100% gross notional.
- Parameters
ts – Input timeseries.
- Returns
pandas Dataframe.
allocation.normalize_weights( pd.DataFrame({'A': [2, 2, 2], 'B': [1, 2, 1]}) )
Returns:
A
B
0
0.67
0.33
1
0.5
0.5
2
0.67
0.33
-
normalize_weights_zero_filled() pandas.core.frame.DataFrame
Normalise weights to have 100% gross notional and fill empty values with zeros.
- Parameters
ts – Input timeseries.
- Returns
pandas Dataframe.
normalize_weights_zero_filled( pd.DataFrame({'A': [1,np.nan,2], 'B': [0.5, np.nan, np.nan]}) )
Returns:
# A
B
0
0.67
0.33
1
0.0
0.0
2
1.0
0.0
-
percentile()
Expand the percentile rank of a timeseries.
- Parameters
ts – pandas Series or DataFrame.
- Returns
pandas Series or DataFrame.
-
print_dependencies(root_dependency: Optional[sigtech.framework.internal.infra.mu.graph.registry.factory.Dependency] = None, resolve_future_dependencies: bool = True, fields: Optional[list] = None)
Pretty print dependency tree :param root_dependency: starting dependency of the tree. :param resolve_future_dependencies: resolve future dependencies before printing. If ‘false’ nothing get printed. :param fields: additional fields to extract from dependencies object. Default fields are
product_type
,currency
,frequency
anddata_source
. To get the list of available fields for an object you can use thedata_dict()
method.
-
property product_type
Return the
product_type
property of this object.
-
property sector
Sector used on BBG, or the class ID for SIG instruments.
-
sigmoid(ts)
Sigmoid operator.
- Parameters
factor – Factor value.
ts – Input timeseries.
- Returns
pandas Series or DataFrame.
-
simple_ma_signal(long_span, df)
Create a signal based on rolling average cross operator.
- Parameters
short_span – Size of the short span window.
long_span – Size of the long span window.
df – Input DataFrame.
- Returns
Signal
object.
-
static sort_key_static(name)
Convert a name to the sort key as of Portfolio Presentation Guidelines for performance reasons.
- Parameters
name – Input name.
- Returns
Tuple (sort key, length of sort key, input name).
-
textual_representation()
Return a printable representation of this object.
-
validate()
Validation routine adding checks that will be run on object creation.
-
vol(*, ts, factor=252, **kwargs)
Volatility operator.
- Parameters
ts – pandas Series or DataFrame.
factor – Volatility factor (default is 252).
- Returns
pandas Series or DataFrame.
-
z_score(centered=True, min_periods=None, ts=None)
Z-score calculation.
- Parameters
period – Size of the moving window.
centered – If set to True, do not consider the rolling mean (default is True).
min_periods – Minimum number of observations in window required to have a value.
ts – Input timeseries.
-
instrument_id: Optional[int]