“Python or C++ for quantitative finance ?” is as older than the quantitative finance itself. And, of course, if we try to find the best option for so many years, it means that it is not a Boolean answer (Python or C++). We need to nuance our answer because sometimes Python is the best, sometimes it is C++.
The real question (that we will answer here) is “Which one is the best for me?”
1. Python versus C++: Strengths and weaknesses in quant finance
Each strength comes generally with a weakness. For example, C++ is really fast, but the code is more difficult to maintain because of the variables scope. On the other hand, Python is much easier to use, but less efficient than C++. That was only one example, now let me give you a non-exhaustive list of the strengths and weakness of Python and C++ which impact a lot of our choice depending on the quantitative finance project we are working on:
FIGURE: Strengths and Weaknesses for each language
C++ | Python | |
Popularity | Low | High |
Simplicity | Low | High |
Speediness | Very High | From Low to High |
For ML & AI | Not very used | Most used language |
Rapid Prototyping | No | Yes |
Compiled | Yes | No |
So, in two words, C++ is harder and more efficient, and Python is easier but less efficient. So, depending on the efficiency you need in the computation, you will choose the good one.
Keep in mind that killing a mosquito with an AK-47 is too much but trying to fight an elephant only with a knife may probably kill you… All of that to say, each goal needs the right tool. (Examples in the next section)
2. Quant trading application for Python and C++
As mentioned in the previous section, there is not a best universal language for quantitative finance, there is the best for you!
Python in Quantitative Finance
Python is amazing to have a quick code that works very easily: in other words, perfect to save time. If you are dealing with a database with fewer than 1 million rows, with not a lot of computation, Python is perfect. Let me give you a few examples:
- Day-Trading Strategy / Swing Trading strategy
- Features analysis on 4-hour timeframe, 15-minute timeframe …
- Ticks processing (even if you can have much more than 1 million rows, it will just take more time)
- Backtest a trading strategy
- Plot insightful graph about the structure of your data very easily!
- Live Trading execution for trading strategy with a small-time computation
It is a non-exhaustive list, but all these propositions have one thing in common: if they take time, they are not in the live trading execution process. For example, ticks processing in quantitative finance can take 2 hours, 5 hours, or 10 hours maybe, but you just can go to sleep and the morning find your output without worrying yourself.
C++ in Quantitative Finance
On the other hand, C++ is here to help you when the speediness and efficiency is not a choice anymore but a necessity. Let me give you some examples:
- High Frequency Trading.
- Backtest on a dataset containing more than 10 million rows.
- Live trading execution for trading strategies that need a lot of computation done instantly (book order strategies, derivative pricing).
As you see, C++ is helpful only for some specific things. Indeed, Python is too slow for High-Frequency trading, or if you want to backtest a strategy (without vectorization) with more than 10 million rows because it can easily take 1 or 2 days, even 1 or 2 weeks if the code is not well done.
Join Our Newsletter
Be the first to receive our latest quant trading content (personal notes, discount, new articles).
3. The Best Programming Language for Quantitative Finance
In my opinion, Python is the winner 90% of the cases: for the research, to use Machine Learning, to use libraries, to use quantitative models, to deal easily with some databases, to create a trading strategy more quickly, …
But of course, for the specific cases I mentioned, especially the High Frequency Trading (HFT), C++ is the king and I have never seen any books or articles doing HFT using Python which is obvious.
On my personal research, I use essentially Python and I’m also using more and more Julia, to process my ticks, because it is very close to Python but nearly as fast than C++.
To conclude, we can highlight the main point of this article: there is not one best language, but the best language for what you are doing. Python is much more user-friendly, with a lot of ready-to-use codes thanks to the libraries. But, Sometimes, Python is too slow for some specific cases (high frequency trading or scalping on very small timeframe essentially) and that’s where we need to use C++.
Join Our Newsletter
Be the first to receive our latest quant trading content (personal notes, discount, new articles).
Lucas Inglese
Lucas is a self-taught Quantitative Analyst, holding degrees in Mathematics and Economics from the University of Strasbourg. Embarking on an independent learning journey, he delved deeply into data science and quantitative finance, eventually mastering the disciplines. Lucas has developed numerous bots, sharing his insights and expertise on LinkedIn, where he regularly posts content. His understanding and empathy for beginners in this complex field led him to author several books and create the comprehensive “Alpha Quant Program.” This program offers e-learning videos, monthly projects, and continuous 7-day-a-week support. Through his online courses and publications, Lucas has successfully guided over 67,000 individuals in their pursuit of knowledge in quantitative finance.
Related Posts
Trading Backtest Explained – 3 real life exemples
Understand how to implement the different methods to do a backtest is good. But knowing how to use them to
Why using Monte-Carlo Simulations in Trading?
If you are interested by quant finance, you should have heard about Monte Carlo simulations in trading. However, the concept
Robustness testing – Find reliable trading strategies !
Doing a backtest is good. Be able to trust it is better! That’s where the robustness testing takes place. Indeed,
The Walk Forward Optimization in trading
Backtesting in not a research tool, ok fine! we have understood it! But, if we can’t optimize our parameters using
The 6 Biggest Portfolio Backtesting Mistakes
If you are backtesting a single trading strategy or you are doing a portfolio backtesting, you need to avoid the
The Scientific Backtesting Guide
If you are here, you know that backtesting on the historical data is clearly not enough to obtain the reliability