資源簡介

代碼片段和文件信息
from?matplotlib.finance?import?quotes_historical_yahoo
from?datetime?import?date
import?numpy?as?np
import?matplotlib.pyplot?as?plt
from?scipy?import?fftpack
from?scipy?import?signal
from?matplotlib.dates?import?DateFormatter?DayLocator?MonthLocator
from?scipy?import?optimize
today?=?date.today()
start?=?(today.year?-?1?today.month?today.day)
quotes?=?quotes_historical_yahoo(“QQQ“?start?today)
quotes?=?np.array(quotes)
dates?=?quotes.T[0]
qqq?=?quotes.T[4]
y?=?signal.detrend(qqq)
alldays?=?DayLocator()??????????????
months?=?MonthLocator()
month_formatter?=?DateFormatter(“%b?%Y“)
fig?=?plt.figure()
ax?=?fig.add_subplot(211)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(month_formatter)
amps?=?np.abs(fftpack.fftshift(fftpack.rfft(y)))
amps[amps?
def?residuals(p?y?x):
???Aktheta?=?p
???err?=?y-A?*?np.sin(2*?np.pi*?k?*?x?+?theta)
???return?err
filtered?=?-fftpack.irfft(fftpack.ifftshift(amps))
N?=?len(qqq)
f?=?np.linspace(-N/2?N/2?N)
p0?=?[filtered.max()?f[amps.argmax()]/N?np.pi/3]
plsq?=?optimize.leastsq(residuals?p0?args=(filtered?dates))
p?=?plsq[0]
print?p
plt.plot(dates?y?‘o‘?label=“detrended“)
plt.plot(dates?filtered?label=“filtered“)
plt.plot(dates?p[0]?*?np.sin(2?*?np.pi?*?dates?*?p[1]?+?p[2])?‘^‘?label=“fit“)
fig.autofmt_xdate()
plt.legend()
ax2?=?fig.add_subplot(212)
plt.plot(f?amps?label=“transformed“)
plt.legend()
plt.show()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-04-22?11:18??Code\ch10code\
?????文件?????????248??2013-02-11?23:19??Code\ch10code\a.mat
?????文件????????1470??2013-02-11?22:51??Code\ch10code\algebra.py
?????文件????????1390??2013-03-16?20:06??Code\ch10code\frequencies.py
?????文件?????????148??2013-02-11?22:56??Code\ch10code\gaussquad.py
?????文件?????????685??2013-03-16?22:38??Code\ch10code\images.py
?????文件????????1711??2013-03-16?22:06??Code\ch10code\optfit.py
?????文件?????????851??2013-02-11?23:17??Code\ch10code\pair.py
?????文件?????????602??2011-07-27?22:46??Code\ch10code\README
?????文件?????????723??2013-02-12?18:11??Code\ch10code\repeat_audio.py
?????文件??????????93??2013-02-11?23:19??Code\ch10code\scipyio.py
?????文件?????????491??2013-02-11?23:22??Code\ch10code\sincinterp.py
?????文件?????????471??2013-02-11?23:23??Code\ch10code\statistics.py
?????文件?????????845??2013-03-16?19:31??Code\ch10code\trend.py
?????目錄???????????0??2013-04-22?11:19??Code\ch11code\
?????文件???????12288??2013-02-15?12:14??Code\ch11code\.life_demo.py.swp
?????文件?????????901??2013-02-14?18:49??Code\ch11code\animation.py
?????文件?????????895??2013-02-14?21:09??Code\ch11code\clustering.py
?????文件????????1302??2012-11-22?21:34??Code\ch11code\head.jpg
?????文件????????2208??2013-02-15?12:14??Code\ch11code\life_demo.py
?????文件????????1481??2013-02-14?19:10??Code\ch11code\matplotlib_demo.py
?????文件?????????978??2013-02-15?12:06??Code\ch11code\opengl_demo.py
?????文件?????????448??2012-11-18?22:47??Code\ch11code\simplegame.py
?????文件?????????574??2013-02-14?19:32??Code\ch11code\surfarray_demo.py
?????目錄???????????0??2013-04-22?11:13??Code\ch1code\
?????文件?????????555??2011-03-13?23:01??Code\ch1code\README
?????文件????????1185??2013-01-12?22:34??Code\ch1code\vectorsum.py
?????目錄???????????0??2013-04-22?11:13??Code\ch2code\
?????文件?????????635??2013-01-16?19:16??Code\ch2code\arrayattributes.py
?????文件????????2064??2013-01-16?19:30??Code\ch2code\arrayattributes2.py
?????文件????????1312??2013-01-16?19:27??Code\ch2code\arrayconversion.py
............此處省略130個文件信息
評論
共有 條評論