python获取计算股票技术指标DIF/DEA/MACD

先了解一下DIF、DEA、MACD指标的计算方式:
python获取计算股票技术指标DIF/DEA/MACD_第1张图片


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'])

你可能感兴趣的:(python)