# -*- 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_BIAS(df,L1=6,L2=12,L3=24): ''' 乖离率 算法: 当日收盘价与移动平均线之间的差距; 用法: 正的乖离率愈大,表示短期获利愈大,则获利回吐的可能性愈高;负的乖离率愈大,则空头回补的可能性愈高。 按个股收盘价与不同天数的平均价之间的差距,可绘制不同的BIAS线。 参数: 系统绘制三条BIAS线,分别为收盘价与L1日、L2日、L3日移动平均价的差。''' df['bias1']=100*(df['close']-df['close'].rolling(L1).mean())/df['close'].rolling(L1).mean() df['bias2']=100*(df['close']-df['close'].rolling(L2).mean())/df['close'].rolling(L1).mean() df['bias3']=100*(df['close']-df['close'].rolling(L3).mean())/df['close'].rolling(L1).mean() return df get_BIAS(df) df.tail()