import pandas as pd
import numpy as np
# 计算EMA(12)和EMA(16)
data['EMA12'] = data['close'].ewm(alpha=2 / 13, adjust=False).mean()
data['EMA26'] = data['close'].ewm(alpha=2 / 27, adjust=False).mean()
# 计算DIFF、DEA、MACD
data['DIFF'] = data['EMA12'] - data['EMA26']
data['DEA'] = data['DIFF'].ewm(alpha=2 / 10, adjust=False).mean()
data['MACD'] = 2 * (data['DIFF'] - data['DEA'])