ta_lib를 이용하면 간단하게 각종 주식 지표를 구할수 있는 다양한 함수를 제공하고 있음
하지만 ta.momentum.stoch 함수는 기본적으로 fast stochastict 값을 반환하므로 스토캐스틱 계산 방식과 같이 fast 값을 3일 이동평균하면 slow 값을 얻을수 있다. 그리고 signal값을 다시 slow값을 3일 이동평균하면 값을 구할 수 있다.
https://github.com/bukosabino/ta/tree/master?tab=readme-ov-file
GitHub - bukosabino/ta: Technical Analysis Library using Pandas and Numpy
Technical Analysis Library using Pandas and Numpy. Contribute to bukosabino/ta development by creating an account on GitHub.
github.com
https://technical-analysis-library-in-python.readthedocs.io/en/latest/ta.html
Documentation — Technical Analysis Library in Python 0.1.4 documentation
Rate of Change (ROC) The Rate-of-Change (ROC) indicator, which is also referred to as simply Momentum, is a pure momentum oscillator that measures the percent change in price from one period to the next. The ROC calculation compares the current price with
technical-analysis-library-in-python.readthedocs.io
https://waymond.tistory.com/167
Python으로 스토캐스틱 계산 및 차트 생성
Python으로 스토캐스틱 계산 및 차트 생성 이번 포스트에서는 Python으로 주식 보조 지표 중 하나인 스토캐스틱을 계산하고 차트를 생성해보는 시간을 가져보고자 한다. 스토캐스틱이 무엇인지 간
waymond.tistory.com
import yfinance as yf
import ta
import pandas as pd
from datetime import datetime
end_date = datetime.today().strftime('%Y-%m-%d')
# TQQQ 데이터 다운로드
ticker = 'TQQQ'
data = yf.download(ticker, start='2024-01-01', end=end_date)
# Fast Stochastic 계산
data['fastk'] = ta.momentum.stoch(data['High'], data['Low'], data['Close'], window=14, smooth_window=1)
# Slow Stochastic 계산 (Fast %K 값에 3일 이동 평균 적용)
data['slowk'] = data['fastk'].rolling(window=3).mean()
data['slowd'] = data['slowk'].rolling(window=3).mean()
'프로그래밍 > 파이썬' 카테고리의 다른 글
배치파일을 통해 관리자 권한으로 실행하기 (0) | 2024.06.22 |
---|---|
matplotlib로 차트 그리기 (0) | 2024.06.21 |
pip 오류 Configuration file could not be loaded. (0) | 2024.06.11 |
파이썬 함수에서 여개의 값을 리턴(반환)하는 방법 (0) | 2024.05.15 |
[에러]pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. (0) | 2024.03.31 |