-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacd.py
More file actions
24 lines (17 loc) · 696 Bytes
/
macd.py
File metadata and controls
24 lines (17 loc) · 696 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# MACD
import yfinance as yf
tickers=["AMZN","GOOG","MSFT"]
ohlcv_data = {}
for ticker in tickers:
temp = yf.download(ticker,period='1mo',interval='15m')
temp.dropna(how='any',inplace=True)
ohlcv_data[ticker]=temp
def MACD(DF, a=12, b=26, c=9):
df=DF.copy()
df["ma_fast"] = df["Adj Close"].ewm(span=a, min_periods=a).mean()
df["ma_slow"] = df["Adj Close"].ewm(span=b, min_periods=b).mean()
df["macd"] = df["ma_fast"] - df["ma_slow"]
df["signal"] = df["macd"].ewm(span=c, min_periods=c).mean()
return df.loc[:,["macd", "signal"]]
for ticker in ohlcv_data:
ohlcv_data[ticker][["MACD", "SIGNAL"]] = MACD(ohlcv_data[ticker])