minrk/scipy-tutorial-2011 — Issue #1: mcdriver.py shape mismatch
Author: hpaulj
Created: 2011-10-24 18:11:50+00:00
State: open

In mcdriver.py, the 3 arrays used for plotting do not match in shape.

prices.shape = (n_strikes, n_sigmas)
strike_mesh, sigma_mesh = np.meshgrid(strike_vals, sigma_vals)

strike_mesh.shape == (n_sigmas, n_strikes), the transpose of prices.

np.meshgrid is a bit confusing in this regard. np.mgrid produces arrays with the shape you apparently expect, but is 'called' with slices, not arrays.

This error is hidden to the casual user because the default invocation uses the same size (5) in both dimensions. But the contour plots are wrong (as shown in the tutorial text). The call should have lower values for lower sigmas (and higher strike prices).