Python is an open-source scripting language that is widely used in quantitative finance, from simple data manipulation to building prototypes of mathematical models. Python is not a new language, compared to Perl, Lua and Ruby; however, the popularity of Python increased dramatically in the last 10 years. Here are four reasons why Python is better than sliced bread:
- Python is highly readable. Unlike many other languages that use sets of braces (e.g. in bash script) or keywords (e.g. in VBA, MATLAB) to build code blocks, Python makes use of whitespaces. This fairly unique characteristic of Python enforces strict indentation, which results in a higher visually organised code. The high number of English keywords in Python syntax also makes it similar to pseudo-code and closer to the English language (at least for English-speaking individuals).
- Python codes are short. Python codes are generally shorter than other programming languages. This is because Python has built in high-level data types and dynamic typing. Appropriate uses of lists, tuples, dictionaries, generators and slicing, reduce the amount of lines of code without sacrificing readability, and hence increase productivity.
- Python has strong third party supports. Popularity is key to a successful open-source language. The more popular a language is, the stronger the developer community is. Python and its users benefit from this popularity by having an extensive set of libraries where active development is underway. Good examples are NumPy/SciPy for statistical modelling, SQLAlchemy for database access, PyMC for probabilistic programming and Ployly for graph plotting. For retrieving financial data, Bloomberg has built an API, blpapi for python, and Thomson Reuters’s API is currently under development.
- Python is Object Oriented. Python supports object oriented (OO) paradigms with strong data structure. During the development of Python, one of the goals was to bring “all objects that could be named in the language (e.g., integers, strings, functions, classes, modules, methods, etc.) to equal status. They can be assigned to variables, placed in lists, stored in dictionaries, passed as arguments, and so forth” – [Guido van Rossum The History of Python]. Having equal status in every object reduces the amount of lines required for a safe OO implementation (Rule of Three is not needed). In addition, the flexibility of Python in terms of OO is high – e.g. user-defined operators overloading is supported. These attributes make Python a strong language for object-oriented programming (OOP).
- Python and other scripting languages have common limitations, notably the speed when compared to lower level languages like C/C++. However, the choice of programming languages should always be based on the business requirements and the resources available.
Many banks now require skilled resources in Python or knowledge of Python for programming roles. As the regulators continue to demand more transparency and require banks to perform large-scale analysis, the demand for Python as a programming language can only grow.