1.3. Why Should Traders Learn Python?

It should now be clear that learning to code is a worthwhile and rewarding goal, but you might still be wondering why this course - indeed our whole business - is focusing specifically on teaching Python for traders. A lot of nuance goes into the design and selection of programming languages, and there's a handful of questions you may have when you think about it:

  • What's the deal with different programming languages anyway?
  • Why are there so many different languages? Don't they all do the same thing?
  • Why would somebody use one language instead of the other?
  • How do I know Python is the right one for me to learn?

At risk of sounding trite, it's common to compare different programming languages to different tools in a toolbox. They vary in their syntax, structure, verbosity, usage, speed, safety, libraries, communities, and at the most fundamental level, they vary in the way a programmer's brain thinks about solving problems when writing code in that language. To make this less abstract, let's take a look at some code examples of identical programs written in different languages.

Comparing Python, Java, and JavaScript

Let's walk through some code snippets that do simple computational tasks to get a feel for the differences in the languages. Since this may be your first time seeing code, don't get too bogged down with trying to understand all the details of how it's working. Instead, I want you to focus on the appearance of the different languages and how they seem to express the same idea in different ways.

There's a long history in computing that the first program you write in a language is called "Hello World" - and it simply prints out the words "Hello, World!" to the terminal, as if the computer is announcing its existence to the world.

Check out how "Hello World" is written in Python, Java, and JavaScript.

In Python, it takes just one line:

In Java, it takes a few more:

And in JavaScript, it's just one line again, though now it's referencing some sort of console thing as well:

Each one of these programs does nothing more than write a single line of text, but notice how different the Java one looks compared to the others. It's also clear the Python code is frankly as simple as anything could be, having only one instruction that sounds like plain English: print("Hello, World").

In addition to the syntax, different languages require different workflows. For example, the Java code must go through a compiler before it can run - this is another program that takes in Java code and returns a binary that can execute directly. However, the Python code can be run as it is, without this extra step, because the computer can interpret it on the fly. The consequence of this difference is the Java code will typically execute faster, but it takes more work to develop it.

Again, don't worry too much about the details here if this isn't making complete sense to you yet – the bigger picture will become clearer to you as you learn more – but hopefully this provides a quick example of what programming languages look like. Let's build off that to examine what makes Python specifically the best choice for you to learn as a beginner and as a trader.

Python is an excellent language for beginners

Python is a general-purpose programming language with thousands of high-quality, free libraries available and a simple syntax that makes it read like English.

It does everything you need.

Everything listed below and more is both possible and easy to do with Python:

  • Automated financial data collection, cleaning, and consolidation 
  • Compute custom summary statistics over large datasets 
  • Create aesthetic and interactive visualizations from large datasets 
  • Rapidly research, experiment, and present conclusions with Jupyter notebooks 
  • Build statistical models for forecasting price, returns, volatility, etc. 
  • Rigorously quantify the correlation relationships between predictive variables 
  • Utilize machine learning to understand structured and unstructured datasets 
  • Build options pricing models using Monte Carlo methods 
  • Connect to an exchange API for sending orders and receiving market events 
  • Automate trade execution based on custom rules
  • Backtest a trading algorithm on historical data

It has a low learning curve.

Python was designed with several high-level abstractions that let the programmer focus on their data and logic without being bothered by low-level details of how things happen at a granular level inside the computer. A Python programmer doesn't have to worry about things like memory management, string representations, buffer overflows, or other issues found in languages like C++ and Java.

As you've already seen, the syntax and program structure of Python is incredibly simple as well. There are just 3 main data structures (lists, dictionaries, and sets), 10 main data types, and 5 fundamental constructs comprising the language (variables, loops, conditionals, functions, and classes). There are no curly braces, semi-colons, or boilerplate required to write a valid program.

It's widely used and accepted language in the industry.

Lastly, if all the above wasn't enough to convince you of Python's value, take comfort in the knowledge that everyone else is already using Python everywhere in finance and trading. It's become the lingua franca of the industry, and your skills in it will be immediately transferable to any trading desk or fund that also uses it. There are also widely used, open source software packages targeting Python that are extremely useful for financial applications, like pandas for data manipulation and zipline for strategy simulation.

Other languages add complexity and hassle

Python boasts a comprehensive and ever-growing library ecosystem specifically tailored for finance and algorithmic trading. Libraries such as NumPy for numerical computations, pandas for data handling, and Matplotlib for data visualization, along with dedicated financial libraries like Zipline and PyAlgoTrade, provide an extensive toolkit for traders to quickly and effectively build and test their algorithms. In contrast, Java and JavaScript have fewer specialized libraries for algorithmic trading, which can limit the ease and speed of development. Users may need to write more code from scratch or seek third-party tools, adding complexity and time to the development process.

Python's syntax is renowned for its simplicity and readability, making it highly accessible for traders who may not come from a traditional programming background. This simplicity allows traders to focus more on their trading strategies rather than getting bogged down by the intricacies of the language. On the other hand, Java, known for its verbosity, requires more lines of code to accomplish similar tasks. This can make the codebase larger and harder to maintain. JavaScript, while versatile, often shows inconsistency in behavior and requires understanding of its asynchronous nature, which can be a hurdle in synchronous trading logic.

Python enables rapid development and testing, which is crucial in the fast-paced world of trading where market conditions change rapidly. The dynamic nature of Python allows for quicker iteration and testing cycles, whereas Java, being a statically-typed language, requires explicit type declarations and longer compilation times, slowing down the development process. JavaScript, primarily used in web development, can introduce additional complexities when adapted for server-side applications or data analysis tasks in trading, which are more naturally suited to Python’s capabilities.

Running and managing Python code is generally straightforward, with environments like Jupyter Notebook offering an interactive, user-friendly interface for coding and data analysis. Java and JavaScript environments, in contrast, often require more setup and configuration. Java needs a compilation step, and managing dependencies can be more cumbersome. JavaScript, while not requiring compilation, often necessitates a more complex setup, especially when used outside the browser context, like in Node.js for server-side applications.

The Python community is vast, with a wealth of resources available for learning and troubleshooting, including forums, tutorials, and extensive documentation. This is particularly beneficial in algorithmic trading, where community support can significantly accelerate problem-solving and learning. Java and JavaScript, while also having large communities, lack the same level of focused resources in the domain of finance and trading.

While Java and JavaScript are powerful in their respective domains, for algorithmic trading applications, Python’s simplicity, extensive libraries, and supportive community make it a more efficient and less cumbersome choice. It allows traders to develop, test, and deploy trading strategies with less hassle and more focus on the core aspects of trading.

The Bottom Line: Python is the First & Foremost Language for Traders to Learn

Complete and Continue