Python 技术分析库

使用 Pandas 和 Numpy 的技术分析库。「Technical Analysis Library using Pandas and Numpy」

Github stars Tracking Chart

CircleCI
Documentation Status
Coverage Status
Code style: black
Linter: Prospector
PyPI
PyPI - Downloads
Donate PayPal

Technical Analysis Library in Python

It is a Technical Analysis library useful to do feature engineering from financial time series datasets (Open, Close, High, Low, Volume). It is built on Pandas and Numpy.

Bollinger Bands graph example

The library has implemented 43 indicators:

Volume

ID Name Class defs
1 Money Flow Index (MFI) MFIIndicator money_flow_index
2 Accumulation/Distribution Index (ADI) AccDistIndexIndicator acc_dist_index
3 On-Balance Volume (OBV) OnBalanceVolumeIndicator on_balance_volume
4 Chaikin Money Flow (CMF) ChaikinMoneyFlowIndicator chaikin_money_flow
5 Force Index (FI) ForceIndexIndicator force_index
6 Ease of Movement (EoM, EMV) EaseOfMovementIndicator ease_of_movementsma_ease_of_movement
7 Volume-price Trend (VPT) VolumePriceTrendIndicator volume_price_trend
8 Negative Volume Index (NVI) NegativeVolumeIndexIndicator negative_volume_index
9 Volume Weighted Average Price (VWAP) VolumeWeightedAveragePrice volume_weighted_average_price

Volatility

ID Name Class defs
10 Average True Range (ATR) AverageTrueRange average_true_range
11 Bollinger Bands (BB) BollingerBands bollinger_hbandbollinger_hband_indicatorbollinger_lbandbollinger_lband_indicatorbollinger_mavgbollinger_pbandbollinger_wband
12 Keltner Channel (KC) KeltnerChannel keltner_channel_hbandkeltner_channel_hband_indicatorkeltner_channel_lbandkeltner_channel_lband_indicatorkeltner_channel_mbandkeltner_channel_pbandkeltner_channel_wband
13 Donchian Channel (DC) DonchianChannel donchian_channel_hbanddonchian_channel_lbanddonchian_channel_mbandonchian_channel_pbanddonchian_channel_wband
14 Ulcer Index (UI) UlcerIndex ulcer_index

Trend

ID Name Class defs
15 Simple Moving Average (SMA) SMAIndicator sma_indicator
16 Exponential Moving Average (EMA) EMAIndicator ema_indicator
17 Weighted Moving Average (WMA) WMAIndicator wma_indicator
18 Moving Average Convergence Divergence (MACD) MACD macd macd_diffmacd_signal
19 Average Directional Movement Index (ADX) ADXIndicator adxadx_negadx_pos
20 Vortex Indicator (VI) VortexIndicator vortex_indicator_neg vortex_indicator_pos
21 Trix (TRIX) TRIXIndicator trix
22 Mass Index (MI) MassIndex mass_index
23 Commodity Channel Index (CCI) CCIIndicator cci
24 Detrended Price Oscillator (DPO) DPOIndicator dpo
25 KST Oscillator (KST) KSTIndicator kstkst_sig
26 Ichimoku Kinkō Hyō (Ichimoku) IchimokuIndicator ichimoku_aichimoku_bichimoku_base_lineichimoku_conversion_line
27 Parabolic Stop And Reverse (Parabolic SAR) PSARIndicator psar_down psar_down_indicatorpsar_uppsar_up_indicator
28 Schaff Trend Cycle (STC) STCIndicator stc
29 Aroon Indicator AroonIndicator aroon_downaroon_up

Momentum

