-
Notifications
You must be signed in to change notification settings - Fork 4
stock #1
Copy link
Copy link
Open
Description
`import yfinance as yf
import pandas as pd
from talib import abstract
from finlab.plot_candles import plot_candles
下載股票歷史資料(範例用:TSLA)
data = yf.download(”TSLA“, start=”2023-09-02“, end=”2023-12-31“)
整理資料格式以符合 talib 要求
df = pd.DataFrame({
’open‘: data[’Open‘],
’high‘: data[’High‘],
’low‘: data[’Low‘],
’close‘: data[’Close‘],
’volume‘: data[’Volume‘]
})
計算技術指標
SMA = abstract.SMA(df)
RSI = abstract.RSI(df)
STOCH = abstract.STOCH(df)
畫出 K 線圖 + 技術指標
plot_candles(
start_time=’2023-09-02‘,
end_time=’2023-12-31‘,
pricing=df,
title=’Candles‘,
volume_bars=True,
overlays=[SMA], # 在K線圖上疊加均線
technicals=[RSI, STOCH], # 在圖表下方加入 RSI 與 KD 指標
technicals_titles=[’RSI‘, ’KD‘] # 指標圖表標題
)`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels