exodus-stock/indicator_MACD.py

17 lines
591 B
Python
Raw Normal View History

2022-04-06 03:56:09 -04:00
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt
def macd_data(data):
tick_history = data
tick_macd = pd.DataFrame()
tick_macd['Close'] = tick_history['Close']
tick_macd['EMA-12'] = tick_macd['Close'].ewm(span=12, adjust=False).mean()
tick_macd['EMA-26'] = tick_macd['Close'].ewm(span=26, adjust=False).mean()
tick_macd['MACD'] = tick_macd['EMA-12'] - tick_macd['EMA-26']
tick_macd['Signal'] = tick_macd['MACD'].ewm(span=9, adjust=False).mean()
tick_macd['Gap'] = tick_macd['MACD'] - tick_macd['Signal']
print(tick_macd.index)
return tick_macd