# -*- coding: utf-8 -*- """ Created on Wed May 24 15:47:51 2017 @author: yunjinqi E-mail:yunjinqi@qq.com Differentiate yourself in the world from anyone else. """ import pandas as pd import numpy as np import datetime import time #获取数据 df=pd.read_csv('C:/Users/HXWD/Desktop/000001.csv',encoding='gbk') df.columns=['date','code','name','close','high','low','open','preclose', 'change','change_per','volume','amt'] df=df[['date','open','high','low','close','volume','amt']] df.head() def get_EMA(df,N): for i in range(len(df)): if i==0: df.ix[i,'ema']=df.ix[i,'volume'] if i>0: df.ix[i,'ema']=(2*df.ix[i-1,'volume']+(N-1)*df.ix[i,'volume'])/(N+1) ema=list(df['ema']) return ema def get_VMACD(df,short=12,long=26,M=9): a=get_EMA(df,short) b=get_EMA(df,long) df['diff']=pd.Series(a)-pd.Series(b) #print(df['diff']) for i in range(len(df)): if i==0: df.ix[i,'dea']=df.ix[i,'diff'] if i>0: df.ix[i,'dea']=(2*df.ix[i-1,'diff']+(M-1)*df.ix[i,'diff'])/(M+1) df['macd']=2*(df['diff']-df['dea']) return df get_VMACD(df,12,26,9) df.tail()
''' 量指数平滑异同平均线 原理: 以成交量为权数的MACD指标。 算法: DIFF线 成交量的短期(SHORT)、长期(LONG)指数平滑移动平均线间的差。 DEA线 DIFF线的M日指数平滑移动平均线。 MACD线 DIFF线与DEA线的差,彩色柱状线。 用法: 1.DIFF、DEA均为正,DIFF向上突破DEA,买入信号。 2.DIFF、DEA均为负,DIFF向下跌破DEA,卖出信号。 3.DEA线与K线发生背离,行情反转信号。 4.分析MACD柱状线,由正变负,卖出信号;由负变正,买入信号。'''
注:以上代码仅供参考,需要单独编写文华财经,金字塔,大智慧,通达信,TB, Python 平台的指标、策略等,请联系扣扣1733505732,兼职时间:工作日下午18:00-22:00,节假日。