TA-Lib is a Python wrapper for the widely-used TA-Lib C library, designed for technical analysis of financial market data. It provides over 150 indicators and candlestick pattern recognition functions, optimized for performance using Cython and NumPy. The current Python wrapper version is 0.6.8, and it maintains compatibility branches for different NumPy and underlying C TA-Lib versions.
pip install TA-LibVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates calculating common technical indicators like Simple Moving Average (SMA) and Relative Strength Index (RSI) using `ta-lib` with both NumPy arrays and Pandas Series as input. Note that `ta-lib` functions return `NaN` for the initial 'lookback' periods where insufficient data is available to compute the indicator.
Follow the platform-specific instructions for installing the TA-Lib C library (e.g., Homebrew for macOS, build from source for Linux, Visual Studio compilation for Windows) before running `pip install TA-Lib`.
Check the `ta-lib-python` GitHub README or PyPI page for exact compatibility matrix. Consider using `conda` (`conda install -c conda-forge ta-lib libta-lib`) as it often handles these dependencies more smoothly.
Use a compatible version of the Python `ta-lib` wrapper (e.g., `0.6.x` for the C library `0.6.x`) or ensure your C library build and linking paths are correctly configured for the Python wrapper's expectations.
Always check the output arrays for `NaN` values, especially at the beginning. Use methods like `dropna()` from Pandas if working with DataFrames, or slice your NumPy arrays to exclude the initial `NaN`s.
Ensure you have the 'Desktop development with C++' workload installed in Visual Studio. For easier installation, many users resort to downloading pre-compiled `.whl` files for their specific Python version and architecture from unofficial sources (e.g., Gohlke's Python wheels, though availability varies) or using Conda.
Download and install "Microsoft C++ Build Tools" (specifically the "Desktop development with C++" workload) from the Visual Studio website, then retry `pip install ta-lib`.
Download and install the C TA-Lib library (e.g., `ta-lib-0.4.0-msvc.zip` for Windows or compile from source on Linux/macOS), then set `TA_INCLUDE_PATH` and `TA_LIBRARY_PATH` environment variables to point to the installed library directories before running `pip install ta-lib`.
Ensure all input series (e.g., `open`, `high`, `low`, `close`) are clean pandas Series or NumPy arrays of float type, with no `NaN`s, and contain sufficient data points before passing them to `ta-lib` functions. Use `dropna()` or `fillna()` for data cleaning.
Explicitly make the input NumPy array or pandas Series values C-contiguous by calling `.copy(order='C')` before passing them to the `ta-lib` function. Example: `talib.SMA(data['close'].values.copy(order='C'))`.