1
1
import numpy as np
2
- from numpy .testing import (
3
- assert_array_equal ,
4
- assert_array_almost_equal ,
5
- assert_allclose
6
- )
7
2
import pytest
8
-
9
3
import talib
4
+ from numpy .testing import (assert_allclose , assert_array_almost_equal ,
5
+ assert_array_equal , assert_array_less )
10
6
from talib import func
11
7
12
8
@@ -159,11 +155,27 @@ def test_RSI():
159
155
0.00000024 , 0.00000024 , 0.00000023 ,
160
156
0.00000023 , 0.00000023 ], dtype = 'float64' )
161
157
result = func .RSI (a , 10 )
162
- assert_array_equal (result , [np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ])
158
+ assert_array_almost_equal (result , [np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,33.333333333333329 ,51.351351351351347 ,39.491916859122398 ,51.84807024709005 ,42.25953803191981 ,52.101824405061215 ,52.101824405061215 ,43.043664867691085 ,43.043664867691085 ,43.043664867691085 ])
159
+ # assert_array_equal(result, [np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,0,0,0,0,0,0,0,0,0,0])
163
160
result = func .RSI (a * 100000 , 10 )
164
161
assert_array_almost_equal (result , [np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,np .nan ,33.333333333333329 ,51.351351351351347 ,39.491916859122398 ,51.84807024709005 ,42.25953803191981 ,52.101824405061215 ,52.101824405061215 ,43.043664867691085 ,43.043664867691085 ,43.043664867691085 ])
165
162
166
163
164
+
165
+ def test_BBANDS ():
166
+ # Bollinger bands for small numbers fix
167
+ inputs = np .array ([
168
+ 0.00000010 ,
169
+ 0.00000011 ,
170
+ 0.00000012 ,
171
+ 0.00000013 ,
172
+ 0.00000014
173
+ ])
174
+ bollinger = func .BBANDS (inputs , matype = 0 , timeperiod = 2 )
175
+ assert_array_less (bollinger [1 ], bollinger [0 ])
176
+ assert_array_less (bollinger [2 ], bollinger [1 ])
177
+
178
+
167
179
def test_MAVP ():
168
180
a = np .array ([1 ,5 ,3 ,4 ,7 ,3 ,8 ,1 ,4 ,6 ], dtype = float )
169
181
b = np .array ([2 ,4 ,2 ,4 ,2 ,4 ,2 ,4 ,2 ,4 ], dtype = float )
@@ -181,8 +193,8 @@ def test_MAVP():
181
193
182
194
183
195
def test_MAXINDEX ():
184
- import talib as func
185
196
import numpy as np
197
+ import talib as func
186
198
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 ])
187
199
b = func .MA (a , 10 )
188
200
c = func .MAXINDEX (b , 10 )
0 commit comments