简体   繁体   English

快速傅立叶变换算法及技术分析

[英]Fast Fourier Transform Algorithm and Technical Analysis

My Mini Practice Project requires me to do: 我的迷你实践项目要求我做以下事情:

  1. Download stock prices. 下载股票价格。
  2. Detrend stock prices. 降低股价。
  3. Smooth detrended stock prices. 平稳的去趋势股票价格。
  4. Apply FFT algorithm. 应用FFT算法。

The Mini Practice Project Python code can be seen below: 迷你实践项目的Python代码如下所示:

#Python code: Download the Daily Stock Prices from Yahoo Finance 
from matplotlib.finance 
import quotes_historical_yahoo 
from pylab
import * import numpy as np import
scipy.signal as sc import
matplotlib.pyplot as plt 
import pandas as pd
ticker='AAPL' begdate=(2013,12,6) enddate=(2015,12,20)
data = quotes_historical_yahoo(ticker, begdate, enddate,asobject=True, adjusted=True)
aapl=data.aclose[1:]
np.count_nonzero(aapl)
plt.plot(aapl)
plt.title(‘Apple stock price movement’)

#Python code: Detrend stock prices
detrend=sc.detrend(aapl)
plt.plot(detrend)
plt.title(‘Apple stock detrended prices’) 

#Python code: Smooth Detrended Apple Stock Prices 
w=np.blackman(20) 

#we selected 20 the parameter of the blackman window function 
y=np.convolve(w/w.sum(),detrend,mode='same')
plt.plot(y) plt.title(‘Blackman window function for detrended Apple stock
price’) 

#Python code: Apply FFT Algorithm 
fft=abs(rfft(y)) plt.plot(fft)
plt.title(‘FFT Algorithm applied to Apple stock price’)

When I type >>> fft, the result should be: array([ 31.29635197, 2706.46455209, 1093.11797192, 904.02261366, 582.27538238, 282.87694269, 244.95336969, 501.27771573, 247.04690328, 554.24978967, 115.67400179, 270.14245787, 194.51970654, 179.0406388, 302.98350318, 170.32131932, 51.39420044, 87.25308608, 87.15654977, 39.34619432]) 当我键入>>> fft时,结果应为:array([31.29635197,2706.46455209,1093.11797192,904.02261366,582.27538238,282.87694269,244.95336969,501.27771573,247.04690328,554.24978967,115.67400179,270.142459.0.174.51970 87.25308608、87.15654977、39.34619432])

I keep getting a code error: from matplotlib.finance is an invalid syntax. 我不断收到代码错误:来自matplotlib.finance是无效的语法。 How do I fix this? 我该如何解决?

from matplotlib.finance 
import quotes_historical_yahoo 

should be on the same line like so: 应该在同一行上,如下所示:

from matplotlib.finance import quotes_historical_yahoo

Alternatively, you can break lines: 或者,您可以折行:

from matplotlib.finance \
import quotes_historical_yahoo 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM