The question I get asked most is, what is your favourite burger joint? The answer.. well, you’ll have to ask me! The second question I get asked a lot, particularly in recent months, is how can I learn Python if I’m working in finance? I will endeavour to answer that question, updating and adding to articles I’ve written before.
If you work in finance there are lots of good reasons to learn Python. It can help to automate all those boring Excel spreadsheet updates. It’s also a good transferable skill that is useful in any industry where you’re working with data. Python is also becoming more of a requirement for many roles in finance. When I started working in markets in 2005, lots of people coded, but mostly it was IT and quants like myself. These days you’ll likely find folks coding in many desks of a bank or on the buy side.
It can help to motivate learning Python, if there’s a particular task you’re looking to solve, whether it’s automating a particular spreadsheet, backtesting a trading strategy etc. Whatever path you choose, it’s important to practice coding to learn to demonstrate what you’ve learn through tutorials and workshops. There is no shortcut, but with perseverance you will learn.
Installing Python, learning the basics and Pandas etc.
I’ve also written a tutorial on my GitHub teaching site, showing you how to install Python and all the various Python data science libraries you will likely to need (on Windows/Linux and Mac). Once you’ve installed Python, you can learn the basics of the Python language, the syntax, control flow etc. A good place to start in the official Python tutorial. and this is what I used when I started to learn Python many years ago. Later on, it’s worth starting to browse through the official tutorials for some important libraries you’ll need for data science, in particular NumPy (for matrix like operations) and Pandas (for time series). Time series are everywhere in Python, so understanding Pandas really is key! There’s also some videos on websites like DataCamp for data science, which can help.
Learning Python for finance
Once you’ve gone through the tutorials above, it’s time to get into specific Python use cases for finance. You’ll need to learn how to download market data (no data.. no results!), doing tasks like backtesting a trading strategy, event studies etc. My free open source library findatapy has many examples on downloading market data from many sources including Quandl and Bloomberg. My library finmarketpy helps you to backtest trading strategies and do tasks like event studies. Again this includes many examples, including this one for a simple trend following strategy.
I’ve developed a Python for finance workshop, which I’ve taught at banks, funds and also at Queen Mary University of London, where I’m a visiting lecturer. I go from the basics in Python, data science libraries, to backtesting and also developing web dashboards in Python, as well as integrating Python with Excel, with xlwings etc. Many of the things I have done during my day job as a quantitative strategist. If you’d be interested in me teaching my workshop at your firm or university, let me know, and I can send you a syllabus. I can also teach it over Zoom given current circumstances. For individuals I’m also teaching Python on the next QDC starting in January (also includes material on languages like kdb+/q).
Moving on to more advanced Python, alternative data and machine learning
If you’re happy with stuff like Pandas and tasks like backtesting in Python, it’s worth thinking about using Python with funkier datasets and more advanced use financial cases. Alexander Denev and I have recently coauthored The Book of Alternative Data: A guide for investors, traders and risk managers discussing how you can use alternative datasets in financial markets.
I’ve created a Python/alt data/NLP/large dataset workshop, partially based on the book. We go over using Python to work with alternative datasets, like images and text, as well as libraries for dealing with large datasets like Dask and PySpark. Let me know if you’d like me to teach this course too at your firm.
In terms of machine learning, I’d strongly recommend the new book Machine Learning in Finance by Matthew Dixon, Igor Halperin and Paul Bilokon which is a great reference on the topic and also includes lots of Python code.
Software design, version control, testing and deploying
A big part of writing code is making sure it is properly written. And no, it’s not an excuse saying I’m a developer, and hence my code can be a mess! At one level this can include simple things like commenting your code and making sure that each function is properly described. This is not just for others in your team, but for you. There is no way I will remember why I wrote something a year from now! If code is designed properly, it makes it easier to maintain. This includes understanding topics thoroughly like object oriented coding and also design patterns. I did a few software design and engineering modules at Imperial during my degree, and to this day I still use the ideas learnt from those courses everyday.
By using version control software like Git you can track your changes more easily and is very important when working in a team. Using unit tests can make your code robust. These automated tests can be run every time you make major changes to your code, to check it still works, and gives you piece of mind. I use Python pytest library for writing my unit tests. For deploying your code, you can create your own conda environments for clients to replicate. For more complicated projects you might want to distribute them with Docker, which automatically sets up all the non-Python dependencies too, like databases etc.
My open source library, tcapy, for doing transaction cost analysis uses many of these ideas, including automated testing and deploying through Docker. I’ve also written it in a very modular way to make it easier to maintain and add new features. Check out the code here on GitHub!
Conclusion
The above was just a very brief summary of how you can go about learning Python for finance, and later more advanced topics like using alternative data (and there’s lots of stuff I haven’t included, which you could also learn). Whatever path you choose, it’s important to reiterate that tutorials/workshops can be part of the learning process, but it is also necessary to spend time coding too. If you’ve got any questions about me teaching my workshops at your firm or university let me know!