1 Star 1 Fork 1

triobox/pandas-ta

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Technical Analysis Library in Python 3.7

Example Chart

Technical Analysis (TA) is an easy to use library that is built upon Python's Pandas library with more than 80 Indicators. These indicators are comminly used for financial time series datasets with columns or labels similar to: datetime, open, high, low, close, volume, et al. Many commonly used indicators are included, such as: Moving Average Convergence Divergence (MACD), Hull Exponential Moving Average (HMA), Bollinger Bands (BBANDS), On-Balance Volume (OBV), Aroon Oscillator (AROON) and more.

This version contains both the orignal code branch as well as a newly refactored branch with the option to use Pandas DataFrame Extension mode. All the indicators return a named Series or a DataFrame in uppercase underscore parameter format. For example, MACD(fast=12, slow=26, signal=9) will return a DataFrame with columns: ['MACD_12_26_9', 'MACDH_12_26_9', 'MACDS_12_26_9'].

Features

  • Over 80 indicators.
  • Example Jupyter Notebook under the examples directory.
  • Abbreviated Indicator names as listed below.
  • Extended Pandas DataFrame as 'ta'. See examples below.
  • Parameter names are more consistent.
  • Refactoring indicators into categories similar to TA-lib.

Recent Changes

  • Updated the example notebook.
  • Trend Return, ta.trend_return(), has a proper index. More consistent with the module.
  • Added an 'adjusted' property to the 'ta' extension so you can override the default 'close' column. By default, df.ta.adjusted = None. If the adjusted close column is 'adj_close' for example, then set df.ta.adjusted = 'adj_close'.

What is a Pandas DataFrame Extension?

A Pandas DataFrame Extension, extends a DataFrame allowing one to add more functionality and features to Pandas to suit your needs. As such, it is now easier to run Technical Analysis on existing Financial Time Series without leaving the current DataFrame. This extension by default returns the Indicator result or, inclusively, it can append the result to the existing DataFrame by including the parameter 'append=True' in the method call. See examples below.

Getting Started and Examples

Installation (python 3)

$ pip install pandas_ta

Latest Version

$ pip install -U git+https://github.com/twopirllc/pandas-ta

Quick Start using the DataFrame Extension

import pandas as pd
import pandas_ta as ta

# Load data
df = pd.read_csv('symbol.csv', sep=',')

# Calculate Returns and append to the df DataFrame
df.ta.log_return(cumulative=True, append=True)
df.ta.percent_return(cumulative=True, append=True)

# New Columns with results
df.columns

# Take a peek
df.tail()

# vv Continue Post Processing vv

Module and Indicator Help

import pandas as pd
import pandas_ta as ta

# Help about this, 'ta', extension
help(pd.DataFrame().ta)

# List of all indicators
pd.DataFrame().ta.indicators()

# Help about the log_return indicator
help(ta.log_return)

# Help about the log_return indicator as a DataFrame Extension
help(pd.DataFrame().ta.log_return)

New ta DataFrame Property: adjusted

# Set ta to default to an adjusted column, 'adj_close', overriding default 'close'
df.ta.adjusted = 'adj_close'
df.ta.sma(length=10, append=True)

# To reset back to 'close', set adjusted back to None
df.ta.adjusted = None

Technical Analysis Indicators (by Category)

Momentum (21)

  • Awesome Oscillator: ao
  • Absolute Price Oscillator: apo
  • Balance of Power: bop
  • Commodity Channel Index: cci
  • Center of Gravity: cg
  • Chande Momentum Oscillator: cmo
  • Coppock Curve: coppock
  • Fisher Transform: fisher
  • KST Oscillator: kst
  • Moving Average Convergence Divergence: macd
  • Momentum: mom
  • Percentage Price Oscillator: ppo
  • Rate of Change: roc
  • Relative Strength Index: rsi
  • Relative Vigor Index: rvi
  • Slope: slope
  • Stochastic Oscillator: stoch
  • Trix: trix
  • True strength index: tsi
  • Ultimate Oscillator: uo
  • Williams %R: willr
Moving Average Convergence Divergence (MACD)
Example MACD

Overlap (24)

  • Double Exponential Moving Average: dema
  • Exponential Moving Average: ema
  • Fibonacci's Weighted Moving Average: fwma
  • High-Low Average: hl2
  • High-Low-Close Average: hlc3
    • Commonly known as 'Typical Price' in Technical Analysis literature
  • Hull Exponential Moving Average: hma
  • Kaufman's Adaptive Moving Average: kama
  • Ichimoku Kinkō Hyō: ichimoku
    • Use: help(ta.ichimoku). Returns two DataFrames.
  • Linear Regression: linreg
  • Midpoint: midpoint
  • Midprice: midprice
  • Open-High-Low-Close Average: ohlc4
  • Pascal's Weighted Moving Average: pwma
  • William's Moving Average: rma
  • Simple Moving Average: sma
  • Sine Weighted Moving Average: sinwma
  • Symmetric Weighted Moving Average: swma
  • T3 Moving Average: t3
  • Triple Exponential Moving Average: tema
  • Triangular Moving Average: trima
  • Volume Weighted Average Price: vwap
  • Volume Weighted Moving Average: vwma
  • Weighted Moving Average: wma
  • Zero Lag Moving Average: zlma
Simple Moving Averages (SMA) and Bollinger Bands (BBANDS)
Example Chart

Performance (3)

Use parameter: cumulative=True for cumulative results.

  • Log Return: log_return
  • Percent Return: percent_return
  • Trend Return: trend_return
Percent Return (Cumulative) with Simple Moving Average (SMA)
Example Cumulative Percent Return

Statistics (8)

  • Kurtosis: kurtosis
  • Mean Absolute Deviation: mad
  • Median: median
  • Quantile: quantile
  • Skew: skew
  • Standard Deviation: stdev
  • Variance: variance
  • Z Score: zscore
Z Score
Example Z Score

Trend (11)

  • Average Directional Movement Index: adx
  • Archer Moving Averages Trends: amat
  • Aroon Oscillator: aroon
  • Decreasing: decreasing
  • Detrended Price Oscillator: dpo
  • Increasing: increasing
  • Linear Decay: linear_decay
  • Long Run: long_run
  • Q Stick: qstick
  • Short Run: short_run
  • Vortex: vortex
Average Directional Movement Index (ADX)
Example ADX

Utility (1)

  • Cross: cross

Volatility (8)

  • Acceleration Bands: accbands
  • Average True Range: atr
  • Bollinger Bands: bbands
  • Donchian Channel: donchian
  • Keltner Channel: kc
  • Mass Index: massi
  • Normalized Average True Range: natr
  • True Range: true_range
Average True Range (ATR)
Example ATR

Volume (13)

  • Accumulation/Distribution Index: ad
  • Accumulation/Distribution Oscillator: adosc
  • Archer On-Balance Volume: aobv
  • Chaikin Money Flow: cmf
  • Elder's Force Index: efi
  • Ease of Movement: eom
  • Money Flow Index: mfi
  • Negative Volume Index: nvi
  • On-Balance Volume: obv
  • Positive Volume Index: pvi
  • Price-Volume: pvol
  • Price Volume Trend: pvt
  • Volume Profile: vp
On-Balance Volume (OBV)
Example OBV

Inspiration

Please leave any comments, feedback, or suggestions.

The MIT License (MIT) Copyright (c) Microsoft Corporation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

An easy to use Python 3 Pandas Extension with 80+Technical Analysis Indicators 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/triobox/pandas-ta.git
git@gitee.com:triobox/pandas-ta.git
triobox
pandas-ta
pandas-ta
master

搜索帮助