I taught a guest lecture tonight to the Baruch MFE program about using Python and pandas for financial data analysis. Many thanks to Alain Ledon and Norman Kabir for inviting me to teach the class. Here are the slides from the first 40 minutes:
I spent the remaining 90 minutes or so going through a fairly epic whirlwind tour of some of the most important nuts and bolts features of pandas for working with time series and other kinds of financial data. Been a while since I've done a talk like this— I usually am talking to a more general audience that don't want to hear about quant finance! I did a number of fun applications:
- Computing rolling 3 year betas to the S&P 500
- Grouped regression of MSFT on AAPL returns by year and month
- Plotting heatmap of daily and monthly stock correlation matrix (this one got some "ooh"s and "ahh"s)
- Minimum tracking error portfolio optimization problem and lite backtest Here is the full PDF of the IPython notebook and a zip file of the IPython notebook and supporting files themselves. Note that the notebook requires a recent GitHub snapshot of statsmodels. I also use the quadratic programming solver in CVXOPT for the portfolio optimization application: if you don't have CVXOPT, you can change it to use the brute force BFGS optimizer (though it's about 50x slower).
See my prior blog post with some more details about installing and getting set up with the IPython notebook.