# -*- 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_CCI(df,N): ''' 顺势指标 原理: 用目前股价的波动程度和常态分布范围比较,来得出超买或超卖的结论,用于捕捉趋势反转点。 算法: 典型价格与典型价格的N日移动平均的差除以N日内典型价格的平均绝对偏差。 用法: 当CCI小于-100时为买入信号,CCI大于100时为卖出信号; 股价产生背离现象时,是一项明显的警告信号。 参数: N 设定计算移动平均的天数,一般为14。''' df['typ']=(df['high']+df['low']+df['close'])/3 df['cci']=((df['typ']-df['typ'].rolling(N).mean())/ (0.015*abs(df['typ']-df['typ'].rolling(N).mean()).rolling(N).mean())) return df get_CCI(df,14) df.tail(100)