or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-ta-lib

Python wrapper for TA-LIB providing 175+ technical analysis indicators for financial market data

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/ta-lib@0.6.x

To install, run

npx @tessl/cli install tessl/pypi-ta-lib@0.6.0

0

# TA-Lib

1

2

TA-Lib is a comprehensive Python wrapper for the TA-LIB C library, providing 175+ technical analysis indicators for financial market data analysis. This library is widely used by trading software developers requiring professional-grade technical analysis of financial data, offering efficient computations that are 2-4 times faster than alternative implementations.

3

4

## Package Information

5

6

- **Package Name**: TA-Lib

7

- **Language**: Python

8

- **Installation**: `pip install TA-Lib`

9

- **Dependencies**: numpy (required), pandas (optional), polars (optional)

10

11

## Core Imports

12

13

```python

14

import talib

15

```

16

17

For abstract interface:

18

19

```python

20

import talib.abstract

21

from talib.abstract import Function

22

```

23

24

For streaming API:

25

26

```python

27

import talib.stream

28

from talib import stream

29

```

30

31

## Basic Usage

32

33

```python

34

import talib

35

import numpy as np

36

37

# Create sample OHLC data

38

close = np.random.random(100)

39

high = np.random.random(100)

40

low = np.random.random(100)

41

open_prices = np.random.random(100)

42

43

# Calculate simple moving average

44

sma = talib.SMA(close, timeperiod=30)

45

46

# Calculate RSI

47

rsi = talib.RSI(close, timeperiod=14)

48

49

# Calculate Bollinger Bands

50

upper, middle, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2)

51

52

# Calculate MACD

53

macd, macdsignal, macdhist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)

54

```

55

56

## Architecture

57

58

TA-Lib provides three distinct APIs for different use cases:

59

60

- **Function API**: Direct function calls for batch processing of arrays

61

- **Abstract API**: Flexible interface supporting DataFrames and named inputs

62

- **Streaming API**: Real-time processing returning only the latest value

63

64

All functions support numpy arrays as primary input, with automatic conversion from pandas Series and polars Series. The library handles initialization and cleanup automatically, with robust NaN propagation and lookback period management.

65

66

## Capabilities

67

68

### Overlap Studies

69

70

Trend-following indicators and moving averages that smooth price data to identify trends and provide support/resistance levels. Includes moving averages, Bollinger Bands, and trend line indicators.

71

72

```python { .api }

73

def SMA(real, timeperiod=30): ...

74

def EMA(real, timeperiod=30): ...

75

def BBANDS(real, timeperiod=5, nbdevup=2, nbdevdn=2, matype=MA_Type.SMA): ...

76

def KAMA(real, timeperiod=30): ...

77

def SAR(high, low, acceleration=0, maximum=0): ...

78

```

79

80

[Overlap Studies](./overlap-studies.md)

81

82

### Momentum Indicators

83

84

Oscillators and momentum-based indicators that measure the rate of price change and help identify overbought/oversold conditions and potential reversal points.

85

86

```python { .api }

87

def RSI(real, timeperiod=14): ...

88

def MACD(real, fastperiod=12, slowperiod=26, signalperiod=9): ...

89

def STOCH(high, low, close, fastk_period=5, slowk_period=3, slowk_matype=MA_Type.SMA, slowd_period=3, slowd_matype=MA_Type.SMA): ...

90

def ADX(high, low, close, timeperiod=14): ...

91

def CCI(high, low, close, timeperiod=14): ...

92

def IMI(open, close, timeperiod=14): ...

93

```

94

95

[Momentum Indicators](./momentum-indicators.md)

96

97

### Volume Indicators

98

99

Indicators that analyze the relationship between price movements and trading volume to confirm trends and identify potential reversals.

100

101

```python { .api }

102

def AD(high, low, close, volume): ...

103

def OBV(close, volume): ...

104

def ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10): ...

105

```

106

107

[Volume Indicators](./volume-indicators.md)

108

109

### Volatility Indicators

110

111

Measures of price volatility and range to assess market conditions and potential breakout scenarios.

112

113

```python { .api }

114

def ATR(high, low, close, timeperiod=14): ...

115

def NATR(high, low, close, timeperiod=14): ...

116

def TRANGE(high, low, close): ...

117

def ACCBANDS(high, low, close, timeperiod=20): ...

118

```

119

120

[Volatility Indicators](./volatility-indicators.md)

121

122

### Pattern Recognition

123

124

