if there is one…
As a professor of computing, I’m sometimes asked “Which programming language is best?” The answer depends significantly on the application, but there are other important factors as well…
If you’re building a company around code, the commitment to a particular programming language is an important business decision. I know of well run fund management companies that rely on C, R, C++, Java, MATLAB, ML, Python and PERL. I’ll bet there are others that rely on Visual BASIC, Mathematica, and assembly language as well.
a checklist…
Here’s a checklist of considerations you might think about when making this decision:
- Which language do you think in best?
If you’re the lead developer or CTO, at least some consideration should be given to the languages you’re able to develop in most fluently and easily. This will enable you to participate more effectively in setting the direction of your company’s code. A closely related consideration is: Which languages provide the best expressivity for your tasks? Many quants like to manipulate large matrices, and MATLAB is very good at that, as is Python/NumPy, which has a similar notation for matrices.
- Will you be leading a large collaborative team?
In this case you may need to give priority to languages that provide well-defined interface boundaries so that programming tasks can be partitioned easily between developers. Java is probably the best alternative in this case, and C is probably the worst.
- How important is speed?
If you’re code must make split-second trading decisions, you’ll probably have to be writing in C or C++. It’s my opinion that a culture of “machismo” has arisen around these languages that leads to an overemphasis on speed, and prevents developers from making thoughtful decisions in this regard. Yes, these are the fastest languages, but there are costs for development management and systems reliability. C/C++ is the language most susceptible to memory leaks and other sorts of bugs. These languages are also more difficult to develop in collaboratively.
You can often get the performance of C in other languages through library calls. MATLAB for instance makes strong use of underlying C libraries.
- How well does the language span your company’s tasks?
Some languages, like R, are great for modeling, but don’t have the robustness or speed you might need for execution. Other languages, like Python, are pretty good at both ends of the spectrum.
- What about multiple languages?
Avoid if at all possible. It’s best if your developers are all thinking in the same language, and can be re-targeted to different coding tasks within the company. I once led a project in which our team used 4 different programming languages. It was a nightmare. There are a number of reasons this was a bad choice: Most critically we created problems for ourselves at the boundaries between the languages.
On the other hand, I can imagine some situations where a combination of two languages might make sense. I know of a fund for instance, that does their modeling in R, but their execution in C (because they’re an HFT shop).
- How strong is the developer community?
R, Python (NumPY) and MATLAB lead in this arena. They all have strong communities developing code for numerical analysis and quantitative finance. R is especially strong in the finance community; many academic researchers do their work in R. There’s even an annual R in Finance conference that’s worth attending even if you’re not a R user. The numerical analysis community in Java seems to have evaporated over the last few years.
- Open source or closed source?
Even though MATLAB is a great choice for quant work, the fact that it is a closed source platform is sometimes problematic. The developer community is slowed a bit in this environment. And even if you’re using an open platform (like Python) you might consider a proprietary library, e.g., for optimization. Consider the costs of these choices carefully — and I don’t mean just the licensing costs.
We chose Python…
In the end, our company (Lucena Research, LLC) chose Python. Here’s why: I came to appreciate the power of MATLAB’s matrix syntax during my time at Cerebellum Capital. It’s very expressive and well suited for quant work. But I didn’t like the closed source model of MATLAB. Python offers the sam syntax plus the power of the active NumPy community. We also discovered a very nice open source toolkit for financial time series called Pandas.
Finally, we’re not an HFT shop, so we weren’t constrained by a need for speed. I should say though that Python’s numerical routines are written in C and Fortran, so we get the best of both worlds.
Some related links…
- Picking the right programming language for your startup: Former facebook developer choses Python
- Another startup programming language article
Michael
August 2, 2011
Thank you for this article.
Knowing a couple of languages myself, I was wondering what do you think of PHP in regards to Phyton.
Tucker Balch
August 2, 2011
Hello Michael,
PHP is best suited for handling website interaction. I don’t think it is a good choice for serious infrastructure code.
Tucker
Vicky Sajnani
October 22, 2011
What are your views on Mathematica?
Tucker Balch
November 11, 2011
Sorry not to respond sooner. I have not worked with Mathematica, but I understand it supports financial modeling very well. If you’re comfortable using Mathematica already, keep using it. But if you are just now going to learn a language in that space (modeling) though, I’d recommend R because that’s what most people use and it has a strong community and an annual conference.
I would not use Mathematica or R for really implementing a trading system that would interact with the internet.
dankamongmen
July 10, 2012
A mix of CUDA, x86 assembly with SSE and AVX extensions, C for the U/I and disk access, and 800 lines of Make. Also XML for a man page.
Pheiku
July 20, 2012
Hi, just wanna point out that the link to “Another startup programming language article” is broken (hovering the link shows http://http//kevindewalt.com/blog/2009/10/14/the-best-programming-language-for-a-lean-startup/). You may wanna fix it.
Jonathan Charlton
September 26, 2012
What do you think of ADA?
Tucker Balch
October 31, 2012
I think ADA is a decent language, but it doesn’t have a big following, and not much in the way of numerical libraries. So I don’t consider it a good candidate for finance/trading.
Dennis M Senyonjo
October 2, 2012
Hi Tucker,
Thanks for your very insightful posts. As a developer who leans more toward the functional paradigm (Primarily Erlang…though I use Clisp for my pet projects when I get the chance) though I also use OO languages like C++ regularly. I would like to know what your opinion is on functional programming usage in computational finance, it potential merits and de-merits.
Being new to Computational Finance and Financial Engineering, I personally can’t say much from the finance/economist mindset, but I do know Goldman Saachs uses Erlang significantly,while Jane Street and LexiFi use Ocaml Primarily.
I found that functional programming is closer to the mindset of most of the quants. Again, it is not accidental that Matlab, originally created by a physicist, is functional. When prototyping, I am always using functional languages because of the way I think about the problem at hand.
Last, but not least, compile-time correctness is easier to force in functional languages, but typically (unfortunately) there is no time for such a high quality programming in practice in languages like Java.
Ian Smith
October 16, 2012
Well, go gives you the convenience of notation of python but with the performance of C/C++. For details of the benchmark in question, see http://blog.golang.org/2011/06/profiling-go-programs.html
Offshore Company
December 18, 2012
Amazing! I’m truly enjoying the layout of your blog. Are you using a custom made template or is this freely available to all users? If you don’t want to say the name of it out in
the general public, please be sure to contact me.
I’d really enjoy to get my hands on this template! Many thanks.
psteckler
December 22, 2012
I can’t say I’m enamored of Python — no typechecking, highly stateful.
There is a trend towards using typed functional languages at financial institutions. Another poster mentions Jane Street Capital, which is the world’s largest OCaml shop. Credit Suisse and Standard Chartered have been pioneers in the use of Haskell. And, I’m told, some quants are using F#, which is based on OCaml, but runs on .NET.
psteckler
January 1, 2013
Did you look at GNU Octave, which is an open source package similar to Matlab?
Andrew Ng uses it for his Machine Learning course on Coursera. I found it to work pretty well, though I’m unsure of how fast it is.
Note that I did not use the word “performant”, out of principle. :-)
Cássio Pagnoncelli
January 8, 2013
There’s the point that Octave seems to be in the very early development for quant; tt doesn’t offer you a framework where you can have the facilities Matlab, R, Python, and others give. If you are interested in doing something different, Mathematica is moving some efforts in the latter versions; it’s a very strong and powerful tool but don’t expect performance from it –it’s aimed to symbolic computation.
It’s also known VB is widely used in industry. I don’t trust writing programs in M$ plataform, neither running a live strategy in a Uindous platform.
I’d do all the work in C/C++, but there’s absolutelly no facility to deal with matrices (compare with Matlab or NumPy, for example). Maybe, the best choice for developing Buy&Hold strategies lies in one of Matlab, Python, and R.
Elroy Serrao (@enygmatic_in)
September 30, 2013
Any particular reason why you chose Python over R? Was lack of ready interfaces to the internet the only reason ?
Tucker Balch
October 7, 2013
R is not robust enough to run as a server. It is also kind of a kludgy language that does not submit well to software development cycles.
Edgar's Creative
December 6, 2013
Reblogged this on Edgar's Real Edge and commented:
A very special Post. Reblogging from a former Coursera Tutor of Computational Investing I