systematically:
In  [ 62 ]: func_list   =   [‘f_py’,    ‘f_np’, ‘f_nb’]
data_list   =    3  *   [‘I,    J’]
In  [ 63 ]: perf_comp_data(func_list,   data_list)
Out[63]:    function:   f_nb,   av. time    sec:            0.02022,    relative:               1.0
                                    function:   f_np,   av. time    sec:            1.67494,    relative:           82.8
                                    function:   f_py,   av. time    sec:        15.82375,   relative:       782.4
The    Numba   version of  the nested  loop    implementation  is  by  far the fastest;    much    faster
even   than    the NumPy   vectorized  version.    The pure    Python  version is  much    slower  than    the
other  two versions.
QUICK WINS
Many  approaches  for performance improvements    (of numerical   algorithms) involve considerable    effort. With
Python    and Numba   you have    an  approach    available   that    involves    only    the smallest    effort  possible    —   in  general,
importing the library and a   single  additional  line    of  code.   It  does    not work    for all kinds   of  algorithms, but it  is
often worth   a   (quick) try and sometimes   indeed  yields  a   quick   win.
Binomial    Option  Pricing
The    previous    section uses    Monte   Carlo   simulation  to  value   European    call    options,    using   a
parallel   computing   approach.   Another popular numerical   method  to  value   options is  the
binomial   option  pricing model   pioneered   by  Cox,    Ross,   and Rubinstein  (1979). In  this
model, as  in  the Black-Scholes-Merton    setup,  there   is  a   risky   asset,  an  index   or  stock,  and
a  riskless    asset,  a   bond.   As  with    Monte   Carlo,  the relevant    time    interval    from    today   until
the    maturity    of  the option  is  divided into    generally   equidistant subintervals,    t. Given   an
index  level   at  time    s   of  Ss, the index   level   at  t   =   s   +    t  is  given   by  St  =   Ss  ·   m,  where   m   is
chosen randomly    from    from    {u,d}   with        as  well    as   .  r   is
the    constant,   riskless    short   rate.   The risk-neutral    probability for an  up-movement is  given
as .
Consider   that    a   parameterization    for the model   is  given   as  follows:
In  [ 64 ]: #   model   &   option  parameters
S0  =   100. #  initial index   level
T   =   1. #    call    option  maturity
r   =   0.05 #  constant    short   rate
vola    =   0.20 #  constant    volatility  factor  of  diffusion
#   time    parameters
M   =    1000        #  time    steps
dt  =   T   /   M # length  of  time    interval
df  =   exp(-r  *   dt)     #   discount    factor  per time    interval
#   binomial    parameters
u   =   exp(vola    *   sqrt(dt))       #   up-movement
d   =    1  /   u # down-movement
q   =   (exp(r  *   dt) -   d)  /   (u  -   d)      #   martingale  probability
An implementation  of  the binomial    algorithm   for European    options consists    mainly  of
these  parts:
Index  level   simulation
Simulate   step    by  step    the index   levels.
Inner  value   calculation
Calculate  the inner   values  at  maturity    and/or  at  every   time    step.