Why do hedge funds and financial services often use OCaml?
Asked Answered
C

9

30

Speaking to a number of quants / hedgies, I came to the conclusion that a large number of them seem to be using either a homebrew language or OCaml for many tasks. What many of them couldn't answer was why.

I can certainly understand why they wouldnt want to use C++ for the most part, but why is OCaml superior for these uses compared to other scripting languages, say Python, Ruby etc?

Cameraman answered 17/12, 2009 at 20:31 Comment(3)
Honestly, other than Jane Street Capital, I am not aware of any other hedge funds or financial services using OCamlDenison
What do they use then if not OCaml other than C++ or Java?Straticulate
GS uses a proprietary language called slang efinancialcareers.com/news/2017/05/slang-goldman-sachs Think of it as a horrible version of Perl.Shayna
P
29

Try reading Caml trading - experiences with functional programming on Wall Street by Yaron Minsky and Stephen Weeks (apologies, while this article used to be hosted for free at Jane Capital, it is no longer there, so I leave the ACM link for reference). They go into great detail about what they feel are the advantages and disadvantages of OCaml, though they for the most part take it as a given that it is better than most other options they considered (i.e. not a lot of direct comparisons with C++, Python, what have you).

The authors work at Jane Street Capital which has invested heavily in OCaml code.

Update: See also the thread What programming language(s) is algorithmic trading software written in?. One of the comments mentions a presentation Yaron Minsky gave at CMU on Jane Street Capital's use of Caml. About an hour long, and very interesting.

Update Two: Yaron has written another overview, this time for ACM Queue, called OCaml for the Masses.

Pincushion answered 17/12, 2009 at 21:30 Comment(3)
Link to Caml trading paper broken. Do you have a link to the full text? Everywhere I looked, you have to pay for journal accessDemulcent
Sorry, looks like Jane Capital no longer hosts it. I tried finding it elsewhere but it is only at ACM. I'm leaving that link for folks who can access it. Oddly, the StackOverflow links are broken/missing as well. Anyone have any idea what happened to them or how to restore them?Pincushion
The linked thread and associated comment are dead, but the talk is here youtu.be/hKcOkWzj0_sAdscription
L
16

See for example the programming languages shootout for speed comparisons:

Now, we all heard the line about lies, damned lies and benchmarks so grains of salt recommended -- but this a fairly well done comparison. At the end of the day it matters what one gets done with one's own problem and data.

Laywoman answered 17/12, 2009 at 20:38 Comment(2)
+1 for this! That's the speed they crave with the function as first class objects and multiple tail recursions they enjoy.Whorish
shootout.alioth.debian.org/u64q/… seems not for OCaml vs Python, but for OCaml vs HaskellDenison
A
13

First thing to keep in mind, is that even though OCaml has an REPL and clear, succinct syntax, it's not a dynamic language like Python or Ruby. It has static typing and compiles to native code.

For Quantitative Analysis, scripting languages are more convenient. You have access to alot of libraries, it's easy to do quick and dirty scripts to manage information, and building small to medium programs is easy even for a non-programmer.

For creating algorithms and systems which actually engage in trading, you want something like OCaml. The main advantages of OCaml are its functional nature, readability (it reads almost as nicely as a dynamic language like Python), reliability, but mostly speed. OCaml is much, much faster than most people believe - it's C fast (actually slightly slower than C, but many, many times quicker than dynamic languages). OCaml is fast enough to create a HFT system, which isn't something that can be said for either Python or Ruby.

Also, keep in mind Jane Street (the most vocal OCaml evangelist) adopted OCaml before Scala and Clojure came onto the scene.

Aculeate answered 11/12, 2012 at 13:18 Comment(1)
I realize that HFT is no longer as big a thing as when you wrote this answer in 2012 but might you know of any HFT systems written in OCaml ?Lohengrin
C
10

Being a functional language, it is mathematical in nature, which probably fits in nicely with the kinds of problems these firms need to solve. And as others have pointed out, it has a nice performance profile.

Maybe this is why Microsoft co-opted OCaml for F#

Colonist answered 17/12, 2009 at 20:40 Comment(0)
K
5

Because it's blazingly fast (and far more succinct than C++).

Kishke answered 17/12, 2009 at 20:35 Comment(0)
I
3

Picking up on Don's post, Jane Street Captial even has a page dedicated to OCaml, with further links to their OCaml engagement (including a blog).- Performance of OCaml is usually a big argument, but I think also the "quants" love it because the functional paradigm lends itself very well to their kind of analytical work, so I think they are the early adopters. And then firms discover that it is equally suited for systems programming.

UPDATE: The links are mostly broken and cannot easily be updated. Jane Street seems to be less outspoken about whatever remains of their OCaml engagement these days.

Irony answered 5/1, 2010 at 12:6 Comment(1)
They still have the blog and page section on oCaml janestreet.com/technology & blog.janestreet.com/why-ocamlLowlife
D
2

I don't work at a place like that, so these are just guesses as to why I might do it in their position:

It's generally quite a bit faster than languages like Ruby and Python and, as a statically typed functional language, it's generally somewhat easier to reason about the code and know that it doesn't contain subtle bugs. (Yes, unit tests should help catch those as well, but extra assurance that your financial numbers aren't getting screwed up is nice to have.) Also, functional programming is very closely tied to math, more so than most high-level language paradigms (like, there isn't an OO branch of math), so it's good at modeling what they actually do there.

Dy answered 17/12, 2009 at 20:46 Comment(3)
Couldn't you say category theory is the OO branch of math? There are plenty of functional ways of modeling category theory, though.Shaynashayne
If category theory is the OO branch of math, that would make Haskell an OO language. I don't see how OO languages strive to be computer approximations of category theory any more than any other language with a type system.Dy
I suppose so, but a fair amount of the theory of object systems comes from category theory. Granted, the ideas are far less abstract once turned into an OO language and they don't look very much alike.Shaynashayne
S
1

Trivial parallelization compared to Python/Ruby? At least this is true for F#, but should be true for Caml/OCaml for much the same reasons.

As much as I love Ruby, it wouldn't be my first choice for heavy-duty tasks that are mostly mathematical or aggregations, and neither Python nor Ruby have really great support for multithreading yet.

The terseness of relatively complex pipelines of calculations thanks to pattern matching and the preference for immutability (harder to enforce in Ruby, slightly easier in Python but still harder than in ML-based languages) are most valuable for calculations on large data sets.

Shaynashayne answered 17/12, 2009 at 20:39 Comment(4)
Parallelization is actually a little bit awkward in OCaml — the whole language has a global lock, so only one thread can be executing OCaml code at a time. You have to split off additional processes to use multiple cores or CPUs.Dy
Wow, that's a bummer. I guess that means it's on roughly the same footing as Python, except for all the nice pattern matching stuff and more pervasive immutability.Shaynashayne
@Chuck: You have multicore Ocaml now: github.com/ocamllabs/compiler-hacking/wiki/Multicore-OCamlRecalcitrate
Multicore OCaml is arriving, but I would also love to see OCaml adopt the Libuv library, so we could create evented servers a la Node.js, see: github.com/fdopen/uwtNoreennorene
D
0

In my experience of Quants it's VBA (read: Excel) with c#, or f# sometimes too. I don't know personally of any Quants using caml...

Dani answered 17/12, 2009 at 21:20 Comment(1)
yeah, i think in the vast majority of cases that is true, but there also seems to be a pretty substantial number (growing?) of cases where other languages / setups are being used for more involved processing...Cameraman

© 2022 - 2024 — McMap. All rights reserved.