Saturday, December 17, 2011

Learn Python - Reading List

Python is rapidly gaining traction in the quant finance world. Many of the top quant forums contain more and more questions every day about how Python can be used in quantitative finance. This article will present a list of textbooks that are suitable for learning Python from the ground up to an intermediate level.

Python, at least in the financial engineering world, originally began life as the "glue" between other codes written in compiled languages such as C++ and Java. However, with the advent of projects like NumPy, SciPy, Unladen Swallow and PyPy, it is beginning to make in-roads into the realm of scientific computing, and hence derivatives pricing.


What is the return on investment for this group by learning Python? The list of benefits below sums up what the language has to offer:

  • Python is designed from the ground up to encourage maintainable, readable and reusable code. It has great support for particular paradigms such as object-oriented programming.
  • Python code is usually around a quarter of the length of code generated by C++ or Java - less typing, less debugging and less maintenance.
  • Python does not need to be compiled or linked, which allows for a more iterative programming style and a quicker development cycle.
  • Python is extremely portable. Code can be easily exchanged between Windows, Mac OS and Linux with little to no modification.
  • Python comes with a staggering array of standard libraries and mature third-party projects. Web development, scientific computing, operator system access and network scripting are all supported.
  • Python can talk with many other languages easily. It has support for invoking C and C++ code and can itself be called from libraries written in these languages.

Python presents a comprehensive list of benefits, but where does one begin learning the language? Fortunately, there are plenty of high quality textbooks and guides available to help a beginner learn Python.

Textbooks for Beginning Python


As with the previous article on C++, an initial consideration is which software framework will be used to develop the code. There are many Integrated Development Environments (IDE) for Python. The main contenders are Eclipse/PyDev, IDLE, Komodo, IPython and the good ol' command line.

In the author's opinion, the best book to learn the syntax and basic usage of the language is with Mark Lutz's Learning Python. It is an extremely weighty tome at just under 1200 pages, but it will give you a great introduction into how to use Python code effectively. It is currently in its 4th Edition, which covers Python 2.6 and 3.x, which is roughly where the language is now. Highlights of the book include differences between 2.6 and 3.x code (very useful for porting) and an in-depth look at object-oriented programming. QuantStart recommends this book highly.

For a more rapid (and less forgiving) introduction to the language, the best resource is to be found at the Dive Into Python website. Mark Pilgrim has made his famous ebook freely available in HTML or PDF format. It can even be purchased from Amazon. DIP is designed for seasoned developers who are aware of intermediate level programming concepts but need a quick introduction to Python syntax. The tutorial can be worked through quickly and it will provide a good flavour of what Python can achieve.

Another beginner book of note is Magnus Lie Hetland's Beginning Python: From Novice to Professional. It takes a project-based approach and provides multiple iterations of the same solution in order to see how the code life-cycle evolves. This is particularly useful to beginning programmers.

Python Textbooks for Seasoned Developers


Once the basic concepts are grasped, it is time to learn how to program production applications in the right way. For this one needs to be aware of both the more advanced features of the language as well as software engineering practices in general.

Mark Lutz's Programming Python provides an in-depth treatment of GUI programming, network programming and database integration. On top of that it devotes a chapter on connecting Python with C++, which is very useful for quant devs who are ready to give Python a go. Another book that really takes intermediate Python programmers to the next level is Marty Alchin's Pro Python. This book explains how to code in a highly 'Pythonic' way, making use of the advanced features of the language such as generators and list comprehensions.

Two more books worth mentioning are the Python Cookbook, by Alex Martelli et al. and Foundations of Agile Python Development by Jeff Younker. The first has many recipes for text and file manipulation, time and money, searching, databases, threading, system admin etc. Definitely one to keep on the desk. The second book concentrates on Agile practices as applied to Python software development, including chapters on version control, unit testing and functional testing. Both are fantastic "shelf" resources for a solid quant dev team.

Summary and Suggested Reading Chronology


  1. Beginning Python: From Novice to Professional - Hetland
  2. Learning Python - Lutz
  3. Dive Into Python - Pilgrim
  4. Programming Python - Lutz
  5. Pro Python - Alchin
  6. Python Cookbook - Martelli, Ravenscroft, Ascher
  7. Foundations of Agile Python Development - Younker

The books at the end of the list can be read in any order and are usually specific to the particular domain at hand.