A Monte Carlo pricer may calculate thousands of path payoffs with the same formula. Array operations express that calculation directly and can reduce Python loop overhead. This lesson checks broadcasting shapes, samples terminal and full-path values, and computes portfolio returns from a date-by-asset matrix. It also explains when a loop remains clearer or faster.
Learning objectives. By the end of this note you should be able to:
- apply broadcasting to scenario × asset and path × time grids without silent shape bugs;
- rewrite a path loop for geometric Brownian motion (GBM) terminal values as a single array expression;
- compute portfolio returns from a matrix with a matrix–vector product;
- decide when a loop is clearer or necessary (path-dependent early exercise, sequential filters).
In this lesson
- Broadcasting as a contract
- Monte Carlo without a path loop
- Returns matrices and date axes
- When a loop is the right tool
- Masks instead of branchy loops
- One weight is applied to each asset column
- Terminal-only sampling avoids unused path dates
Before you start
The full lesson, with worked examples and exercise solutions, is for members.
Read the full lessonNew to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.