Spaces:
Sleeping
Sleeping
File size: 526 Bytes
8e0b458 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# indicators/macd.py
import pandas as pd
def macd(df, fast_period=12, slow_period=26, signal_period=9, column="Close"):
"""
Calculates MACD Line, Signal Line, and Histogram
"""
ema_fast = df[column].ewm(span=fast_period, adjust=False).mean()
ema_slow = df[column].ewm(span=slow_period, adjust=False).mean()
macd_line = ema_fast - ema_slow
signal_line = macd_line.ewm(span=signal_period, adjust=False).mean()
histogram = macd_line - signal_line
return macd_line, signal_line, histogram
|