Python for Financial Data Analysis with pandas

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.

    IPython Notebook PDF Output
    IPython Notebook and supporting files

    • http://profiles.google.com/jev.kuznetsov Jev Kuznetsov

      Very neat, thanks!

      [Reply]

    • Thomas Maloney

      Thanks for the talk Wes, the time series stuff was really cool.

      [Reply]

    • Xxx

      your supporting files included dependency to qqplot. Where should I get this?

      [Reply]

      Wes McKinney Reply:

      My apologies. You can comment out the qqplot import in demo_support.py. I will post a new zip file with it removed so others don’t have the same problem when they try it out :)

      [Reply]

    • Simon Thornington

      Just stumbled across all of this (python, pandas, scipy/numpy) as I rapidly reached the end of my rope in Excel. A thousand times thank-you, you’ve saved me god-knows how many hours of coding, and I get to learn python besides.

      [Reply]

    • Jacob Irwin

      Wes, can you share url to the audio or video for this presentation?

      [Reply]