计算简单移动平均线
import numpy as np import sys from matplotlib.pyplot import plot from matplotlib.pyplot import show N = int(sys.argv[1]) weights = np.ones(N) / N weights c = np.loadtxt('data.csv', delimiter=',', usecols=(6,), unpack=True) sma = np.convolve(weights, c)[N-1:-N+1] t = np.arange(N - 1, len(c)) plot(t, c[N-1:], lw=1.0) plot(t, sma, lw=2.0) show()
在下图中,相对较平滑的粗线描绘的是5日移动平均线,而锯齿状的细线描绘的是每天的收
盘价。
2018-03-0819:58:18