nardew/talipp

talipp v2.x

nardew opened this issue · 4 comments

New major release of talipp!

This major release aims to modernize the API (it has not been touched for 3 years) and bring new features requested by users. Despite the breaking changes, it should be straightforward to migrate to the new version. To make transition easier, please follow guidelines below.

Aggregate PR: #96

High-level scope

Parameter name unification

Parameter names have been unified across all indicators.

Example:
Before:

class AO(Indicator):
   def __init__(self, period_fast: int, period_slow: int, ...):

After:

class AO(Indicator):
   def __init__(self, fast_period: int, slow_period: int, ...):

Migration:
Since parameters were only renamed and none was removed, check the indicators' definition for the new name.

PR: #95

Align length of input and output lists

If indicator requires multiple input values to produce the first output value, the input and output lists will have different lengths as initial None values are not kept in the output list. While this does not limit usage of the indicators (input and output lists are simply aligned from right), it was often confusing for the users. Therefore I decided to align lengths of the lists and use None if output value cannot be calculated.

Example:
Before:

sma = SMA(3, input_values=[1,2,3])
print(sma) -> [2]

After:

sma = SMA(3, input_values=[1,2,3])
print(sma) -> [None, None, 2]

Migration:
Any custom code handling varying lengths of the input and output lists can be removed.

PR: #104

Input values modifiers

In case of indicator chaining (i.e. output of one indicator is an input of another) it happens that output and input value types are sometimes incompatible (e.g. OHLCV -> float). All indicators now accept a new parameter input_modifier which is a callable object (method, lambda, ...) that will always be applied before processing the input value.

Example:

macd = MACD(...)
sma = SMA(3, input_indicator=macd, input_modifier=lambda x: x.signal)

Migration:
Some indicators contain input modifier already today but it is called value_extractor. If you were using value_extractor, just rename it to input_modifier.

PR: #97, #110

Customizable moving average sub-indicators

Many indicators use a moving average sub-indicator within them. By now moving average type was always hardcoded (SMA, EMA, ...). Sometimes it's useful to let user choose the moving average type used in an indicator. All indicators using a moving average internally now have another parameter which specifies moving average type.

Example:

class MACD(Indicator):
    def __init__(self, ..., ma_type: MAType = MAType.EMA)

PR: #99

New indicators added

Following indicators have been added:

  • ZLEMA
  • T3

Example:

zlema = ZLEMA(period=9, input_values=...)
t3 = T3(period=9, factor=0.7, input_values=...)

PR: #108 (ZLEMA), #109 (T3)

Method deprecation

Following methods have become deprecated and replaced by new ones with the same signature:

Indicator.add_intput_value -> Indicator.add
Indicator.update_intput_value -> Indicator.update
Indicator.remo_intput_value -> Indicator.remove

Example:

sma = SMA(period=3, input_values=...)
sma.add(3)
sma.update(5)
sma.remove()

Migration:
Even though previous methods still exist and point the new ones, it is recommended to rename the methods to new ones.

PR: #107

HaoH commented

It looks better!

I'll update my code using talipp 2.x :)

It looks better!

I'll update my code using talipp 2.x :)

Thanks for feedback @HaoH !

maybe add method should have been named append to have a similar interface than list, dequeue...

maybe add method should have been named append to have a similar interface than list, dequeue...

It could but Indicator is not a standard container, it is a generic Sequence, and the API is therefore defined according to that (meaning both add vs. append are fine).