This post is part of a series of Reading Lists for Beginner Quants. Other posts in the series concentrate on Derivative Pricing, C++ Programming and Numerical Methods:
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 and PyPy, it is beginning to make in-roads into the realm of scientific computing, and hence derivatives pricing.
Many quants will already be seasoned C++, R, MatLab or Java developers. 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 old 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: Powerful Object-Oriented Programming. 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, consider Mark Pilgrim's Dive Into Python 3. 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 David Beazley 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
- Beginning Python: From Novice to Professional - Hetland
- Learning Python: Powerful Object-Oriented Programming - Lutz
- Dive Into Python 3 - Pilgrim
- Programming Python - Lutz
- Pro Python - Alchin
- Python Cookbook - Beazley et al
- 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.