$npx -y skills add agiprolabs/claude-trading-skills --skill ta-libC-optimized technical analysis with 150+ functions and 61 candlestick pattern recognition functions via TA-Lib
| 1 | # ta-lib — C-Optimized Technical Analysis |
| 2 | |
| 3 | TA-Lib (Technical Analysis Library) is a C library with a Python wrapper providing 150+ technical analysis functions and 61 candlestick pattern recognition functions. It is the industry standard for performance-critical indicator computation, used in production trading systems where pandas-ta or pure-Python alternatives are too slow. |
| 4 | |
| 5 | ## What TA-Lib Is |
| 6 | |
| 7 | TA-Lib was originally written in C for financial market data analysis. The Python wrapper (`TA-Lib` on PyPI, imported as `talib`) provides: |
| 8 | |
| 9 | - **150+ indicator functions** across overlap, momentum, volume, volatility, cycle, and math categories |
| 10 | - **61 candlestick pattern recognition functions** — the most comprehensive pattern library available |
| 11 | - **C-speed computation** — 10-100x faster than pure-Python equivalents on large datasets |
| 12 | - **Two APIs**: a function API (pass arrays directly) and an abstract API (pass dict of arrays) |
| 13 | - **NumPy native** — all inputs and outputs are NumPy arrays |
| 14 | |
| 15 | ## Installation |
| 16 | |
| 17 | TA-Lib requires the underlying C library to be installed first: |
| 18 | |
| 19 | ```bash |
| 20 | # macOS |
| 21 | brew install ta-lib |
| 22 | uv pip install TA-Lib numpy pandas |
| 23 | |
| 24 | # Ubuntu/Debian |
| 25 | sudo apt-get install -y ta-lib |
| 26 | uv pip install TA-Lib numpy pandas |
| 27 | |
| 28 | # From source (any platform) |
| 29 | wget https://github.com/ta-lib/ta-lib/releases/download/v0.6.4/ta-lib-0.6.4-src.tar.gz |
| 30 | tar -xzf ta-lib-0.6.4-src.tar.gz |
| 31 | cd ta-lib-0.6.4 |
| 32 | ./configure --prefix=/usr/local |
| 33 | make && sudo make install |
| 34 | uv pip install TA-Lib numpy pandas |
| 35 | ``` |
| 36 | |
| 37 | If the C library is not installed, `import talib` will fail with an `ImportError`. The scripts in this skill include fallback logic for environments without TA-Lib installed. |
| 38 | |
| 39 | ## When to Use TA-Lib vs pandas-ta |
| 40 | |
| 41 | | Criterion | TA-Lib | pandas-ta | |
| 42 | |---|---|---| |
| 43 | | Speed | C-optimized, 10-100x faster | Pure Python, slower on large data | |
| 44 | | Candlestick patterns | 61 built-in patterns | Limited pattern support | |
| 45 | | Installation | Requires C library | `pip install` only | |
| 46 | | API style | NumPy arrays | DataFrame `.ta` accessor | |
| 47 | | Indicator count | 150+ | 130+ | |
| 48 | | Streaming | Single-value update possible | Recompute entire series | |
| 49 | | Dependencies | C lib + numpy | pandas only | |
| 50 | |
| 51 | **Use TA-Lib when:** |
| 52 | - Processing millions of bars or running backtests at scale |
| 53 | - You need candlestick pattern recognition (TA-Lib is unmatched here) |
| 54 | - You are building a production pipeline where latency matters |
| 55 | - You need cycle indicators (Hilbert Transform family) |
| 56 | |
| 57 | **Use pandas-ta when:** |
| 58 | - You want DataFrame-native convenience |
| 59 | - Installation simplicity matters (no C dependency) |
| 60 | - You need indicators not in TA-Lib (pandas-ta has some extras) |
| 61 | |
| 62 | ## Quick Start |
| 63 | |
| 64 | ```python |
| 65 | import numpy as np |
| 66 | import talib |
| 67 | |
| 68 | # Create sample data |
| 69 | close = np.random.randn(100).cumsum() + 50 |
| 70 | high = close + np.abs(np.random.randn(100)) |
| 71 | low = close - np.abs(np.random.randn(100)) |
| 72 | open_ = close + np.random.randn(100) * 0.5 |
| 73 | volume = np.random.randint(1000, 10000, 100).astype(float) |
| 74 | |
| 75 | # Function API — pass arrays directly |
| 76 | rsi = talib.RSI(close, timeperiod=14) |
| 77 | macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) |
| 78 | upper, middle, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2) |
| 79 | atr = talib.ATR(high, low, close, timeperiod=14) |
| 80 | |
| 81 | # Candlestick patterns — return +100 (bullish), -100 (bearish), or 0 |
| 82 | doji = talib.CDLDOJI(open_, high, low, close) |
| 83 | hammer = talib.CDLHAMMER(open_, high, low, close) |
| 84 | engulfing = talib.CDLENGULFING(open_, high, low, close) |
| 85 | ``` |
| 86 | |
| 87 | ## Function API vs Abstract API |
| 88 | |
| 89 | ### Function API (Recommended) |
| 90 | |
| 91 | Call functions directly with NumPy arrays: |
| 92 | |
| 93 | ```python |
| 94 | import talib |
| 95 | |
| 96 | rsi = talib.RSI(close, timeperiod=14) |
| 97 | sma = talib.SMA(close, timeperiod=20) |
| 98 | upper, mid, lower = talib.BBANDS(close) |
| 99 | ``` |
| 100 | |
| 101 | ### Abstract API |
| 102 | |
| 103 | Pass a dictionary of arrays and get results by name: |
| 104 | |
| 105 | ```python |
| 106 | from talib import abstract |
| 107 | |
| 108 | inputs = {"open": open_, "high": high, "low": low, "close": close, "volume": volume} |
| 109 | |
| 110 | # Call by function name |
| 111 | rsi = abstract.RSI(inputs, timeperiod=14) |
| 112 | macd = abstract.MACD(inputs) # returns (macd, signal, hist) |
| 113 | ``` |
| 114 | |
| 115 | The abstract API is useful for dynamic indicator selection (e.g., looping over a list of indicator names). |
| 116 | |
| 117 | ## Function Groups |
| 118 | |
| 119 | TA-Lib organizes functions into these groups: |
| 120 | |
| 121 | ### Overlap Studies |
| 122 | Moving averages and envelope indicators that overlay price charts. |
| 123 | |
| 124 | ```python |
| 125 | sma = talib.SMA(close, timeperiod=20) |
| 126 | ema = talib.EMA(close, timeperiod=12) |
| 127 | upper, mid, lower = talib.BBANDS(close, timeperiod=20, nbdevup=2, nbdevdn=2) |
| 128 | sar = talib.SAR(high, low, acceleration=0.02, maximum=0.2) |
| 129 | mama, fama = talib.MAMA(close, fastlimit=0.5, slowlimit=0.05) |
| 130 | ``` |
| 131 | |
| 132 | ### Momentum Indicators |
| 133 | Oscillators and trend-strength measures. |
| 134 | |
| 135 | ```python |
| 136 | rsi = talib.RSI(close, timeperiod=14) |
| 137 | macd, signal, hist = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) |
| 138 | slowk, slowd = talib.STOCH(high, low, close) |
| 139 | cci = talib.CCI(high, |