랭그래프 활용한 주식 정보 도출 프로젝트
- yahooquery, ta 라이브러리 활용
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import yahooquery as yf
|
||||
from ta.trend import MACD, SMAIndicator
|
||||
from ta.momentum import RSIIndicator
|
||||
|
||||
async def get_technical_info(ticker: str):
|
||||
"""
|
||||
yfinance, ta api 이용
|
||||
"""
|
||||
|
||||
# 주가 데이터 다운로드
|
||||
df = yf.download(ticker, period="1y", interval="1d")
|
||||
# 종가 가져오기
|
||||
close = df['Close'].squeeze()
|
||||
|
||||
macd = MACD(close)
|
||||
macd_value = float(macd.macd().iloc[-1])
|
||||
signal_value = float(macd.macd_signal().iloc[-1])
|
||||
trend = "bullish" if macd_value > signal_value else "bearish"
|
||||
|
||||
return {
|
||||
# 현재 주가
|
||||
"current_price":close.iloc[-1],
|
||||
# 20 일선
|
||||
"sma20":float(SMAIndicator(close, window=20).sma_indicator().iloc[-1]),
|
||||
# 60 일선
|
||||
"sma60":float(SMAIndicator(close, window=60).sma_indicator().iloc[-1]),
|
||||
# rsi
|
||||
"rsi":float(SMAIndicator(close, window=14).rsi().iloc[-1]),
|
||||
# macd
|
||||
"macd":macd.macd(),
|
||||
# macd_signal
|
||||
"macd_signal": signal_value,
|
||||
# trend
|
||||
"trend": trend,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user