Skip to content

Indicators

Supports TA-Lib and pandas_ta with hundreds of technical indicators. Calculate thousands of stocks over long time periods with a single line, suitable for individual stock analysis and machine learning.

Installing TA-Lib

Before computing indicators, you need to install TA-Lib:

  • Local environment: Refer to the official installation guide, which supports Windows, MacOS, and Linux.
  • Google Colab: Simply run the following command:
    !pip install ta-lib
    

For more parameters and functions, see the TA-Lib official documentation.

Computing RSI for All Stocks

Use data.indicator() to compute RSI (timeperiod=14):

from finlab import data
data.indicator('RSI', timeperiod=14)

The first 14 days may be NaN due to insufficient data.

Technical Indicators with Two Time Series (Stochastic Oscillator KD)

Use data.indicator('STOCH') to compute the Stochastic Oscillator (KD values), which returns two DataFrames (K and D).

from finlab import data
k, d = data.indicator('STOCH')
k

Stock Screening Using KD Values

List stocks where K > D on the most recent day:

(k > d).iloc[-1]
0015    False
0050     True
0051    False
0052     True
0053     True
        ...
9951     True
9955    False
9958    False
9960     True
9962     True
Name: 2021-07-13 00:00:00, Length: 2269, dtype: bool
In the above syntax, (k > d) returns a DataFrame where each element is a boolean indicating whether the corresponding stock's K value is greater than its D value. .iloc[-1] selects the last row, which is the most recent day's data. The result is a boolean Series where True indicates K > D for that stock.

Computing pandas_ta Technical Indicators

pandas_ta can also compute many technical indicators; see the official documentation for installation and available indicators.

pip install pandas-ta
In FinLab, you can use it directly through data.indicator(). For example, to compute supertrend:

from finlab import data

values = data.indicator('supertrend')
If TA-Lib does not have the corresponding function, pandas_ta will be used instead (computation may be slower).