Indicator operations#
Each indicator provides operations to read, add, update and remove its values.
Reading values#
Indicators implement Sequence interface, meaning they can be treated as any other list when reading data.
Following operations demonstrate how to read indicator's values:
from talipp.indicators import SMA
sma = SMA(period=3, input_values=[1,2,3])
# print all values
# outputs [None, None, 2]
print(sma)
# print last value
# outputs 2
print(sma[-1])
# print number of values
# outputs 3
print(len(sma))
Adding values#
To incrementally add a new value use add method:
from talipp.indicators import SMA
sma = SMA(period=3, input_values=[1,2,3])
# add a single value
sma.add(4)
# add a list of values
sma.add([4, 5, 6])
Updating values#
To update the most recent value use update method:
from talipp.indicators import SMA
sma = SMA(period=3, input_values=[1,2,3])
# update the last input value
sma.update(4)
Note
Update of a value does not change number of indicator's values. Instead, it first removes the last input value and then it appends a new one.
Removing values#
Indicators provide several ways how to remove data:
-
To remove the most recent input value, use remove method:
-
To remove all input values, use remove_all method:
-
To remove the oldest values, use purge_oldest method:
Note
Purging old values is useful when memory consumption is a concern. If old indicator's values are not needed anymore, feel free to purge them. However, be careful not to purge any data if calculation of the current values still depends on them.