-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_bar.py
60 lines (52 loc) · 1.32 KB
/
csv_bar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from util import *
def average(marr):
tot = 0.0
for aFloat in marr:
tot += aFloat
return tot / len(marr)
class csv_bar:
def __init__(self):
self.vdateTime = []
self.vday = []
self.vopen = []
self.vclose =[]
self.vhigh = []
self.vlow = []
self.vvolume = []
def load(self,fname):
f = open(fname)
header = f.readline()
vdateTime = self.vdateTime # copy to local varibles because faster
vday = self.vday
vopen = self.vopen
vclose = self.vclose
vhigh = self.vhigh
vlow = self.vlow
vvolume = self.vvolume
while 1:
aLine = f.readline()
if not aLine:
break;
if len(aLine) < 5:
continue
ra = aLine.split(",")
vdateTime.append(ra[0])
vday.append(ra[1])
vopen.append(float(ra[2]))
vclose.append(float(ra[3]))
vhigh.append(float(ra[4]))
vlow.append(float(ra[5]))
vvolume.append(int(ra[6]))
f.close();
def main():
run_start = curr_ms()
abars = csv_bar()
abars.load("c:/JOE/stock/JTDATA/symbols/SPY/2012.M1.csv")
elap("Total Load time ", run_start, curr_ms())
print "out contains", len(abars.vopen), " records"
beg_time = curr_ms()
tavg = average(abars.vclose)
elap("Average close elap", beg_time, curr_ms())
print "close avg=", tavg
if __name__ == "__main__":
main()