"""
Created on Thu May 24 21:00:47 2018
@author: luogan
"""
import numpy as np
from scipy.fftpack import fft,ifft
import matplotlib.pyplot as plt
import seaborn
import tushare as ts
df=ts.get_hist_data('000001',start='2015-02-02',end='2018-05-24')
x=list(range(df.shape[0]))
y=list(df['p_change'])
yy=fft(y)
yreal = yy.real
yimag = yy.imag
yf=abs(fft(y))
yf1=abs(fft(y))/len(x)
yf2 = yf1[range(int(len(x)/2))]
xf = np.arange(len(y))
xf1 = xf
xf2 = xf[range(int(len(x)/2))]
plt.subplot(221)
plt.plot(x[0:50],y[0:50])
plt.title('Original wave')
plt.subplot(222)
plt.plot(xf,yf,'r')
plt.title('FFT of Mixed wave(two sides frequency range)',fontsize=7,color='#7A378B')
plt.subplot(223)
plt.plot(xf1,yf1,'g')
plt.title('FFT of Mixed wave(normalization)',fontsize=9,color='r')
plt.subplot(224)
plt.plot(xf2,yf2,'b')
plt.title('FFT of Mixed wave)',fontsize=10,color='#F08080')
plt.show()