Skip to content
Python for Quantitative Finance / Scientific Python and data

Statistical Computation

A covariance estimate used in a risk report must identify its observations and divisor. A regression must identify its response and factors. This lesson connects NumPy calculations to those statistical objects, then checks a simulated option price against a closed form with a stated tolerance.

Learning objectives. By the end of this note you should be able to:
  • compute sample means and covariances with an explicit ddof choice and state what was estimated;
  • fit a one-factor OLS slope (e.g. excess return on market) with a normal equation or np.linalg.lstsq;
  • simulate a known model and assert the estimator or pricer lands near the closed form;
  • refuse to invent econometric theory beyond what the computation requires.

In this lesson

  1. Sample mean and covariance
  2. Least squares as a linear map
  3. Simulation check against a known formula
  4. Portfolio variance as a quadratic form
  5. What this note deliberately skips
  6. Hand-off to design and delivery

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.