[Python] finta 를 사용하여 RSI 값을 가져오는 방법

2023. 12. 24. 22:41카테고리 없음

대부분 파이썬 데이터를 활용하여 내용을 가져오고, 그 데이터를 기반으로 RSI / CCI / MA 등을 확인할 수 있다. 

그 가져오기 위한 일부 라이블러리들 중에서 아래의 라이블러리가 편하고 사용하기 쉬웠다.

사용법 및 설치 방법도 간단하여, 지금까지 사용해고 있는 것 같다. 

 

설치방법
윈도우 pip install finta
리눅스 pip3 install finta

 

사용방법
# finta를 사용하기 위한 선언
from finta import TA

# 한국투자증권을 사용하거나 pykrx를 사용하여 해당 dataframe 정보를 가져온다. 
self.df = self.KIS_KR.GetOhlcvA(ticker, df_cnt)

# finta를 사용하여 해당 RSI 정보를 가져온다. 
# 기본적으로 14를 사용하지만 일부 변경이 필요하여 8로 변경하였다. 
RSI = TA.RSI(self.df, 8)
RSI_1 = RSI.iloc[-1]
RSI_2 = RSI.iloc[-2]
RSI_3 = RSI.iloc[-3]
RSI_4 = RSI.iloc[-4]
해당정보를 가져왔다. (아래 이미지)

 

간단하게 finta 를 통하여 해당 내용을 확인할 수 있도록 반영하고 DB에 저장하여 해당 사항의 추세를 확인할 수 있다. 

해당 라이블러리는 아래에서 확인할 수 있다. 

 

https://pypi.org/project/finta/

 

finta

Common financial technical indicators implemented in Pandas.

pypi.org

 

* Simple Moving Average 'SMA'
* Simple Moving Median 'SMM'
* Smoothed Simple Moving Average 'SSMA'
* Exponential Moving Average 'EMA'
* Double Exponential Moving Average 'DEMA'
* Triple Exponential Moving Average 'TEMA'
* Triangular Moving Average 'TRIMA'
* Triple Exponential Moving Average Oscillator 'TRIX'
* Volume Adjusted Moving Average 'VAMA'
* Kaufman Efficiency Indicator 'ER'
* Kaufman's Adaptive Moving Average 'KAMA'
* Zero Lag Exponential Moving Average 'ZLEMA'
* Weighted Moving Average 'WMA'
* Hull Moving Average 'HMA'
* Elastic Volume Moving Average 'EVWMA'
* Volume Weighted Average Price 'VWAP'
* Smoothed Moving Average 'SMMA'
* Fractal Adaptive Moving Average 'FRAMA'
* Moving Average Convergence Divergence 'MACD'
* Percentage Price Oscillator 'PPO'
* Volume-Weighted MACD 'VW_MACD'
* Elastic-Volume weighted MACD 'EV_MACD'
* Market Momentum 'MOM'
* Rate-of-Change 'ROC'
* Relative Strenght Index 'RSI'
* Inverse Fisher Transform RSI 'IFT_RSI'
* True Range 'TR'
* Average True Range 'ATR'
* Stop-and-Reverse 'SAR'
* Bollinger Bands 'BBANDS'
* Bollinger Bands Width 'BBWIDTH'
* Momentum Breakout Bands 'MOBO'
* Percent B 'PERCENT_B'
* Keltner Channels 'KC'
* Donchian Channel 'DO'
* Directional Movement Indicator 'DMI'
* Average Directional Index 'ADX'
* Pivot Points 'PIVOT'
* Fibonacci Pivot Points 'PIVOT_FIB'
* Stochastic Oscillator %K 'STOCH'
* Stochastic oscillator %D 'STOCHD'
* Stochastic RSI 'STOCHRSI'
* Williams %R 'WILLIAMS'
* Ultimate Oscillator 'UO'
* Awesome Oscillator 'AO'
* Mass Index 'MI'
* Vortex Indicator 'VORTEX'
* Know Sure Thing 'KST'
* True Strength Index 'TSI'
* Typical Price 'TP'
* Accumulation-Distribution Line 'ADL'
* Chaikin Oscillator 'CHAIKIN'
* Money Flow Index 'MFI'
* On Balance Volume 'OBV'
* Weighter OBV 'WOBV'
* Volume Zone Oscillator 'VZO'
* Price Zone Oscillator 'PZO'
* Elder's Force Index 'EFI'
* Cummulative Force Index 'CFI'
* Bull power and Bear Power 'EBBP'
* Ease of Movement 'EMV'
* Commodity Channel Index 'CCI'
* Coppock Curve 'COPP'
* Buy and Sell Pressure 'BASP'
* Normalized BASP 'BASPN'
* Chande Momentum Oscillator 'CMO'
* Chandelier Exit 'CHANDELIER'
* Qstick 'QSTICK'
* Twiggs Money Index 'TMF'
* Wave Trend Oscillator 'WTO'
* Fisher Transform 'FISH'
* Ichimoku Cloud 'ICHIMOKU'
* Adaptive Price Zone 'APZ'
* Squeeze Momentum Indicator 'SQZMI'
* Volume Price Trend 'VPT'
* Finite Volume Element 'FVE'
* Volume Flow Indicator 'VFI'
* Moving Standard deviation 'MSD'
* Schaff Trend Cycle 'STC'

Dependencies:

  • python (3.6+)
  • pandas (1.0.0+)

TA class is very well documented and there should be no trouble exploring it and using with your data. Each class method expects proper ohlc DataFrame as input.

Install:

pip install finta

or latest development version:

pip install git+git://github.com/peerchemist/finta.git

Import

from finta import TA

Prepare data to use with finta:

finta expects properly formated ohlc DataFrame, with column names in lowercase: ["open", "high", "low", "close"] and ["volume"] for indicators that expect ohlcv input.

to resample by time period (you can choose different time period)

ohlc = resample(df, "24h")

You can also load a ohlc DataFrame from .csv file

data_file = ("data/bittrex:btc-usdt.csv")

ohlc = pd.read_csv(data_file, index_col="date", parse_dates=True)


Examples:

will return Pandas Series object with the Simple moving average for 42 periods

TA.SMA(ohlc, 42)

will return Pandas Series object with "Awesome oscillator" values

TA.AO(ohlc)

expects ["volume"] column as input

TA.OBV(ohlc)

will return Series with Bollinger Bands columns [BB_UPPER, BB_LOWER]

TA.BBANDS(ohlc)

will return Series with calculated BBANDS values but will use KAMA instead of MA for calculation, other types of Moving Averages are allowed as well.

TA.BBANDS(ohlc, TA.KAMA(ohlc, 20))

For more examples see examples directory.


I welcome pull requests with new indicators or fixes for existing ones. Please submit only indicators that belong in public domain and are royalty free.

Contributing

  1. Fork it (https://github.com/peerchemist/finta/fork)
  2. Study how it's implemented.
  3. Create your feature branch (git checkout -b my-new-feature).
  4. Run black code formatter on the finta.py to ensure uniform code style.
  5. Commit your changes (git commit -am 'Add some feature').
  6. Push to the branch (git push origin my-new-feature).
  7. Create a new Pull Request.

Donate

Buy me a beer 🍺:

Bitcoin: 3NibjuvQPzcfuLaefhUEEFBcmHpXgKgs4m

Peercoin: P9dAfWoxT7kksKAStubDQR6RhdXk5z12rV

반응형