ID Name Class defs
30 Relative Strength Index (RSI) RSIIndicator rsi
31 Stochastic RSI (SRSI) StochRSIIndicator stochrsistochrsi_dstochrsi_k
32 True strength index (TSI) TSIIndicator tsi
33 Ultimate Oscillator (UO) UltimateOscillator ultimate_oscillator
34 Stochastic Oscillator (SR) StochasticOscillator stochstoch_signal
35 Williams %R (WR) WilliamsRIndicator williams_r
36 Awesome Oscillator (AO) AwesomeOscillatorIndicator awesome_oscillator
37 Kaufman's Adaptive Moving Average (KAMA) KAMAIndicator kama
38 Rate of Change (ROC) ROCIndicator roc
39 Percentage Price Oscillator (PPO) PercentagePriceOscillator ppoppo_histppo_signal
40 Percentage Volume Oscillator (PVO) PercentageVolumeOscillator pvopvo_histpvo_signal

Others

ID Name Class defs
41 Daily Return (DR) DailyReturnIndicator daily_return
42 Daily Log Return (DLR) DailyLogReturnIndicator daily_log_return
43 Cumulative Return (CR) CumulativeReturnIndicator cumulative_return

Documentation

https://technical-analysis-library-in-python.readthedocs.io/en/latest/

Motivation to use

How to use (Python 3)

$ pip install --upgrade ta

To use this library you should have a financial time series dataset including Timestamp, Open, High, Low, Close and Volume columns.

You should clean or fill NaN values in your dataset before add technical analysis features.

You can get code examples in examples_to_use folder.

You can visualize the features in this notebook.

Example adding all features

import pandas as pd
from ta import add_all_ta_features
from ta.utils import dropna


# Load datas
df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

# Clean NaN values
df = dropna(df)

# Add all ta features
df = add_all_ta_features(
    df, open="Open", high="High", low="Low", close="Close", volume="Volume_BTC")

Example adding particular feature

import pandas as pd
from ta.utils import dropna
from ta.volatility import BollingerBands


# Load datas
df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

# Clean NaN values
df = dropna(df)

# Initialize Bollinger Bands Indicator
indicator_bb = BollingerBands(close=df["Close"], window=20, window_dev=2)

# Add Bollinger Bands features
df['bb_bbm'] = indicator_bb.bollinger_mavg()
df['bb_bbh'] = indicator_bb.bollinger_hband()
df['bb_bbl'] = indicator_bb.bollinger_lband()

# Add Bollinger Band high indicator
df['bb_bbhi'] = indicator_bb.bollinger_hband_indicator()

# Add Bollinger Band low indicator
df['bb_bbli'] = indicator_bb.bollinger_lband_indicator()

# Add Width Size Bollinger Bands
df['bb_bbw'] = indicator_bb.bollinger_wband()

# Add Percentage Bollinger Bands
df['bb_bbp'] = indicator_bb.bollinger_pband()

Deploy and develop (for developers)

$ git clone https://github.com/bukosabino/ta.git
$ cd ta
$ pip install -r requirements-play.txt
$ make test

Sponsor

Logo OpenSistemas

Thank you to OpenSistemas! It is because of your contribution that I am able to continue the development of this open source library.

Based on

In Progress

  • Automated tests for all the indicators.

TODO

Changelog

Check the changelog of project.

Donation

If you think ta library help you, please consider buying me a coffee.

Credits

Developed by Darío López Padial (aka Bukosabino) and other contributors.

Please, let me know about any comment or feedback.

Also, I am a software engineer freelance focused on Data Science using Python tools such as Pandas, Scikit-Learn, Backtrader, Zipline or Catalyst. Don't hesitate to contact me if you need to develop something related with this library, Python, Technical Analysis, AlgoTrading, Machine Learning, etc.

Overview

Name With Ownerbukosabino/ta
Primary LanguageJupyter Notebook
Program languagePython (Language Count: 3)
Platform
License:MIT License
Release Count65
Last Release Name0.11.0 (Posted on 2023-11-02 14:52:54)
First Release Name0.1 (Posted on 2018-04-06 13:41:40)
Created At2018-01-02 18:08:48
Pushed At2024-03-20 17:31:08
Last Commit At2023-11-02 14:49:44
Stargazers Count4.1k
Watchers Count150
Fork Count844
Commits Count662
Has Issues Enabled
Issues Count214
Issue Open Count110
Pull Requests Count84
Pull Requests Open Count23
Pull Requests Close Count20
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private
To the top