This site collects notebooks that take a model or method from finance and implement it end to end in Python: pulling the data, solving the problem numerically, and looking at what comes out. Each notebook is self-contained and shows all of its code, so it can be read on its own or used as a starting point for your own work.
Some notebooks use data from WRDS, which requires a subscription to reproduce. The rendered results are stored with the site, so the pages read the same either way.
Portfolio Choice
Implementing the Critical Line Algorithm Trace the mean-variance frontier with short-sales constraints using the Critical Line Algorithm of Markowitz, which builds the frontier from segments joined at corner portfolios, and check it against a numerical solver on real stock data.
Implementing the Minimum-Variance Portfolio Estimate the global minimum variance portfolio of the 100 largest U.S. stocks from a rolling 60-month window, where the sample covariance matrix is singular, use short-sale constraints to make the problem solvable, and compare the resulting long-only portfolio to the value-weighted market with CRSP data.
Recursive Utility
Exact Value Function for Recursive Utility Solve the exact nonlinear boundary-value problem for the continuation value in a one-factor Gaussian endowment economy, and measure how far the equilibrium objects are from the local affine approximation.
Option Pricing
Calibrating the Heston Model Implement the Heston closed-form option pricing formula in Python and calibrate the model to AAPL call prices by minimizing the root mean-squared pricing error.