“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
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.
Obtain 1 week of content 100% Free !
- The Basics of Quant Finance
- The Biggest Backtesting errors
- The Scientific Backtesting Guide
- Prerequisites to break into quant finance
- Technical indicators in python
- Create your first Trading Strategy in Python
- Full Details about my ML Reversal FX Strategy
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++.