假设您以“低”列中的值进行购买,并以“高”中的值进行出售。您可能不会在同一天买卖。您的函数,股票应采用包含数据的CSV文件的文件名字符串。您可以假设文件按时间顺序排列。
我不明白为什么我的程序中出现了nontype错误
import csv
def stocks(s):
a=[]
b=[]
trades=[]
with open('DJI.csv', newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
a.append(row['Low'])
b.append(row['High'])
trades.append(float(min(a)))
i1=a.index(min(a))
trades.append(float(max(b[i1:])))
assert round(trades[0],2)
assert round(trades[1],2)
print(trades)
trades = stocks("DJI.csv")
print(trades)
结果应为:[15340.69043, 26616.710938]
实际结果:
[15340.69043, 26616.710938]
None
assert round(trades[0], 2) == 15340.69
assert round(trades[1], 2) == 26616.71
实际结果:'NoneType' object is not subscriptable