Skip to content

Commit a9652eb

Browse files
committed
Adding new indicators: ACCBANDS, AVGDEV, IMI
1 parent 7f3e20a commit a9652eb

File tree

7 files changed

+155
-4
lines changed

7 files changed

+155
-4
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.6.2
2+
=====
3+
4+
- [NEW]: Adding indicators ACCBANDS, AVGDEV, IMI
5+
16
0.6.1
27
=====
38

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ta-lib"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
dynamic = ["authors", "classifiers", "description", "license", "readme"]
55
dependencies = [
66
"setuptools",

setup.py

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

152152
setup(
153153
name='TA-Lib',
154-
version='0.6.1',
154+
version='0.6.2',
155155
description='Python wrapper for TA-Lib',
156156
long_description=long_description,
157157
long_description_content_type='text/markdown',

talib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def wrapper(*args, **kwds):
132132
setattr(stream, func_name, wrapped_func)
133133
globals()[stream_func_name] = wrapped_func
134134

135-
__version__ = '0.6.1'
135+
__version__ = '0.6.2'
136136

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

talib/_func.pxi

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,33 @@ cdef np.ndarray make_int_array(np.npy_intp length, int lookback):
139139
return outinteger
140140

141141

142+
@wraparound(False) # turn off relative indexing from end of lists
143+
@boundscheck(False) # turn off bounds-checking for entire function
144+
def ACCBANDS( np.ndarray high not None , np.ndarray low not None , np.ndarray close not None , int timeperiod=-2**31 ):
145+
""" ACCBANDS(high, low, close[, timeperiod=?])"""
146+
cdef:
147+
np.npy_intp length
148+
int begidx, endidx, lookback
149+
TA_RetCode retCode
150+
int outbegidx
151+
int outnbelement
152+
np.ndarray outrealupperband
153+
np.ndarray outrealmiddleband
154+
np.ndarray outreallowerband
155+
high = check_array(high)
156+
low = check_array(low)
157+
close = check_array(close)
158+
length = check_length3(high, low, close)
159+
begidx = check_begidx3(length, <double*>(high.data), <double*>(low.data), <double*>(close.data))
160+
endidx = <int>length - begidx - 1
161+
lookback = begidx + lib.TA_ACCBANDS_Lookback( timeperiod )
162+
outrealupperband = make_double_array(length, lookback)
163+
outrealmiddleband = make_double_array(length, lookback)
164+
outreallowerband = make_double_array(length, lookback)
165+
retCode = lib.TA_ACCBANDS( 0 , endidx , <double *>(high.data)+begidx , <double *>(low.data)+begidx , <double *>(close.data)+begidx , timeperiod , &outbegidx , &outnbelement , <double *>(outrealupperband.data)+lookback , <double *>(outrealmiddleband.data)+lookback , <double *>(outreallowerband.data)+lookback )
166+
_ta_check_success("TA_ACCBANDS", retCode)
167+
return outrealupperband , outrealmiddleband , outreallowerband
168+
142169
@wraparound(False) # turn off relative indexing from end of lists
143170
@boundscheck(False) # turn off bounds-checking for entire function
144171
def ACOS( np.ndarray real not None ):
@@ -555,6 +582,27 @@ def AVGPRICE( np.ndarray open not None , np.ndarray high not None , np.ndarray l
555582
_ta_check_success("TA_AVGPRICE", retCode)
556583
return outreal
557584

585+
@wraparound(False) # turn off relative indexing from end of lists
586+
@boundscheck(False) # turn off bounds-checking for entire function
587+
def AVGDEV( np.ndarray real not None , int timeperiod=-2**31 ):
588+
""" AVGDEV(real[, timeperiod=?])"""
589+
cdef:
590+
np.npy_intp length
591+
int begidx, endidx, lookback
592+
TA_RetCode retCode
593+
int outbegidx
594+
int outnbelement
595+
np.ndarray outreal
596+
real = check_array(real)
597+
length = real.shape[0]
598+
begidx = check_begidx1(length, <double*>(real.data))
599+
endidx = <int>length - begidx - 1
600+
lookback = begidx + lib.TA_AVGDEV_Lookback( timeperiod )
601+
outreal = make_double_array(length, lookback)
602+
retCode = lib.TA_AVGDEV( 0 , endidx , <double *>(real.data)+begidx , timeperiod , &outbegidx , &outnbelement , <double *>(outreal.data)+lookback )
603+
_ta_check_success("TA_AVGDEV", retCode)
604+
return outreal
605+
558606
@wraparound(False) # turn off relative indexing from end of lists
559607
@boundscheck(False) # turn off bounds-checking for entire function
560608
def BBANDS( np.ndarray real not None , int timeperiod=-2**31 , double nbdevup=-4e37 , double nbdevdn=-4e37 , int matype=0 ):
@@ -3174,6 +3222,28 @@ def HT_TRENDMODE( np.ndarray real not None ):
31743222
_ta_check_success("TA_HT_TRENDMODE", retCode)
31753223
return outinteger
31763224

3225+
@wraparound(False) # turn off relative indexing from end of lists
3226+
@boundscheck(False) # turn off bounds-checking for entire function
3227+
def IMI( np.ndarray open not None , np.ndarray close not None , int timeperiod=-2**31 ):
3228+
""" IMI(open, close[, timeperiod=?])"""
3229+
cdef:
3230+
np.npy_intp length
3231+
int begidx, endidx, lookback
3232+
TA_RetCode retCode
3233+
int outbegidx
3234+
int outnbelement
3235+
np.ndarray outreal
3236+
open = check_array(open)
3237+
close = check_array(close)
3238+
length = check_length2(open, close)
3239+
begidx = check_begidx2(length, <double*>(open.data), <double*>(close.data))
3240+
endidx = <int>length - begidx - 1
3241+
lookback = begidx + lib.TA_IMI_Lookback( timeperiod )
3242+
outreal = make_double_array(length, lookback)
3243+
retCode = lib.TA_IMI( 0 , endidx , <double *>(open.data)+begidx , <double *>(close.data)+begidx , timeperiod , &outbegidx , &outnbelement , <double *>(outreal.data)+lookback )
3244+
_ta_check_success("TA_IMI", retCode)
3245+
return outreal
3246+
31773247
@wraparound(False) # turn off relative indexing from end of lists
31783248
@boundscheck(False) # turn off bounds-checking for entire function
31793249
def KAMA( np.ndarray real not None , int timeperiod=-2**31 ):
@@ -5219,4 +5289,4 @@ def WMA( np.ndarray real not None , int timeperiod=-2**31 ):
52195289
_ta_check_success("TA_WMA", retCode)
52205290
return outreal
52215291

5222-
__TA_FUNCTION_NAMES__ = ["ACOS","AD","ADD","ADOSC","ADX","ADXR","APO","AROON","AROONOSC","ASIN","ATAN","ATR","AVGPRICE","BBANDS","BETA","BOP","CCI","CDL2CROWS","CDL3BLACKCROWS","CDL3INSIDE","CDL3LINESTRIKE","CDL3OUTSIDE","CDL3STARSINSOUTH","CDL3WHITESOLDIERS","CDLABANDONEDBABY","CDLADVANCEBLOCK","CDLBELTHOLD","CDLBREAKAWAY","CDLCLOSINGMARUBOZU","CDLCONCEALBABYSWALL","CDLCOUNTERATTACK","CDLDARKCLOUDCOVER","CDLDOJI","CDLDOJISTAR","CDLDRAGONFLYDOJI","CDLENGULFING","CDLEVENINGDOJISTAR","CDLEVENINGSTAR","CDLGAPSIDESIDEWHITE","CDLGRAVESTONEDOJI","CDLHAMMER","CDLHANGINGMAN","CDLHARAMI","CDLHARAMICROSS","CDLHIGHWAVE","CDLHIKKAKE","CDLHIKKAKEMOD","CDLHOMINGPIGEON","CDLIDENTICAL3CROWS","CDLINNECK","CDLINVERTEDHAMMER","CDLKICKING","CDLKICKINGBYLENGTH","CDLLADDERBOTTOM","CDLLONGLEGGEDDOJI","CDLLONGLINE","CDLMARUBOZU","CDLMATCHINGLOW","CDLMATHOLD","CDLMORNINGDOJISTAR","CDLMORNINGSTAR","CDLONNECK","CDLPIERCING","CDLRICKSHAWMAN","CDLRISEFALL3METHODS","CDLSEPARATINGLINES","CDLSHOOTINGSTAR","CDLSHORTLINE","CDLSPINNINGTOP","CDLSTALLEDPATTERN","CDLSTICKSANDWICH","CDLTAKURI","CDLTASUKIGAP","CDLTHRUSTING","CDLTRISTAR","CDLUNIQUE3RIVER","CDLUPSIDEGAP2CROWS","CDLXSIDEGAP3METHODS","CEIL","CMO","CORREL","COS","COSH","DEMA","DIV","DX","EMA","EXP","FLOOR","HT_DCPERIOD","HT_DCPHASE","HT_PHASOR","HT_SINE","HT_TRENDLINE","HT_TRENDMODE","KAMA","LINEARREG","LINEARREG_ANGLE","LINEARREG_INTERCEPT","LINEARREG_SLOPE","LN","LOG10","MA","MACD","MACDEXT","MACDFIX","MAMA","MAVP","MAX","MAXINDEX","MEDPRICE","MFI","MIDPOINT","MIDPRICE","MIN","MININDEX","MINMAX","MINMAXINDEX","MINUS_DI","MINUS_DM","MOM","MULT","NATR","OBV","PLUS_DI","PLUS_DM","PPO","ROC","ROCP","ROCR","ROCR100","RSI","SAR","SAREXT","SIN","SINH","SMA","SQRT","STDDEV","STOCH","STOCHF","STOCHRSI","SUB","SUM","T3","TAN","TANH","TEMA","TRANGE","TRIMA","TRIX","TSF","TYPPRICE","ULTOSC","VAR","WCLPRICE","WILLR","WMA"]
5292+
__TA_FUNCTION_NAMES__ = ["ACCBANDS","ACOS","AD","ADD","ADOSC","ADX","ADXR","APO","AROON","AROONOSC","ASIN","ATAN","ATR","AVGPRICE","AVGDEV","BBANDS","BETA","BOP","CCI","CDL2CROWS","CDL3BLACKCROWS","CDL3INSIDE","CDL3LINESTRIKE","CDL3OUTSIDE","CDL3STARSINSOUTH","CDL3WHITESOLDIERS","CDLABANDONEDBABY","CDLADVANCEBLOCK","CDLBELTHOLD","CDLBREAKAWAY","CDLCLOSINGMARUBOZU","CDLCONCEALBABYSWALL","CDLCOUNTERATTACK","CDLDARKCLOUDCOVER","CDLDOJI","CDLDOJISTAR","CDLDRAGONFLYDOJI","CDLENGULFING","CDLEVENINGDOJISTAR","CDLEVENINGSTAR","CDLGAPSIDESIDEWHITE","CDLGRAVESTONEDOJI","CDLHAMMER","CDLHANGINGMAN","CDLHARAMI","CDLHARAMICROSS","CDLHIGHWAVE","CDLHIKKAKE","CDLHIKKAKEMOD","CDLHOMINGPIGEON","CDLIDENTICAL3CROWS","CDLINNECK","CDLINVERTEDHAMMER","CDLKICKING","CDLKICKINGBYLENGTH","CDLLADDERBOTTOM","CDLLONGLEGGEDDOJI","CDLLONGLINE","CDLMARUBOZU","CDLMATCHINGLOW","CDLMATHOLD","CDLMORNINGDOJISTAR","CDLMORNINGSTAR","CDLONNECK","CDLPIERCING","CDLRICKSHAWMAN","CDLRISEFALL3METHODS","CDLSEPARATINGLINES","CDLSHOOTINGSTAR","CDLSHORTLINE","CDLSPINNINGTOP","CDLSTALLEDPATTERN","CDLSTICKSANDWICH","CDLTAKURI","CDLTASUKIGAP","CDLTHRUSTING","CDLTRISTAR","CDLUNIQUE3RIVER","CDLUPSIDEGAP2CROWS","CDLXSIDEGAP3METHODS","CEIL","CMO","CORREL","COS","COSH","DEMA","DIV","DX","EMA","EXP","FLOOR","HT_DCPERIOD","HT_DCPHASE","HT_PHASOR","HT_SINE","HT_TRENDLINE","HT_TRENDMODE","IMI","KAMA","LINEARREG","LINEARREG_ANGLE","LINEARREG_INTERCEPT","LINEARREG_SLOPE","LN","LOG10","MA","MACD","MACDEXT","MACDFIX","MAMA","MAVP","MAX","MAXINDEX","MEDPRICE","MFI","MIDPOINT","MIDPRICE","MIN","MININDEX","MINMAX","MINMAXINDEX","MINUS_DI","MINUS_DM","MOM","MULT","NATR","OBV","PLUS_DI","PLUS_DM","PPO","ROC","ROCP","ROCR","ROCR100","RSI","SAR","SAREXT","SIN","SINH","SMA","SQRT","STDDEV","STOCH","STOCHF","STOCHRSI","SUB","SUM","T3","TAN","TANH","TEMA","TRANGE","TRIMA","TRIX","TSF","TYPPRICE","ULTOSC","VAR","WCLPRICE","WILLR","WMA"]

talib/_stream.pxi

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@ from _ta_lib cimport TA_RetCode
66

77
np.import_array() # Initialize the NumPy C API
88

9+
@wraparound(False) # turn off relative indexing from end of lists
10+
@boundscheck(False) # turn off bounds-checking for entire function
11+
def stream_ACCBANDS( np.ndarray high not None , np.ndarray low not None , np.ndarray close not None , int timeperiod=-2**31 ):
12+
""" ACCBANDS(high, low, close[, timeperiod=?])"""
13+
cdef:
14+
np.npy_intp length
15+
TA_RetCode retCode
16+
double* high_data
17+
double* low_data
18+
double* close_data
19+
int outbegidx
20+
int outnbelement
21+
double outrealupperband
22+
double outrealmiddleband
23+
double outreallowerband
24+
high = check_array(high)
25+
high_data = <double*>high.data
26+
low = check_array(low)
27+
low_data = <double*>low.data
28+
close = check_array(close)
29+
close_data = <double*>close.data
30+
length = check_length3(high, low, close)
31+
outrealupperband = NaN
32+
outrealmiddleband = NaN
33+
outreallowerband = NaN
34+
retCode = lib.TA_ACCBANDS( <int>(length) - 1 , <int>(length) - 1 , high_data , low_data , close_data , timeperiod , &outbegidx , &outnbelement , &outrealupperband , &outrealmiddleband , &outreallowerband )
35+
_ta_check_success("TA_ACCBANDS", retCode)
36+
return outrealupperband , outrealmiddleband , outreallowerband
37+
938
@wraparound(False) # turn off relative indexing from end of lists
1039
@boundscheck(False) # turn off bounds-checking for entire function
1140
def stream_ACOS( np.ndarray real not None ):
@@ -432,6 +461,25 @@ def stream_AVGPRICE( np.ndarray open not None , np.ndarray high not None , np.nd
432461
_ta_check_success("TA_AVGPRICE", retCode)
433462
return outreal
434463

464+
@wraparound(False) # turn off relative indexing from end of lists
465+
@boundscheck(False) # turn off bounds-checking for entire function
466+
def stream_AVGDEV( np.ndarray real not None , int timeperiod=-2**31 ):
467+
""" AVGDEV(real[, timeperiod=?])"""
468+
cdef:
469+
np.npy_intp length
470+
TA_RetCode retCode
471+
double* real_data
472+
int outbegidx
473+
int outnbelement
474+
double outreal
475+
real = check_array(real)
476+
real_data = <double*>real.data
477+
length = real.shape[0]
478+
outreal = NaN
479+
retCode = lib.TA_AVGDEV( <int>(length) - 1 , <int>(length) - 1 , real_data , timeperiod , &outbegidx , &outnbelement , &outreal )
480+
_ta_check_success("TA_AVGDEV", retCode)
481+
return outreal
482+
435483
@wraparound(False) # turn off relative indexing from end of lists
436484
@boundscheck(False) # turn off bounds-checking for entire function
437485
def stream_BBANDS( np.ndarray real not None , int timeperiod=-2**31 , double nbdevup=-4e37 , double nbdevdn=-4e37 , int matype=0 ):
@@ -3273,6 +3321,28 @@ def stream_HT_TRENDMODE( np.ndarray real not None ):
32733321
_ta_check_success("TA_HT_TRENDMODE", retCode)
32743322
return outinteger
32753323

3324+
@wraparound(False) # turn off relative indexing from end of lists
3325+
@boundscheck(False) # turn off bounds-checking for entire function
3326+
def stream_IMI( np.ndarray open not None , np.ndarray close not None , int timeperiod=-2**31 ):
3327+
""" IMI(open, close[, timeperiod=?])"""
3328+
cdef:
3329+
np.npy_intp length
3330+
TA_RetCode retCode
3331+
double* open_data
3332+
double* close_data
3333+
int outbegidx
3334+
int outnbelement
3335+
double outreal
3336+
open = check_array(open)
3337+
open_data = <double*>open.data
3338+
close = check_array(close)
3339+
close_data = <double*>close.data
3340+
length = check_length2(open, close)
3341+
outreal = NaN
3342+
retCode = lib.TA_IMI( <int>(length) - 1 , <int>(length) - 1 , open_data , close_data , timeperiod , &outbegidx , &outnbelement , &outreal )
3343+
_ta_check_success("TA_IMI", retCode)
3344+
return outreal
3345+
32763346
@wraparound(False) # turn off relative indexing from end of lists
32773347
@boundscheck(False) # turn off bounds-checking for entire function
32783348
def stream_KAMA( np.ndarray real not None , int timeperiod=-2**31 ):

talib/_ta_lib.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ cdef extern from "ta-lib/ta_abstract.h":
193193
char* TA_FunctionDescriptionXML()
194194

195195
cdef extern from "ta-lib/ta_func.h":
196+
TA_RetCode TA_ACCBANDS(int startIdx, int endIdx, const double inHigh[], const double inLow[], const double inClose[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outRealUpperBand[], double outRealMiddleBand[], double outRealLowerBand[])
197+
int TA_ACCBANDS_Lookback(int optInTimePeriod)
196198
TA_RetCode TA_ACOS(int startIdx, int endIdx, const double inReal[], int *outBegIdx, int *outNBElement, double outReal[])
197199
int TA_ACOS_Lookback()
198200
TA_RetCode TA_AD(int startIdx, int endIdx, const double inHigh[], const double inLow[], const double inClose[], const double inVolume[], int *outBegIdx, int *outNBElement, double outReal[])
@@ -219,6 +221,8 @@ cdef extern from "ta-lib/ta_func.h":
219221
int TA_ATR_Lookback(int optInTimePeriod)
220222
TA_RetCode TA_AVGPRICE(int startIdx, int endIdx, const double inOpen[], const double inHigh[], const double inLow[], const double inClose[], int *outBegIdx, int *outNBElement, double outReal[])
221223
int TA_AVGPRICE_Lookback()
224+
TA_RetCode TA_AVGDEV(int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
225+
int TA_AVGDEV_Lookback(int optInTimePeriod)
222226
TA_RetCode TA_BBANDS(int startIdx, int endIdx, const double inReal[], int optInTimePeriod, double optInNbDevUp, double optInNbDevDn, TA_MAType optInMAType, int *outBegIdx, int *outNBElement, double outRealUpperBand[], double outRealMiddleBand[], double outRealLowerBand[])
223227
int TA_BBANDS_Lookback(int optInTimePeriod, double optInNbDevUp, double optInNbDevDn, TA_MAType optInMAType)
224228
TA_RetCode TA_BETA(int startIdx, int endIdx, const double inReal0[], const double inReal1[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
@@ -383,6 +387,8 @@ cdef extern from "ta-lib/ta_func.h":
383387
int TA_HT_TRENDLINE_Lookback()
384388
TA_RetCode TA_HT_TRENDMODE(int startIdx, int endIdx, const double inReal[], int *outBegIdx, int *outNBElement, int outInteger[])
385389
int TA_HT_TRENDMODE_Lookback()
390+
TA_RetCode TA_IMI(int startIdx, int endIdx, const double inOpen[], const double inClose[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
391+
int TA_IMI_Lookback(int optInTimePeriod)
386392
TA_RetCode TA_KAMA(int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])
387393
int TA_KAMA_Lookback(int optInTimePeriod)
388394
TA_RetCode TA_LINEARREG(int startIdx, int endIdx, const double inReal[], int optInTimePeriod, int *outBegIdx, int *outNBElement, double outReal[])

0 commit comments

Comments
 (0)