-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_bar_parse.jl
More file actions
119 lines (96 loc) · 2.5 KB
/
csv_bar_parse.jl
File metadata and controls
119 lines (96 loc) · 2.5 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Julia function to load CSV and compute
# a couple of SMA. written to be identical
# to lua version.
using DataFrames
# Note: There are faster ways to compute SMA but this
# is closest to the method shown in basic tutorials
# and is a valid test of a tight loop that spends a
# a lot of time indexing into an array. We show it
# as a nested loop instead of slice
function sma(avect, numPer)
print(length(avect), " numper=", numPer)
numEle = length(avect)
tout = Array(Float32, numEle)
for ndx = 1:numEle
tsum = 0.0
begndx = max(1, ndx - numPer)
for slicendx = begndx:ndx
tsum += avect[slicendx]
end
tout[ndx] = tsum / float32(numPer)
end
return tout
end
## Showing the more common Julia version of
## slicing out what we need and applying builtin
## operator mean instead of manual sub loop.
function sma_slice(avect, numPer)
print(length(avect), " numper=", numPer)
numEle = length(avect)
tout = Array(Float32, numEle)
for ndx = 1:numEle
begndx = max(1, ndx - numPer)
tout[ndx] = mean(avect[begndx:ndx])
end
return tout
end
function runTest()
print ("read table")
tic()
dta = readtable("2014.M1.csv")
toc()
println("finished read table")
closeVect = dta[:close]
println("compute sma(14)")
tic()
sma14 = sma(closeVect, 14)
toc()
println("finished sma(14)")
println("compute sma (600)")
tic()
sma600 = sma(closeVect, 600)
toc()
println("finished sma(600)")
closeVect = dta[:close]
println("compute sma_slice(14)")
tic()
sma14 = sma_slice(closeVect, 14)
toc()
println("finished sma_slice(14)")
println("compute sma_slice(600)")
tic()
sma600 = sma_slice(closeVect, 600)
toc()
println("finished sma_slice(600)")
println("\n\n Convert to Typed vector and try again \n\n")
tic()
tlen = length(closeVect)
tvect = Array(Float32, tlen)
for ndx = 1:tlen
tvect[ndx] = closeVect[ndx]
end
toc()
println("vector convertion complete")
println("compute sma(14)")
tic()
sma14 = sma(tvect, 14)
toc()
println("finished sma(14)")
println("compute sma (600)")
tic()
sma600 = sma(tvect, 600)
toc()
println("finished sma(600)")
closeVect = dta[:close]
println("compute sma_slice(14)")
tic()
sma14 = sma_slice(tvect, 14)
toc()
println("finished sma_slice(14)")
println("compute sma_slice(600)")
tic()
sma600 = sma_slice(tvect, 600)
toc()
println("finished sma_slice(600)")
end
runTest()