indicator_util
#
Indicator utilities.
composite_to_lists
#
Transform the list of composite indicator output values into lists of values per each member attribute.
Applicable only to indicators retuning composite output values.
Examples:
Take Bollinger Bands indicator and its BBVal output value type. If the indicator is printed, it will return
[BBVal(lb=x1, cb=y1, ub=z1), BBVal(lb=x2, cb=y2, ub=z2), ...]
If the indicator is passed into composite_to_lists
method, the output will be transformed into
{'lb': [x1, x2, ...], 'cb': [y1, y2, ...], 'ub': [z1, z2, ...]}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indicator |
Indicator
|
Indicator to be transformed. |
required |
Returns:
Type | Description |
---|---|
Dict[str, List[float]]
|
A dictionary with keys being all members of the composite output type and values being all indicator's output values of given key. |
Raises:
Type | Description |
---|---|
TalippException
|
Indicator returning non-composite output values was passed in. |
Source code in talipp/indicator_util.py
has_valid_values
#
has_valid_values(
sequence: Union[Indicator, List[Any]],
window: int = 1,
exact: bool = False,
) -> bool
Evaluate whether sequence has well-defined values.
By well-defined values it is meant that the sequence has sufficient length (defined by window
argument) and its values do not contain None
. Not all values within the window
are checked, only the one at the beginning of the window. If it is non-None
, then it is assumed all values are non-None
.
If exact check is required (exact
argument), then any other value before the window must be None
.
Examples:
sequence=[1, 2], window=2, exact=True/False => return True
sequence=[1, 2], window=1, exact=False => return True
sequence=[1, 2], window=1, exact=True => return False
sequence=[None, 2], window=1, exact=True => return True
sequence=[None, 2], window=2, exact=True/False => return False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
Union[Indicator, List[Any]]
|
The input sequence. |
required |
window |
int
|
The window of values to be evaluated. |
1
|
exact |
bool
|
True if the evaluation requires the specified window contains well-defined values but any other greater window does not. |
False
|
Returns:
Type | Description |
---|---|
bool
|
True if sequence contains well-defined values, otherwise False. |
Source code in talipp/indicator_util.py
previous_if_exists
#
previous_if_exists(
sequence: Union[Indicator, List[Any]],
index: int = -1,
default: Any = 0,
) -> Any
Return value from index
th position in the sequence
if exists, otherwise return default
value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence |
Union[Indicator, List[Any]]
|
The input sequence. |
required |
index |
int
|
Index to be returned. |
-1
|
default |
Any
|
Default value to be returned if |
0
|
Returns:
Type | Description |
---|---|
Any
|
The value from the sequence at |