TA-Lib integration
The pyalgotrade.talibext.indicator module provides integration with Python wrapper for TA-Lib (http://mrjbq7.github.com/ta-lib/)
to enable calling TA-Lib functions directly with pyalgotrade.dataseries.DataSeries or pyalgotrade.dataseries.bards.BarDataSeries
instances instead of numpy arrays.
If you’re familiar with the talib module, then using the pyalgotrade.talibext.indicator module should be straightforward.
When using talib standalone you do something like this:
import numpy
import talib
data = numpy.random.random(100)
upper, middle, lower = talib.BBANDS(data, matype=talib.MA_T3)
To use the pyalgotrade.talibext.indicator module in your strategies you should do something like this:
def onBars(self, bars):
closeDs = self.getFeed().getDataSeries("orcl").getCloseDataSeries()
upper, middle, lower = pyalgotrade.talibext.indicator.BBANDS(closeDs, 100, matype=talib.MA_T3)
if upper != None:
print "%s" % upper[-1]
Every function in the pyalgotrade.talibext.indicator module receives one or more dataseries (most receive just one) and the
number of values to use from the dataseries. In the example above, we’re calculating Bollinger Bands over the last 100 closing prices.
If the parameter name is ds, then you should pass a regular pyalgotrade.dataseries.DataSeries instance, like the one
shown in the example above.
If the parameter name is barDs, then you should pass a pyalgotrade.dataseries.bards.BarDataSeries instance, like in the next
example:
def onBars(self, bars):
barDs = self.getFeed().getDataSeries("orcl")
sar = indicator.SAR(barDs, 100)
if sar != None:
print "%s" % sar[-1]
The following TA-Lib functions are available through the pyalgotrade.talibext.indicator module:
-
pyalgotrade.talibext.indicator.AD(barDs, count)
Chaikin A/D Line
-
pyalgotrade.talibext.indicator.ADOSC(barDs, count, fastperiod=-2147483648, slowperiod=-2147483648)
Chaikin A/D Oscillator
-
pyalgotrade.talibext.indicator.ADX(barDs, count, timeperiod=-2147483648)
Average Directional Movement Index
-
pyalgotrade.talibext.indicator.ADXR(barDs, count, timeperiod=-2147483648)
Average Directional Movement Index Rating
-
pyalgotrade.talibext.indicator.APO(ds, count, fastperiod=-2147483648, slowperiod=-2147483648, matype=0)
Absolute Price Oscillator
-
pyalgotrade.talibext.indicator.AROON(barDs, count, timeperiod=-2147483648)
Aroon
-
pyalgotrade.talibext.indicator.AROONOSC(barDs, count, timeperiod=-2147483648)
Aroon Oscillator
-
pyalgotrade.talibext.indicator.ATR(barDs, count, timeperiod=-2147483648)
Average True Range
-
pyalgotrade.talibext.indicator.AVGPRICE(barDs, count)
Average Price
-
pyalgotrade.talibext.indicator.BBANDS(ds, count, timeperiod=-2147483648, nbdevup=-4e+37, nbdevdn=-4e+37, matype=0)
Bollinger Bands
-
pyalgotrade.talibext.indicator.BETA(ds1, ds2, count, timeperiod=-2147483648)
Beta
-
pyalgotrade.talibext.indicator.BOP(barDs, count)
Balance Of Power
-
pyalgotrade.talibext.indicator.CCI(barDs, count, timeperiod=-2147483648)
Commodity Channel Index
-
pyalgotrade.talibext.indicator.CDL2CROWS(barDs, count)
Two Crows
-
pyalgotrade.talibext.indicator.CDL3BLACKCROWS(barDs, count)
Three Black Crows
-
pyalgotrade.talibext.indicator.CDL3INSIDE(barDs, count)
Three Inside Up/Down
-
pyalgotrade.talibext.indicator.CDL3LINESTRIKE(barDs, count)
Three-Line Strike
-
pyalgotrade.talibext.indicator.CDL3OUTSIDE(barDs, count)
Three Outside Up/Down
-
pyalgotrade.talibext.indicator.CDL3STARSINSOUTH(barDs, count)
Three Stars In The South
-
pyalgotrade.talibext.indicator.CDL3WHITESOLDIERS(barDs, count)
Three Advancing White Soldiers
-
pyalgotrade.talibext.indicator.CDLABANDONEDBABY(barDs, count, penetration=-4e+37)
Abandoned Baby
-
pyalgotrade.talibext.indicator.CDLADVANCEBLOCK(barDs, count)
Advance Block
-
pyalgotrade.talibext.indicator.CDLBELTHOLD(barDs, count)
Belt-hold
-
pyalgotrade.talibext.indicator.CDLBREAKAWAY(barDs, count)
Breakaway
-
pyalgotrade.talibext.indicator.CDLCLOSINGMARUBOZU(barDs, count)
Closing Marubozu
-
pyalgotrade.talibext.indicator.CDLCONCEALBABYSWALL(barDs, count)
Concealing Baby Swallow
-
pyalgotrade.talibext.indicator.CDLCOUNTERATTACK(barDs, count)
Counterattack
-
pyalgotrade.talibext.indicator.CDLDARKCLOUDCOVER(barDs, count, penetration=-4e+37)
Dark Cloud Cover
-
pyalgotrade.talibext.indicator.CDLDOJI(barDs, count)
Doji
-
pyalgotrade.talibext.indicator.CDLDOJISTAR(barDs, count)
Doji Star
-
pyalgotrade.talibext.indicator.CDLDRAGONFLYDOJI(barDs, count)
Dragonfly Doji
-
pyalgotrade.talibext.indicator.CDLENGULFING(barDs, count)
Engulfing Pattern
-
pyalgotrade.talibext.indicator.CDLEVENINGDOJISTAR(barDs, count, penetration=-4e+37)
Evening Doji Star
-
pyalgotrade.talibext.indicator.CDLEVENINGSTAR(barDs, count, penetration=-4e+37)
Evening Star
-
pyalgotrade.talibext.indicator.CDLGAPSIDESIDEWHITE(barDs, count)
Up/Down-gap side-by-side white lines
-
pyalgotrade.talibext.indicator.CDLGRAVESTONEDOJI(barDs, count)
Gravestone Doji
-
pyalgotrade.talibext.indicator.CDLHAMMER(barDs, count)
Hammer
-
pyalgotrade.talibext.indicator.CDLHANGINGMAN(barDs, count)
Hanging Man
-
pyalgotrade.talibext.indicator.CDLHARAMI(barDs, count)
Harami Pattern
-
pyalgotrade.talibext.indicator.CDLHARAMICROSS(barDs, count)
Harami Cross Pattern
-
pyalgotrade.talibext.indicator.CDLHIGHWAVE(barDs, count)
High-Wave Candle
-
pyalgotrade.talibext.indicator.CDLHIKKAKE(barDs, count)
Hikkake Pattern
-
pyalgotrade.talibext.indicator.CDLHIKKAKEMOD(barDs, count)
Modified Hikkake Pattern
-
pyalgotrade.talibext.indicator.CDLHOMINGPIGEON(barDs, count)
Homing Pigeon
-
pyalgotrade.talibext.indicator.CDLIDENTICAL3CROWS(barDs, count)
Identical Three Crows
-
pyalgotrade.talibext.indicator.CDLINNECK(barDs, count)
In-Neck Pattern
-
pyalgotrade.talibext.indicator.CDLINVERTEDHAMMER(barDs, count)
Inverted Hammer
-
pyalgotrade.talibext.indicator.CDLKICKING(barDs, count)
Kicking
-
pyalgotrade.talibext.indicator.CDLKICKINGBYLENGTH(barDs, count)
Kicking - bull/bear determined by the longer marubozu
-
pyalgotrade.talibext.indicator.CDLLADDERBOTTOM(barDs, count)
Ladder Bottom
-
pyalgotrade.talibext.indicator.CDLLONGLEGGEDDOJI(barDs, count)
Long Legged Doji
-
pyalgotrade.talibext.indicator.CDLLONGLINE(barDs, count)
Long Line Candle
-
pyalgotrade.talibext.indicator.CDLMARUBOZU(barDs, count)
Marubozu
-
pyalgotrade.talibext.indicator.CDLMATCHINGLOW(barDs, count)
Matching Low
-
pyalgotrade.talibext.indicator.CDLMATHOLD(barDs, count, penetration=-4e+37)
Mat Hold
-
pyalgotrade.talibext.indicator.CDLMORNINGDOJISTAR(barDs, count, penetration=-4e+37)
Morning Doji Star
-
pyalgotrade.talibext.indicator.CDLMORNINGSTAR(barDs, count, penetration=-4e+37)
Morning Star
-
pyalgotrade.talibext.indicator.CDLONNECK(barDs, count)
On-Neck Pattern
-
pyalgotrade.talibext.indicator.CDLPIERCING(barDs, count)
Piercing Pattern
-
pyalgotrade.talibext.indicator.CDLRICKSHAWMAN(barDs, count)
Rickshaw Man
-
pyalgotrade.talibext.indicator.CDLRISEFALL3METHODS(barDs, count)
Rising/Falling Three Methods
-
pyalgotrade.talibext.indicator.CDLSEPARATINGLINES(barDs, count)
Separating Lines
-
pyalgotrade.talibext.indicator.CDLSHOOTINGSTAR(barDs, count)
Shooting Star
-
pyalgotrade.talibext.indicator.CDLSHORTLINE(barDs, count)
Short Line Candle
-
pyalgotrade.talibext.indicator.CDLSPINNINGTOP(barDs, count)
Spinning Top
-
pyalgotrade.talibext.indicator.CDLSTALLEDPATTERN(barDs, count)
Stalled Pattern
-
pyalgotrade.talibext.indicator.CDLSTICKSANDWICH(barDs, count)
Stick Sandwich
-
pyalgotrade.talibext.indicator.CDLTAKURI(barDs, count)
Takuri (Dragonfly Doji with very long lower shadow)
-
pyalgotrade.talibext.indicator.CDLTASUKIGAP(barDs, count)
Tasuki Gap
-
pyalgotrade.talibext.indicator.CDLTHRUSTING(barDs, count)
Thrusting Pattern
-
pyalgotrade.talibext.indicator.CDLTRISTAR(barDs, count)
Tristar Pattern
-
pyalgotrade.talibext.indicator.CDLUNIQUE3RIVER(barDs, count)
Unique 3 River
-
pyalgotrade.talibext.indicator.CDLUPSIDEGAP2CROWS(barDs, count)
Upside Gap Two Crows
-
pyalgotrade.talibext.indicator.CDLXSIDEGAP3METHODS(barDs, count)
Upside/Downside Gap Three Methods
-
pyalgotrade.talibext.indicator.CMO(ds, count, timeperiod=-2147483648)
Chande Momentum Oscillator
-
pyalgotrade.talibext.indicator.CORREL(ds1, ds2, count, timeperiod=-2147483648)
Pearson’s Correlation Coefficient (r)
-
pyalgotrade.talibext.indicator.DEMA(ds, count, timeperiod=-2147483648)
Double Exponential Moving Average
-
pyalgotrade.talibext.indicator.DX(barDs, count, timeperiod=-2147483648)
Directional Movement Index
-
pyalgotrade.talibext.indicator.EMA(ds, count, timeperiod=-2147483648)
Exponential Moving Average
-
pyalgotrade.talibext.indicator.HT_DCPERIOD(ds, count)
Hilbert Transform - Dominant Cycle Period
-
pyalgotrade.talibext.indicator.HT_DCPHASE(ds, count)
Hilbert Transform - Dominant Cycle Phase
-
pyalgotrade.talibext.indicator.HT_PHASOR(ds, count)
Hilbert Transform - Phasor Components
-
pyalgotrade.talibext.indicator.HT_SINE(ds, count)
Hilbert Transform - SineWave
-
pyalgotrade.talibext.indicator.HT_TRENDLINE(ds, count)
Hilbert Transform - Instantaneous Trendline
-
pyalgotrade.talibext.indicator.HT_TRENDMODE(ds, count)
Hilbert Transform - Trend vs Cycle Mode
-
pyalgotrade.talibext.indicator.KAMA(ds, count, timeperiod=-2147483648)
Kaufman Adaptive Moving Average
-
pyalgotrade.talibext.indicator.LINEARREG(ds, count, timeperiod=-2147483648)
Linear Regression
-
pyalgotrade.talibext.indicator.LINEARREG_ANGLE(ds, count, timeperiod=-2147483648)
Linear Regression Angle
-
pyalgotrade.talibext.indicator.LINEARREG_INTERCEPT(ds, count, timeperiod=-2147483648)
Linear Regression Intercept
-
pyalgotrade.talibext.indicator.LINEARREG_SLOPE(ds, count, timeperiod=-2147483648)
Linear Regression Slope
-
pyalgotrade.talibext.indicator.MA(ds, count, timeperiod=-2147483648, matype=0)
All Moving Average
-
pyalgotrade.talibext.indicator.MACD(ds, count, fastperiod=-2147483648, slowperiod=-2147483648, signalperiod=-2147483648)
Moving Average Convergence/Divergence
-
pyalgotrade.talibext.indicator.MACDEXT(ds, count, fastperiod=-2147483648, fastmatype=0, slowperiod=-2147483648, slowmatype=0, signalperiod=-2147483648, signalmatype=0)
MACD with controllable MA type
-
pyalgotrade.talibext.indicator.MACDFIX(ds, count, signalperiod=-2147483648)
Moving Average Convergence/Divergence Fix 12/26
-
pyalgotrade.talibext.indicator.MAMA(ds, count, fastlimit=-4e+37, slowlimit=-4e+37)
MESA Adaptive Moving Average
-
pyalgotrade.talibext.indicator.MAX(ds, count, timeperiod=-2147483648)
Highest value over a specified period
-
pyalgotrade.talibext.indicator.MAXINDEX(ds, count, timeperiod=-2147483648)
Index of highest value over a specified period
-
pyalgotrade.talibext.indicator.MEDPRICE(barDs, count)
Median Price
-
pyalgotrade.talibext.indicator.MFI(barDs, count, timeperiod=-2147483648)
Money Flow Index
-
pyalgotrade.talibext.indicator.MIDPOINT(ds, count, timeperiod=-2147483648)
MidPoint over period
-
pyalgotrade.talibext.indicator.MIDPRICE(barDs, count, timeperiod=-2147483648)
Midpoint Price over period
-
pyalgotrade.talibext.indicator.MIN(ds, count, timeperiod=-2147483648)
Lowest value over a specified period
-
pyalgotrade.talibext.indicator.MININDEX(ds, count, timeperiod=-2147483648)
Index of lowest value over a specified period
-
pyalgotrade.talibext.indicator.MINMAX(ds, count, timeperiod=-2147483648)
Lowest and highest values over a specified period
-
pyalgotrade.talibext.indicator.MINMAXINDEX(ds, count, timeperiod=-2147483648)
Indexes of lowest and highest values over a specified period
-
pyalgotrade.talibext.indicator.MINUS_DI(barDs, count, timeperiod=-2147483648)
Minus Directional Indicator
-
pyalgotrade.talibext.indicator.MINUS_DM(barDs, count, timeperiod=-2147483648)
Minus Directional Movement
-
pyalgotrade.talibext.indicator.MOM(ds, count, timeperiod=-2147483648)
Momentum
-
pyalgotrade.talibext.indicator.NATR(barDs, count, timeperiod=-2147483648)
Normalized Average True Range
-
pyalgotrade.talibext.indicator.OBV(ds1, volumeDs, count)
On Balance Volume
-
pyalgotrade.talibext.indicator.PLUS_DI(barDs, count, timeperiod=-2147483648)
Plus Directional Indicator
-
pyalgotrade.talibext.indicator.PLUS_DM(barDs, count, timeperiod=-2147483648)
Plus Directional Movement
-
pyalgotrade.talibext.indicator.PPO(ds, count, fastperiod=-2147483648, slowperiod=-2147483648, matype=0)
Percentage Price Oscillator
-
pyalgotrade.talibext.indicator.ROC(ds, count, timeperiod=-2147483648)
Rate of change : ((price/prevPrice)-1)*100
-
pyalgotrade.talibext.indicator.ROCP(ds, count, timeperiod=-2147483648)
Rate of change Percentage: (price-prevPrice)/prevPrice
-
pyalgotrade.talibext.indicator.ROCR(ds, count, timeperiod=-2147483648)
Rate of change ratio: (price/prevPrice)
-
pyalgotrade.talibext.indicator.ROCR100(ds, count, timeperiod=-2147483648)
Rate of change ratio 100 scale: (price/prevPrice)*100
-
pyalgotrade.talibext.indicator.RSI(ds, count, timeperiod=-2147483648)
Relative Strength Index
-
pyalgotrade.talibext.indicator.SAR(barDs, count, acceleration=-4e+37, maximum=-4e+37)
Parabolic SAR
-
pyalgotrade.talibext.indicator.SAREXT(barDs, count, startvalue=-4e+37, offsetonreverse=-4e+37, accelerationinitlong=-4e+37, accelerationlong=-4e+37, accelerationmaxlong=-4e+37, accelerationinitshort=-4e+37, accelerationshort=-4e+37, accelerationmaxshort=-4e+37)
Parabolic SAR - Extended
-
pyalgotrade.talibext.indicator.SMA(ds, count, timeperiod=-2147483648)
Simple Moving Average
-
pyalgotrade.talibext.indicator.STDDEV(ds, count, timeperiod=-2147483648, nbdev=-4e+37)
Standard Deviation
-
pyalgotrade.talibext.indicator.STOCH(barDs, count, fastk_period=-2147483648, slowk_period=-2147483648, slowk_matype=0, slowd_period=-2147483648, slowd_matype=0)
Stochastic
-
pyalgotrade.talibext.indicator.STOCHF(barDs, count, fastk_period=-2147483648, fastd_period=-2147483648, fastd_matype=0)
Stochastic Fast
-
pyalgotrade.talibext.indicator.STOCHRSI(ds, count, timeperiod=-2147483648, fastk_period=-2147483648, fastd_period=-2147483648, fastd_matype=0)
Stochastic Relative Strength Index
-
pyalgotrade.talibext.indicator.SUM(ds, count, timeperiod=-2147483648)
Summation
-
pyalgotrade.talibext.indicator.T3(ds, count, timeperiod=-2147483648, vfactor=-4e+37)
Triple Exponential Moving Average (T3)
-
pyalgotrade.talibext.indicator.TEMA(ds, count, timeperiod=-2147483648)
Triple Exponential Moving Average
-
pyalgotrade.talibext.indicator.TRANGE(barDs, count)
True Range
-
pyalgotrade.talibext.indicator.TRIMA(ds, count, timeperiod=-2147483648)
Triangular Moving Average
-
pyalgotrade.talibext.indicator.TRIX(ds, count, timeperiod=-2147483648)
1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
-
pyalgotrade.talibext.indicator.TSF(ds, count, timeperiod=-2147483648)
Time Series Forecast
-
pyalgotrade.talibext.indicator.TYPPRICE(barDs, count)
Typical Price
-
pyalgotrade.talibext.indicator.ULTOSC(barDs, count, timeperiod1=-2147483648, timeperiod2=-2147483648, timeperiod3=-2147483648)
Ultimate Oscillator
-
pyalgotrade.talibext.indicator.VAR(ds, count, timeperiod=-2147483648, nbdev=-4e+37)
Variance
-
pyalgotrade.talibext.indicator.WCLPRICE(barDs, count)
Weighted Close Price
-
pyalgotrade.talibext.indicator.WILLR(barDs, count, timeperiod=-2147483648)
Williams’ %R
-
pyalgotrade.talibext.indicator.WMA(ds, count, timeperiod=-2147483648)
Weighted Moving Average