Skip to main content
Education

Python and Its Tightening Grip in Finance

Kamran Khan, CFA

Introducing Python

The term “Python” has been coming up more and more in professional discussions lately, leaving many to wonder what all the hype is about. In response to those left wondering, Python is a programming language that is rapidly gaining general popularity, and has particular applications within the financial community.

Origins

The number of queries for Python has tripled over the past decade, while those for other major programming languages have been flat or declining.  Python is so popular that a July 2018 Economist article highlighted that, in 2017, American Google searches for Python outnumbered searches for Kim Kardashian. The TIOBE Programming Community Index, a measure of the popularity of programming languages maintained by the TIOBE Company in the Netherlands, shows that Python has grown so much in popularity that it currently ranks third in the Index, behind C (first) and Java (second).

But, despite the explosion in Python’s popularity in recent years—along with the rapidly growing need for better data science tools—Python is not a new language: it has, in fact, been around for over 30 years.

Python was created in 1989 by Guido van Rossum, a Dutch computer scientist. Frustrated by the inadequacies of existing programming languages, Van Rossum decided to create a new programming language—one that would be easy-to-use yet powerful. He wanted to emphasize code readability and a syntax that required fewer lines of code, and—importantly—he wanted it to be open source, so anyone could contribute to its development.

Most people assume that van Rossum named Python after the snake; even the logo of the Python programming language contains an image of two snakes. In fact, he named it after the BBC TV show as a big fan of Monty Python’s Flying Circus, and Monty Python references show up in various forms within the Python community.

Simple yet powerful

Python’s main advantages are its simplicity and flexibility, which have helped fuel its growing user base. It is a beginner-friendly language that can handle a large range of tasks.

Unlike some programming languages, which overwhelm users with parentheses, brackets, braces, commas, and colons, Python’s simplicity can be seen in the syntax. Python code is simpler, concise, and resembles the English language. It also offers elegant one-line solutions as an alternative to what takes a whole block of code in other languages.

The following statements illustrate how you would print Hello, World! in Java, C, and Python.

Java

class HelloWorld
{

  public static void main(String[] args)

  {

   System.out.println("Hello, World!");

  }

}

 

C

#include <stdio.h>

int main(void)

{

  printf("Hello, World!\n");

  return 0;

}

 

Python

print('Hello, World!')

Python is a general-purpose coding language, which means it can be used by different people to carry out a variety of tasks in many fields. It is used by software engineers, developers, mathematicians, scientists, data analysts, and accountants: even kids can use it.

Python is used in web development and game development, and can be used to create desktop or mobile applications. It is fantastic at automating routine and/or time-consuming tasks. As a web-scraping tool, Python allows you to extract large amounts of data from websites and is a favourite tool for people involved in machine learning and artificial intelligence. In fields that involve managing large amounts of data, like Finance, Python is commonly used for data gathering and manipulation, as well as for data analysis and visualization.

Given all these capabilities, Python’s appeal goes beyond the tech community, and many of those studying Python are looking to acquire skills that will help them in non-technical roles. Marketers may use Python’s data science capabilities to measure the effectiveness of campaigns, for example, and journalists can use Python code for research by scraping the web for data.

With Python’s usefulness extending into many different fields, it is not surprising that many career sites have reported a significant increase in listings mentioning Python in the job description.

Python for finance professionals

There is a growing demand for Python across the finance industry as the programming language is being used more and more by researchers, analysts, and traders. Some financial firms have even incorporated Python into their training and continuing education programs.

An Oct. 24, 2019 Globe & Mail article “Investment managers need to become coders, says former CPPIB CEO,” has sparked a lot of interest in Python from finance professionals. Bogdan Tudose, a principal and instructor at The Marquee Group, has noticed more people enquiring about Python and how it can help them in their roles.

Bogdan delivers a variety of courses at The Marquee Group that focus on financial modeling, data sciences, and programming (including Python). He notes that many finance professionals initially get exposed to programming as they advance their Excel skills and start to utilize Excel VBA (Visual Basic for Applications). “Excel has limitations,” Bogdan cautions. “When you’re working with large amounts of data, it’s not as easy to process in Excel, even using VBA.” While Excel’s limit is about a million rows, Bogdan notices performance issues after exceeding 10,000 rows of data.

Python is a lifesaver when it comes to automating mindless tasks to dramatically improve productivity, such as scraping reams of data from the web and organizing it for further analysis. Bogdan cites private equity firms, for example, that use Python to scrape retail store location data for competitive analysis of a specific industry.

“It would take countless hours for several employees to manually gather this data. With Python, you can do it
with a few lines of code.”

Python also offers a wide range of analytical tools to clean, analyze, and visualize financial data. Some of the most popular Python packages harness machine learning and AI by crunching large quantities of data to pick out otherwise imperceptible patterns.

Python is used extensively in trading strategies, when it is often necessary to sift through massive amounts of data, and for statistical analysis, risk analysis, and portfolio optimizations—the list of potential uses goes on and on.

Supportive community

Whether new to Python or a long-time user, programmers can always find help from Python’s large user community, which supports users at all levels through online resources, forums, regional events, and local meetups. Users can easily find other Pythonistas (Python users) to seek advice, mentorship, and inspiration, or just to chat.

Python comes with a standard library that contains pre-packaged modules (files of Python code) that makes it possible to skip the process of coding many types of functions, and making for a more efficient coding process. As an open-source coding language, Python is free to use and anyone can modify or create extensions for the language. As a result, there is no shortage of packages (a collection of modules), libraries (a collection of packages) and frameworks (yes; a collection of libraries) for Python to fit anyone’s specific coding needs.

Pythonistas have uploaded over 100,000 custom-built software packages to an online repository known as the Cheese Shop (another Monty Python reference). These tools cover a very wide range of subjects, and can be installed and inserted into a Python program with a few keystrokes. Whatever a user is thinking of doing, there is a good chance someone else has done it before and made the tools available to the Python community.

Getting started with Python

There are extensive resources available for those interested in learning Python. While some programming background obviously helps, people can still learn Python even if they are new to coding.

The Python Software Foundation hosts a free Python tutorial on their official website with extensive material tailored towards beginners. Sites like learnpython.org and python-guide.org have additional tutorials available. Codecademy offers tutorials along with hands-on lessons, where learners actually get to write some code.

And, of course, there are countless Python videos on free sites, like YouTube, along with paid course providers such as Udemy and Coursera.

For those who prefer something more interactive, search out CFA Society Toronto's website for upcoming events (pre-Covid, CFA Society Toronto had planned introductory and advanced 'Python for Financial Professionals' sessions). These comprehensive full-day sessions will be taught by instructors from The Marquee Group. Stay tuned for future sessions, or check out The Marquee Group for alternate scheduling.

If the thought of learning something new (especially a programming language) seems a bit overwhelming, consider that Python is one of the most popular languages amongst kids—and give it a try!

Kamran Khan, CFA, has over 20 years of experience in investment management, with over 10 years managing U.S. and global equities. He is currently managing director of Khan Financial, which offers financial advisory and consulting services.

Back to top arrow