-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Many indicators that can be calculated by single close value are not support input_values=list[OHLCV] in init. But time is required in resample.
I found the usecase in the tail of https://nardew.github.io/talipp/latest/timeframe-sampling/ and it fail.
It seems to be issues.
import sys; sys.version
'3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:21:13) [GCC 13.3.0]'
pip freeze | grep talipp
talipp==2.5.0
My test code:
print(type(goo), len(goo), type(goo[0]))
pprint(goo[:3])
macd = ti.MACD(fast_period=12, slow_period=26, signal_period=9, input_values=goo, input_modifier=lambda x: x.close, input_sampling=tpi.SamplingPeriodType.HOUR_1)
Print message:
<class 'list'> 1000 <class 'talipp.ohlcv.OHLCV'>
[OHLCV(open=235.75,
high=236.52,
low=235.42,
close=235.9,
volume=272749,
time=Timestamp('2023-12-04 22:30:00')),
OHLCV(open=235.94,
high=236.0,
low=235.13,
close=235.14,
volume=414928,
time=Timestamp('2023-12-04 22:31:00')),
OHLCV(open=235.14,
high=235.77,
low=234.92,
close=235.21,
volume=353329,
time=Timestamp('2023-12-04 22:32:00'))]
Error message:
AttributeError Traceback (most recent call last)
Cell In[25], line 5
3 print(type(goo), len(goo), type(goo[0]))
4 pprint(goo[:3])
----> 5 macd = ti.MACD(fast_period=12, slow_period=26, signal_period=9, input_values=goo, input_modifier=lambda x: x.close, input_sampling=tpi.SamplingPeriodType.HOUR_1)
File ~/anaconda3/envs/py312/lib/python3.12/site-packages/talipp/indicators/MACD.py:63, in MACD.init(self, fast_period, slow_period, signal_period, input_values, input_indicator, input_modifier, ma_type, input_sampling)
60 self.add_sub_indicator(self.ma_slow)
61 self.add_managed_sequence(self.signal_line)
---> 63 self.initialize(input_values, input_indicator)
File ~/anaconda3/envs/py312/lib/python3.12/site-packages/talipp/indicators/Indicator.py:69, in Indicator.initialize(self, input_values, input_indicator)
67 if input_values is not None:
68 for value in input_values:
---> 69 self.add(value)
71 if input_indicator is not None:
72 for value in input_indicator:
File ~/anaconda3/envs/py312/lib/python3.12/site-packages/talipp/indicators/Indicator.py:101, in Indicator.add(self, value)
92 def add(self, value: Any) -> None:
93 """Add a new input value.
94
95 Args:
96 value: Value to be added.
97 """
99 if (self.input_sampler is not None
100 and has_valid_values(self.input_values)
--> 101 and self.input_sampler.is_same_period(value, self.input_values[-1])):
102 self.update(value)
103 else:
File ~/anaconda3/envs/py312/lib/python3.12/site-packages/talipp/input.py:140, in Sampler.is_same_period(self, first, second)
127 """Evaluate whether two [OHLCV][talipp.ohlcv.OHLCV] objects belong to the same period.
128
129 OHLCV objects have to contain time component to be comparable.
(...) 136 True if two objects belong to the same period, otherwise False.
137 """
139 first_normalized = self._normalize(first.time)
--> 140 second_normalized = self._normalize(second.time)
142 return first_normalized == second_normalized
AttributeError: 'float' object has no attribute 'time'