Over the past few weeks, I’ve chatted to quite a few people who are starting to learn Python primarily to analyse financial markets and all of them were keen for a bit of guidance of where to start. Hence, I thought it would be useful to collect together a few thoughts on the subject in this blog article. You could argue that “coding” is easy, but unfortunately it takes some time to get to grips with it, if you’ve never seen a programming language. After all the complexities of a real human language are far more subtle. However, the difficulties in a programming language is that there is less ambiguity, hence, in order to “speak” it, you need to be a lot more precise about your grammar and how you “speak” to a computer.
First, if you’ve already coded before, it’s fairly straightforward to get the gist of the basics in Python, understanding the syntax etc (although you’ll still need to spend time understanding all the various libraries). It’s still worth however, quickly going through a basic Python tutorial, to specially see the differences. There are also specific tutorials floating around on the web, if you’re used to other programming languages eg. MovingToPythonFromOtherLanguages. I’ve listed a few Python tutorials below, but it is by no means an exhaustive list below:
- The Python Tutorial – Python Software Foundation (this is the one I used a few years ago!)
- learnpython.org – where you can actually run Python in your browser
- Think Python: Think like a computer scientist
If you haven’t coded before, it’ll probably take a bit more time to go through the tutorials, but I think it’s worth it! I started coding when I was a kid. However, when I got to university, I ended up relearning how to code, as I’d picked up a lot of poor programming habits, making variable names too short, not bothering to properly understand what object oriented programming is and so on. I guess the moral, is to have a bit of direction, when you learn to code, whether that’s from teachers, books, YouTube tutorials etc. so you you avoid picking up bad coding habits (eg. copy and pasting code is NOT code reuse!)
This way you can learn to program properly, and create nice code, that is easier to maintain and more readable. Sure, a lot of learning to code is about practice and indeed at each step of the way I’d recommend being proactive, reading a bit, learning, coding a bit etc. rather than spending weeks just reading, without writing a line of code. A lot coding ends up being trial and error, so the “practice” element is key to this process.
I definitely recommending reading about object oriented programming (OO) once you’re comfortable with the basics of Python. This is also actually relevant for many programming languages. In Python, you don’t have to code in an OO manner, but I personally prefer it, in particular because it makes it easier to build larger systems. Once you get used to it, it can be very intuitive. I’d also take time to delve into design patterns, which helps you structure your code for common concepts which come up again and again in systems.
- MIT OpenWare: Object-Oriented Programming (has examples in Python)
- Improve your Python: Python classes and object oriented programming
- Python Design Patterns: For Sleek And Fashionable Code
- python-patterns – sample Python code on Design Patterns
Before even starting a tutorial, I’d recommend getting Python installed on your computer. For data scientists one of the most common Python distributions is Anaconda. With Anaconda you’ll get a Python installation, plus a lot of useful Python libraries for data science, which will save you from installing them later. It’s also worth downloading a Python IDE to write your code. A nice IDE, which makes it easier to code, and quickly spots trivial errors in your code. Yes, you can just use Notepad to write Python and execute that code via command line, but whenever I’ve done that, it simply takes longer to write! here are a few Python IDEs you can try:
- PyCharm IDE – JetBrains (I use this!)
- Atom.io – Text editor, which has modules for Python
- PyDev – popular IDE for Python based on Eclipse
- Python Tools for Visual Studio – create Python code in Microsoft’s IDE
Focusing more on data science and more specifically finance, I’d also recommend going over tutorials for specific Python libraries and having a look at their GitHub pages. I’d also check out some of the books by Yves Hilpisch on Python in Finance. I’m also working on a chapter on Python in Finance in the new book STRIKE – Novel Methods in Computational Finance, which will be out on Springer in the coming year. I might write a full book on Python (if enough folks are interested?). Below I’ve listed a few cool Python libraries that are very useful for data science more broadly (which are also available on GitHub):
- SciPy stack – includes NumPy, pandas, SciPy etc
- NumPy – matrix algebra
- pandas – time series analysis (especially useful for finance!)
- SciPy library – numerical routines, including a lot on optimisation
- matplotlib – plotting for Python
Here are a few of my own open source Python libraries too (ok, this is a bit of a plug!) if you want to analyse financial markets and for backtesting systematic trading strategies, which are also on GitHub (below). One thing I would say with backtesting a trading strategy, is that to begin with I would try to familiarise yourself with the basic process in Excel first, rather than immediately leaping to Python.
- finmarketpy – analyse financial markets and backtest trading strategies with nice simple templates
- findatapy – download market data from a range of sources (Bloomberg, Google Finance, Yahoo Finance, Quandl etc) using a common interface
- chartpy – create funky visualisations using minimal lines of code using Plotly, Matplotlib and Bokeh backends
Aside, from books/tutorials, I’d also recommend going to Python meetups (generally free or low cost) and workshops/conferences (generally more expensive). In my case, I suspect going to so many Python focused events, was the main factor which made me want to start to using Python! If you are willing to dedicate more time, there are also quite a lot of Python bootcamps around, which last a few weeks (I haven’t been to any of these though, to know what they’re like). Many computer science courses at university now also have a Python element to them. So in short, there are lots of resources out there to learn Python. One of the most important resources which only you can provide is: time…! Best of luck on your search learning Python!