Candlestick pattern recognition functions that identify traditional Japanese candlestick patterns for technical analysis and trading signals.

125

126

```python { .api }

127

def CDLDOJI(open, high, low, close): ...

128

def CDLHAMMER(open, high, low, close): ...

129

def CDLENGULFING(open, high, low, close): ...

130

def CDLMORNINGSTAR(open, high, low, close, penetration=0): ...

131

def CDL3BLACKCROWS(open, high, low, close): ...

132

```

133

134

[Pattern Recognition](./pattern-recognition.md)

135

136

### Price Transform

137

138

Functions that transform OHLC data into standardized price representations for further analysis.

139

140

```python { .api }

141

def AVGPRICE(open, high, low, close): ...

142

def MEDPRICE(high, low): ...

143

def TYPPRICE(high, low, close): ...

144

def WCLPRICE(high, low, close): ...

145

```

146

147

[Price Transform](./price-transform.md)

148

149

### Cycle Indicators

150

151

Hilbert Transform-based indicators for cycle analysis and trend vs cycle mode determination.

152

153

```python { .api }

154

def HT_DCPERIOD(real): ...

155

def HT_SINE(real): ...

156

def HT_TRENDMODE(real): ...

157

def HT_PHASOR(real): ...

158

def HT_DCPHASE(real): ...

159

```

160

161

[Cycle Indicators](./cycle-indicators.md)

162

163

### Statistical Functions

164

165

Statistical analysis functions for correlation, regression, and statistical measures of price data.

166

167

```python { .api }

168

def BETA(real0, real1, timeperiod=5): ...

169

def CORREL(real0, real1, timeperiod=30): ...

170

def LINEARREG(real, timeperiod=14): ...

171

def STDDEV(real, timeperiod=5, nbdev=1): ...

172

def VAR(real, timeperiod=5, nbdev=1): ...

173

def AVGDEV(real, timeperiod=14): ...

174

```

175

176

[Statistical Functions](./statistical-functions.md)

177

178

### Math Operations

179

180

Mathematical transformation and operator functions for array manipulation and calculations.

181

182

```python { .api }

183

def ADD(real0, real1): ...

184

def SUM(real, timeperiod=30): ...

185

def MAX(real, timeperiod=30): ...

186

def MIN(real, timeperiod=30): ...

187

def SQRT(real): ...

188

def SIN(real): ...

189

def LOG10(real): ...

190

```

191

192

[Math Operations](./math-operations.md)

193

194

### Abstract and Streaming APIs

195

196

Alternative interfaces providing flexible DataFrame support and real-time processing capabilities.

197

198

```python { .api }

199

# Abstract API

200

class Function:

201

def __init__(self, function_name, *args, **kwargs): ...

202

203

# Streaming functions return single values

204

def stream_SMA(real, timeperiod=30): ... # Returns latest SMA value only

205

```

206

207

[Abstract and Streaming APIs](./abstract-streaming.md)

208

209

## Common Types

210

211

```python { .api }

212

from enum import Enum

213

from typing import Tuple

214

import numpy as np

215

216

class MA_Type(Enum):

217

"""Moving Average Types"""

218

SMA = 0 # Simple Moving Average

219

EMA = 1 # Exponential Moving Average

220

WMA = 2 # Weighted Moving Average

221

DEMA = 3 # Double Exponential Moving Average

222

TEMA = 4 # Triple Exponential Moving Average

223

TRIMA = 5 # Triangular Moving Average

224

KAMA = 6 # Kaufman Adaptive Moving Average

225

MAMA = 7 # MESA Adaptive Moving Average

226

T3 = 8 # Triple Exponential Moving Average (T3)

227

228

# Type aliases

229

NDArray = np.ndarray

230

PriceArray = np.ndarray[np.float64]

231

IntArray = np.ndarray[np.int32]

232

```

233

234

## Utility Functions

235

236

```python { .api }

237

def get_functions() -> list[str]:

238

"""Returns a list of all supported TA-Lib function names"""

239

240

def get_function_groups() -> dict[str, list[str]]:

241

"""Returns functions organized by group (e.g., 'Overlap Studies', 'Momentum Indicators')"""

242

243

def set_unstable_period(func_id: int, period: int) -> None:

244

"""Set unstable period for a function"""

245

246

def get_unstable_period(func_id: int) -> int:

247

"""Get unstable period for a function"""

248

249

def set_compatibility(value: int) -> None:

250

"""Set compatibility mode"""

251

252

def get_compatibility() -> int:

253

"""Get compatibility mode"""

254

```