Technical Indicators for Financial Analysis
Technical is a Python library that provides a comprehensive collection of technical indicators and utility functions for financial time series analysis. It is designed to be easy to use and is a companion project primarily developed for Freqtrade, assisting in quantitative trading strategy development. The library is actively maintained with frequent releases, currently at version 1.6.0.
Common errors
-
ModuleNotFoundError: No module named 'technical'
cause The 'technical' package is not installed in the current Python environment or is not accessible via `sys.path`.fixEnsure the library is installed: `pip install technical`. If using a virtual environment, activate it first. If running from a custom script location, ensure the package is on `PYTHONPATH` or added to `sys.path`. -
/.../technical/indicators/overlap_studies.py:52: FutureWarning: zema is deprecated, use dema instead
cause You are using the deprecated `zema` function in your code. The developers corrected the underlying indicator's name to `dema` (Double Exponential Moving Average).fixUpdate your code to call `dema` instead of `zema`. For example, `df['dema'] = dema(df['close'], period=X)`. -
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'
cause This error often occurs when an indicator function receives input data containing `NaN` (Not a Number) values and attempts to perform arithmetic operations, or if the period for calculation is too short for the input data. Many technical indicators require a certain look-back period.fixEnsure your input DataFrame columns (e.g., 'close', 'high', 'low', 'volume') are cleaned of `NaN` values before passing them to indicator functions. Common methods include `df.fillna(method='ffill')` or `df.dropna()`. Also, check that the `period` parameter is valid for the length of your data. -
AttributeError: 'Series' object has no attribute 'some_indicator_name'
cause You are trying to call an indicator method directly on a pandas Series, but `technical` indicators are typically functions that take a Series/DataFrame as input. This might also happen if you are confusing `technical` with `pandas_ta` which uses DataFrame extensions.fixImport the indicator function from `technical.indicators` and pass the Series as an argument. For example, instead of `df['close'].sma(period=X)`, use `from technical.indicators import sma; df['sma'] = sma(df['close'], period=X)`.
Warnings
- breaking Python 3.10 support was dropped in version 1.5.4. Ensure your environment uses Python 3.11 or newer for compatibility.
- deprecated The `zema` indicator is deprecated and will issue a `FutureWarning`. Its implementation was found to be functionally equivalent to `dema` (Double Exponential Moving Average).
- gotcha Older versions of `technical` (prior to 1.5.4) might produce pandas `FutureWarning` messages due to API changes in pandas. Version 1.5.4 and later include 'Proper support for latest pandas versions _without deprecation warnings_'.
- breaking The `tv_hma()` and `tv_wma()` functions were updated in version 1.5.0 to consistently return pandas Series objects, rather than potentially other types. This might affect code expecting different return types.
- gotcha Installing the underlying TA-Lib C library can be complex, especially on Windows or certain Linux distributions. While `technical` aims to wrap it, errors like 'Cannot find ta-lib library' during installation are common.
Install
-
pip install technical
Imports
- accumulation_distribution
import technical.accumulation_distribution
from technical.indicators import accumulation_distribution
- resample_to_interval
from technical.util import resample_to_interval
Quickstart
import pandas as pd
from technical.indicators import sma
# Create a sample DataFrame with 'close' prices
df = pd.DataFrame({
'close': [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
})
# Calculate Simple Moving Average (SMA) with a period of 3
df['sma_3'] = sma(df['close'], period=3)
print(df)