Skip to content
Python for Quantitative Finance / Model and software design

Profiling and Optimisation

A slow calibration can delay a risk report or a trading decision. Measure the whole job, find the function that consumes time, and check that an optimisation preserves the numerical result. This lesson compares loop and array implementations under controlled inputs and explains when the speed gain is worth the added complexity.

Learning objectives. By the end of this note you should be able to:
  • wrap a routine in a simple timing harness and in cProfile;
  • interpret a profile enough to name the hot function;
  • replace a Python path loop with a vectorised equivalent and compare speeds;
  • decide when a 10% win is not worth the readability loss.

In this lesson

  1. Measure before rewriting
  2. Reading a small cProfile dump
  3. Before / after on a path loop
  4. When the gain is not worth it
  5. Checklist

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.