Every algorithm in Control Flow and Simple Numerical Programs was a one-off script: hard-code the inputs at the top, run the whole file, edit and rerun for a different input. That does not scale to a program that needs a bisection square root and a bond-yield solver and an implied-volatility routine, called many times on many different values, inside the same run. Functions are Python's mechanism for packaging logic once and calling it under arbitrary inputs, and decomposition — designing a program as a set of functions with clear, individually-specified contracts — is the single most important design habit this vault's programming content assumes from here on. This topic covers how to define and call functions, how to specify what a function promises its callers, a second way to express repetition (recursion), and the deliberate limits placed on Python's one escape hatch from parameter-and-return-value discipline (global variables).
In this lesson
- Learning objectives
- Contents
- The big picture
The full lesson is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.