Python for Finance: Analyze Big Financial Data

(Elle) #1
                                        /out    (EArray(750000, 1000))  ”
atom := Float64Atom(shape=(), dflt=0.0)
maindim := 0
flavor := ‘numpy’
byteorder := ‘little’
chunkshape := (8, 1000)
In [ 145 ]: out[ 0 , : 10 ]
Out[145]: array([-0.95979563, -1.21530335, 0.02687751, 2.88229293, -0.05596624,
-1.70266651, -0.58575264, 1.70317385, 3.54571202, 2.81602673
])

Given that the whole operation takes place out-of-memory, it can be considered quite fast,


in particular as it is executed on standard hardware. Let us briefly compare this to the in-


memory performance of the numexpr module (see also Chapter 8):


In  [ 146 ]:    %time imarray   =   ear.read()
# read whole array into memory
Out[146]: CPU times: user 1.26 s, sys: 4.11 s, total: 5.37 s
Wall time: 5.39 s
In [ 147 ]: import numexpr as ne
expr = ‘3 * sin(imarray) + sqrt(abs(imarray))’
In [ 148 ]: ne.set_num_threads( 16 )
%time ne.evaluate(expr)[ 0 , : 10 ]
Out[148]: CPU times: user 24.2 s, sys: 29.1 s, total: 53.3 s
Wall time: 3.81 s

                                        array([-0.95979563, -1.21530335,        0.02687751,     2.88229293, -0.05596624,
-1.70266651, -0.58575264, 1.70317385, 3.54571202, 2.81602673
])
In [ 149 ]: h5.close()
In [ 150 ]: !rm -f $path*
Free download pdf