|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大神好,最近在学习numpy模块时遇到个问题,就是下面的红色代码运行时发生错误,烦请各位大神指点一二。代码和data.csv文件见下:
py文件:
import numpy as np
import sys
h,l,c=np.loadtxt('data.csv',delimiter=',',usecols=(1,2,3),unpack=True)
N=int(sys.argv[1])
h=h[-N:]
l=l[-N:]
print("len(h)",len(h),"len(l)",len(l))
print("Close",c)
previousclose=(c[-N-1:-1])
print("len(previousclose)",len(previousclose))
print("Previous close",previousclose)
truerange=np.maximum(h-l,h-previousclose,previousclose-l)
print("True range",truerange)
atr=np.zeros(N)
atr[0]=np.mean(truerange)
for i in range(1,N):
atr[i]=(N-1)*atr[i-1]+truerange[i]
atr[i]/=N
print("ATR",atr)
data.csv文件:
344.17 344.4 333.53 336.1 21144800
335.8 340.04 334.3 339.32 13473000
341.3 345.65 340.98 345.03 15236800
344.45 345.25 343.55 344.32 9242600
343.8 344.24 338.55 343.44 14064100
343.61 346.7 343.51 346.5 11494200
347.89 353.25 347.64 351.88 17322100
353.68 355.52 352.15 355.2 13608500
355.19 359 354.87 358.16 17240800
357.39 360 348 354.54 33162400
354.75 357.8 353.54 356.85 13127500
356.79 359.48 356.71 359.18 11086200
359.19 359.97 357.55 359.9 10149000
360.8 364.9 360.5 363.13 17184100
357.1 360.27 356.52 358.3 18949000
358.21 359.5 349.52 350.56 29144500
342.05 345.4 337.72 338.61 31162200
338.77 344.64 338.61 342.62 23994700
344.02 345.15 338.37 342.88 17853500
345.29 348.43 344.8 348.16 13572000
351.21 355.05 351.12 353.21 14395400
355.47 355.72 347.68 349.31 16290300
349.96 354.35 348.4 352.12 21521000
357.2 359.79 355.92 359.56 17885200
360.07 360.29 357.75 360 16188000
361.11 361.67 351.31 355.36 19504300
354.91 357.4 352.25 355.76 12718000
354.69 354.76 350.6 352.47 16192700
349.69 349.77 344.9 346.67 18138800
345.4 352.32 345 351.99 16824200
|
|