Python You Need to Know to Work in Finance, Trading

Python is the big thing in finance at the moment. If you’re a trader and you’ve never coded before, the big question is how much Python do you need to know? Do you really need to give up evenings and weekends to become a proficient coder?

Well, no matter what you’ll be coding, it’s important to know the basics; these concepts will be similar across various programming languages. You’ll need to be able to answer questions such as:

  • What’s a variable?
  • What are data types?
  • What are ‘if’ statements?
  • What’s a function?

For trading, specifically, you will need to know how to download market data from sources such as Bloomberg and Quandl in Python. There are libraries that make that easy to do, such as findatapy (Disclaimer: Yes, I’ve written it, but it’s free and open-source).

Then you’ll want to start number-crunching market data.Pandas is a great tool to learn for this. If you want to dip your toes into machine learning, there’s also scikit-learn. However, personally, I’d recommend trying to understand the basics behind the various machine learning techniques, rather than simply learning how to call functions in scikit-learn.

Once you’ve learned how to code a script that can analyse the market, you’ll need some new skills. You’ll want to plot your output. My favorite tools for visualization in Python are matplotlib and plotly, and you’ll need to learn at least one of these.

Is that enough Python to get you going as a trader? Well it depends what you want to do! If you’re the only person using the Python code, and it’s not mission-critical, then that’s a good start already. However, if you want to start giving your code to other folks on the trading desk, you need to get happy with the “engineering” bit of Python. This means learning about software design and making your code reusable (copy and paste is not the code reuse I have in mind!). Also don’t forget about unit tests to make the code less brittle in production. It means understanding how to fetch data and store it in databases.

If you’re taking your coding to this level, you’ll also need to know how to make your computation more efficient and be able to distribute it. That way it will be able to run in parallel, making it much quicker. This is especially important if you’re dealing with high-frequency data.

You may also want to make it easier for users to interact with the code without needing to know Python. Key to this will be creating an Excel interface (every trader likes Excel!), using a Python tool like xlwings or a web GUI using the flask and dash Python libraries.

My experience is that all the “engineering” bits can often take more time to code than the numerical “calculation” parts. I’ve spent nearly two years developing a Python library for transaction cost analysis, and the number of lines of code for the numerical calculations have ended up being a tiny proportion of the codebase compared with those parts for data loading, visualizations, etc.

It can be pretty daunting to learn Python if you’ve never coded before, but it is doable if you put in the time and in the long run. One way to get a head start is to do a crash course in Python that covers a number of different topics we’ve discussed. But you’ll then need to put this into practice, by sitting down and coding yourself.

Saeed Amen is the founder of Cuemacro. Over the past decade and a half, Saeed Amen has developed systematic trading strategies at major investment banks including Lehman Brothers and Nomura. This article originally appeared in eFinancialCareers.

One Response to “Python You Need to Know to Work in Finance, Trading”

  1. It would be worth mentioning PyXLL, the Python-Excel add-in, too. It’s much more powerful and a lot faster than xlwings. It’s not free, but in a professional environment being able to write a full Excel add-in using Python is a lot better. Using PyXLL you can write user defined functions (including RTD, async and multi-threaded) as well as macro functions, menus and ribbon toolbars with no VBA.