Skip to content

Commit 0dce79b

Browse files
committed
Fixed {MIN/MAX/MINMAX}INDEX functions to return correct indices.
1 parent 521d4a5 commit 0dce79b

File tree

9 files changed

+834
-729
lines changed

9 files changed

+834
-729
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.4.21
2+
======
3+
4+
- [FIX]: Fixed {MIN/MAX/MINMAX}INDEX functions to return correct indices.
5+
16
0.4.20
27
======
38

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def build_extensions(self):
144144

145145
setup(
146146
name='TA-Lib',
147-
version='0.4.20',
147+
version='0.4.21',
148148
description='Python wrapper for TA-Lib',
149149
long_description=long_description,
150150
long_description_content_type='text/markdown',

talib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def wrapper(*args, **kwargs):
7575
setattr(stream, func_name, wrapped_func)
7676
globals()[stream_func_name] = wrapped_func
7777

78-
__version__ = '0.4.20'
78+
__version__ = '0.4.21'
7979

8080
# In order to use this python library, talib (i.e. this __file__) will be
8181
# imported at some point, either explicitly or indirectly via talib.func

talib/_func.pxi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,9 @@ def MAXINDEX( np.ndarray real not None , int timeperiod=-2**31 ):
36673667
outinteger = make_int_array(length, lookback)
36683668
retCode = lib.TA_MAXINDEX( 0 , endidx , <double *>(real.data)+begidx , timeperiod , &outbegidx , &outnbelement , <int *>(outinteger.data)+lookback )
36693669
_ta_check_success("TA_MAXINDEX", retCode)
3670+
outinteger_data = <int*>outinteger.data
3671+
for i from lookback <= i < length:
3672+
outinteger_data[i] += begidx
36703673
return outinteger
36713674

36723675
@wraparound(False) # turn off relative indexing from end of lists
@@ -3856,6 +3859,9 @@ def MININDEX( np.ndarray real not None , int timeperiod=-2**31 ):
38563859
outinteger = make_int_array(length, lookback)
38573860
retCode = lib.TA_MININDEX( 0 , endidx , <double *>(real.data)+begidx , timeperiod , &outbegidx , &outnbelement , <int *>(outinteger.data)+lookback )
38583861
_ta_check_success("TA_MININDEX", retCode)
3862+
outinteger_data = <int*>outinteger.data
3863+
for i from lookback <= i < length:
3864+
outinteger_data[i] += begidx
38593865
return outinteger
38603866

38613867
@wraparound(False) # turn off relative indexing from end of lists
@@ -3924,6 +3930,12 @@ def MINMAXINDEX( np.ndarray real not None , int timeperiod=-2**31 ):
39243930
outmaxidx = make_int_array(length, lookback)
39253931
retCode = lib.TA_MINMAXINDEX( 0 , endidx , <double *>(real.data)+begidx , timeperiod , &outbegidx , &outnbelement , <int *>(outminidx.data)+lookback , <int *>(outmaxidx.data)+lookback )
39263932
_ta_check_success("TA_MINMAXINDEX", retCode)
3933+
outminidx_data = <int*>outminidx.data
3934+
for i from lookback <= i < length:
3935+
outminidx_data[i] += begidx
3936+
outmaxidx_data = <int*>outmaxidx.data
3937+
for i from lookback <= i < length:
3938+
outmaxidx_data[i] += begidx
39273939
return outminidx , outmaxidx
39283940

39293941
@wraparound(False) # turn off relative indexing from end of lists

talib/_ta_lib.c

Lines changed: 780 additions & 722 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

talib/test_abstract.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,21 @@ def test_pandas_series():
4747
output = talib.SMA(input_df['close'], 10)
4848
expected = pandas.Series(func.SMA(ford_2012['close'], 10),
4949
index=input_df.index)
50-
pandas.util.testing.assert_series_equal(output, expected)
50+
pandas.testing.assert_series_equal(output, expected)
5151

5252
# Test kwargs
5353
output = talib.SMA(real=input_df['close'], timeperiod=10)
54-
pandas.util.testing.assert_series_equal(output, expected)
54+
pandas.testing.assert_series_equal(output, expected)
5555

5656
# Test talib.func API
5757
output = func.SMA(input_df['close'], timeperiod=10)
58-
pandas.util.testing.assert_series_equal(output, expected)
58+
pandas.testing.assert_series_equal(output, expected)
5959

6060
# Test multiple outputs such as from BBANDS
6161
_, output, _ = talib.BBANDS(input_df['close'], 10)
6262
expected = pandas.Series(func.BBANDS(ford_2012['close'], 10)[1],
6363
index=input_df.index)
64-
pandas.util.testing.assert_series_equal(output, expected)
64+
pandas.testing.assert_series_equal(output, expected)
6565

6666

6767
def test_SMA():

talib/test_func.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,14 @@ def test_MAVP():
156156
sma3 = func.SMA(a, 3)
157157
assert_np_arrays_equal(result[2::2], sma2[2::2])
158158
assert_np_arrays_equal(result[3::2], sma3[3::2])
159+
160+
def test_MAXINDEX():
161+
import talib as func
162+
import numpy as np
163+
a = np.array([1., 2, 3, 4, 5, 6, 7, 8, 7, 7, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 15])
164+
b = func.MA(a, 10)
165+
c = func.MAXINDEX(b, 10)
166+
assert_np_arrays_equal(c, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,16,16,21])
167+
d = np.array([1., 2, 3])
168+
e = func.MAXINDEX(d, 10)
169+
assert_np_arrays_equal(e, [0,0,0])

talib/test_stream.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ def test_CDL3BLACKCROWS_pandas():
5757

5858
r = stream.CDL3BLACKCROWS(o, h, l, c)
5959
assert_equals(r, -100)
60+
61+
def test_MAXINDEX():
62+
import talib as stream
63+
import numpy as np
64+
a = np.array([1., 2, 3, 4, 5, 6, 7, 8, 7, 7, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5, 15])
65+
r = stream.MAXINDEX(a, 10)
66+
assert_equals(r, 21)

tools/generate_func.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# FIXME: don't return number of elements since it always equals allocation?
1212

1313
functions = []
14-
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include']
14+
include_paths = ['/usr/include', '/usr/local/include', '/opt/include', '/opt/local/include', '/opt/homebrew/Cellar/ta-lib/0.4.0/include']
1515
if sys.platform == 'win32':
1616
include_paths = [r'c:\ta-lib\c\include']
1717
header_found = False
@@ -381,6 +381,18 @@ def cleanup(name):
381381

382382
print(')')
383383
print(' _ta_check_success("%s", retCode)' % name)
384+
if 'INDEX' in f:
385+
for arg in args:
386+
var = arg.split()[-1]
387+
388+
if 'out' not in var:
389+
continue
390+
391+
if var.endswith('[]'):
392+
var = cleanup(var[:-2])
393+
print(' %s_data = <int*>%s.data' % (var, var))
394+
print(' for i from lookback <= i < length:')
395+
print(' %s_data[i] += begidx' % var)
384396
print(' return ', end='')
385397
i = 0
386398
for arg in args:

0 commit comments

Comments
 (0)