Python for Finance: Analyze Big Financial Data

(Elle) #1
In  [ 45 ]: plt.figure(figsize=( 8 ,     4 ))
plt.plot(strikes, option_values_seq, ‘b’, label=‘Sequential’)
plt.plot(strikes, option_values_par, ‘r.’, label=‘Parallel’)
plt.grid(True); plt.legend(loc= 0 )
plt.xlabel(‘strikes’)
plt.ylabel(‘European call option values’)

Figure 8-3. Comparison of European call option values

Performance Comparison


With the help of the perf_comp_func function, we can compare the performance a bit


more rigorously:


In  [ 46 ]: n   =    50      #  number  of  option  valuations
func_list = [‘seq_value’, ‘par_value’]
data_list = 2 * [‘n’]
In [ 47 ]: perf_comp_data(func_list, data_list)
Out[47]: function: par_value, av. time sec: 0.90832, relative: 1.0
function: seq_value, av. time sec: 5.75137, relative: 6.3

The results clearly demonstrate that using IPython.parallel for parallel execution of


functions can lead to an almost linear scaling of the performance with the number of cores


available.

Free download pdf