Choosing a Programming Language for Quantitative Finance
Summary
The document compares Python and MATLAB as starting languages for quantitative finance, with additional views on R and Julia. One answer favors Python for its open source ecosystem, broad community, general-purpose uses, and extensive libraries, while noting that MATLAB has strong built-in risk tools. It argues that performance concerns can often be addressed through compiled extensions or tools that translate numerical functions into faster machine code.
Other respondents recommend R for its statistical libraries and established data science community, or Julia for combining high-level scientific workflows with compiled-language performance. One answer warns that Python numerical packages may depend on C or C++ beneath their interfaces, creating extra complexity when researchers need to implement specialized algorithms. These are personal assessments, not a systematic benchmark or a definitive industry survey. The best choice depends on goals such as employability, available packages, cost, and whether the learner expects to build performance-sensitive libraries.
Key ideas
- Python is presented as a flexible, open source language with a broad package ecosystem and community.
- MATLAB is credited with useful built-in tools, including for some risk management tasks.
- Compiled extensions can speed up Python numerical work, though some libraries rely on C or C++ components.
- R is recommended by some respondents for statistical and data science work.
- Julia is proposed as an option for combining high-level workflows with compiled performance.
- The language choice depends on practical goals and is based here on personal opinions rather than comparative evidence.
Tags
Full text
# MATLAB or Python as starting language? # MATLAB or Python as starting language? 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. ## Answer by Helin (score 7) https://quant.stackexchange.com/a/59733 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: - 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. - 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. - 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. - 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. - 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). ## Answer by user42108 (score 6) https://quant.stackexchange.com/a/59730 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. ## Answer by rvignolo (score 2) https://quant.stackexchange.com/a/59726 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! ## Answer by vonjd (score 1) https://quant.stackexchange.com/a/59736 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.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.