Chapter 11. Performance Python
Performance is often cited as a weakness of Python, especially when people think of it as a language that only runs slow, interpreted loops. In practice, modern Python gives you access to JIT compilers, static compilation, vectorized libraries, and multiprocessing, all from the same code base. This chapter shows how to combine these tools so that numerically intensive finance code runs close to compiled-language speed.
The chapter revisits classic performance benchmarks from the second edition: loops over random numbers, Fibonacci numbers, binomial option pricing trees, Monte Carlo simulation for pi (π) and options, and recursive statistics over time series. It compares pure Python with vectorized NumPy, JIT-compiled Numba, Cython, and simple multiprocessing, and shows where each technique makes the most difference.
To follow along, you need a Python environment with numpy, pandas, numba, and
matplotlib installed, a working IPython or Jupyter session so that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access