MATLAB or Python as starting language? [closed]

I have a fairly rigorous background in mathematics (last year of my undergrad in Pure Maths), and I have been exploring the world of Quantitative Finance as I explore what I might be able to do with my degree. Most of the material that has been suggested to me (mainly Quantitative Trading, Ernest P. Chan 2009) is quite dated, and so I am curious what are the main tools traders/analysts use today for data collection and backtesting. Most of the answers I am seeing are between Python and MATLAB, but I've seen decent arguments for both. Not even sure if this is the right place to be asking this kind of question but I'm quite new to this kind of stuff and most people here seem fairly knowledgeable.

• Sorry, I did not properly read that you focus on data collection and backtesting, hence I removed this sentence. My very own two cents: Often, it simply depends on where the senior quants got their degrees / PhDs, or whether there is a university professor on your team. I've seen teams build everything in Java (...because the prof wrote a book with Java code), or R; others built a humongous Matlab/Octave Lib. And some teams even bought the vendor lockin and went with Python for their Front Arena. Dec 3, 2020 at 13:54
• As someone who has used Matlab for nearly 15 years (five in academia and ten in trading) I would strongly recommend that someone starting out for the first time learns Python as their first language. Dec 3, 2020 at 15:13
• I've used both in my career, and there are many similarities. Seems like Python has come into favor more in recent years, possibly because it's "free" and more widely used. Honestly I'd try them both and compare.contrast. There's nothing (that I know of) that you can't do with either. Dec 3, 2020 at 15:59
• A very warm welcome to Quant.SE! Thank you for your question. I have a clear opinion here, please see my answer below. Dec 3, 2020 at 20:25

These questions inevitably elicit strong responses. The truth is that both are excellent. I used Matlab when I first entered the industry, but have since migrated 100% to Python. I'll provide some quick reasons below:

1. Python is a general purpose language. You can certainly use Python to do computational finance, but you can also use it to automate just about everything. I use Python to scrape the web for data; I have built web apps using Python so that we can explore data more interactively; I've also worked on a silly app to archive/index every PDF I've read. You can do these with Matlab too, just not as intuitively.

2. Python is open source and free. Matlab is rather pricey. Even if cost is not a concern, it is much easier to explore how everything works when something is open source, which can be invaluable for learning. Python packages tend to be open source too. I've personally learned a great deal reading the code of some packages.

3. Python has an exceptional community. The community is much larger, which means getting help/support is likely easier (e.g., here on Stack Overflow). If you run into issues/find a bug, submit a bug report or even create a pull request yourself. I've had bugs fixed by package maintainers within hours. With Matlab, you likely have to wait until the next product update.

4. The Python community has also created some truly remarkable packages to do just about everything. Here, you can see a mapping I attempted between Matlab toolboxes and potential equivalents in Python. I have to admit, for some risk management stuff I did, Matlab's built-in toolboxes are exceptional, but over time I've managed to find/build equivalents that work just as well, with a ton of added flexibility. Python has also become one of the most popular languages in the AI field, with an excellent support community of its own and lots of packages you can readily use in your own projects.

5. A lot of people complain about Python's performance. In my opinion, it is a non-issue. There are so many ways to make your code run orders of magnitude faster and they involve very little extra learning. For example, with a few simple numba decorators, you can have Python functions automatically translated to optimized machine code. You can also use Cython to greatly speed up your Python code, without actually learning C/C++. Take a look at this page, which is a component of the excellent statsmodels package for Python. Some very impressive benchmark results are available at the bottom (incidentally, against Matlab).

You might also want to consider R. Like Python, it's open source and has a large number of libraries.

My impression is Python and R are currently the most popular languages for quant finance, with Python ahead of R. As a result, if one of your goals is employability in the field, Python might be a better choice.

Between Python and MATLAB, I would choose Python. It is open source, has many libraries and it is object oriented. Also, its syntax is nice.

However, Python is slow.

If you are only a library user, you might think that Python is fast. This is because the library is running stuff in C or C++ under the hood. Python has the two language problem, where libraries rely in having code in both Python and something like C or C++ in order to be fast. This can be seen, for example, in the tensorflow repository, where 61% of the code is in C++. Another example is pytorch, where 53% is in C++.

At the beginning, these things might seem not important, but once you need or want to code a library to solve a specific complicated problem, you won't be able to do it in Python (unless an existing library already has the functions that you need, which will probably be in C/C++ and wrapped around Python). Or you will be able but it might be slow.

This will requiere that you learn C or C++ as well.

For those reasons, I will recommend you Julia programming language. It can be fast as C or Fortran and it can also work like Python, i.e. it solves the two language problem. It is easy to learn. Also, its community is full with people trying to solve scientific problems. It has amazing libraries that can be used for quantitative finance. You can write your own libraries in the same language. And many, many more features.

I hope this helps! Thank you!

• But does Julia come equipped with the libraries that developers have spent years on making? Furthermore, are there any specific quantitative finance libraries with Julia? For example, Python has Quantlib, zipline, yfinance, pynance, pandas to name a few, I'm not sure if Julia has the established resources that are necessary and specific for Quantitative Finance. Dec 3, 2020 at 15:01
• Hi! Well, QuantLib is in C++, not in Python, so if you want to extend the library, you have to program in C++. As I previously said, if you are just a library user, Python is ok. On the other hand, Julia has many libraries for finance. For example, it has the best library in the world for Numerical Solutions of Stochastic Differential Equations. Instead of pandas, you have DataFrames.jl, which is much better. Also, you can call any Python library from Julia and use its results. Btu the main reason why I recommended Julia is for developing performant libraries in a unique language. Dec 3, 2020 at 15:22
• Please, refer to this library and start looking at the Julia community. You will be surprised. I hope this helps. Of course you will have to take a time (a couple of weeks at least) to digest everything to see what Julia is about. Thank you very much! Dec 3, 2020 at 15:24
• Saying a language "is slow" is disingenuous. You can write incredibly slow matlab code (and I'm sure Julia code) if you don't structure it properly. i.e. Matlab is finely tuned for linear algebra, but there are python libraries that do set-based operations incredibly fast. I know nothing about Julia so it's not a knock - but this seems very biased and opinion-based. Performance is not the only consideration when choosing a language to learn. Dec 3, 2020 at 15:56
• Yes, there are fast Python libraries that rely in C/C++ code, for sure. I will repeat what I have already said before: Python is great if you are a library user but if you want to code your own library, you might have to use C/C++ to achieve performance (this is the main reason why pytorch, tensorflow, numpy and many other libraries are coded in C++ and python and not just in python). In julia you can write a performant library using only julia. I am not saying python is bad! I use python as well! Dec 3, 2020 at 16:03

I think the best language, especially for QuantFinance, is R!

You can find some arguments in my blog post here: https://blog.ephorie.de/why-r-for-data-science-and-not-python.

Python tries to be everybody's darling whereas R has always been a statistical language, built by statisticians for statisticians. Quant finance mainly is statistics and there is no bigger and more sophisticated ecosystem than the R ecosystem when it comes to data science.

For some use cases see the QuantFinance category on my blog: https://blog.ephorie.de/category/quantitative-finance.