为什么对冲基金和金融服务经常使用 OCaml?
在与许多量化分析师/对冲分析师交谈时,我得出的结论是,他们中的很多人似乎都在使用自制语言或 OCaml 来完成许多任务。他们中的许多人无法回答为什么。
我当然可以理解为什么他们大多数情况下不想使用 C++,但为什么 OCaml 在这些用途上比其他脚本语言(例如 Python、Ruby 等)更优越?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
尝试阅读 Yaron Minsky 和 Stephen 所著的Caml 交易 - 华尔街函数式编程的经验几周(抱歉,虽然这篇文章以前是在 Jane Capital 免费托管的,但现在已经不存在了,所以我留下了 ACM 链接以供参考)。他们详细介绍了他们认为 OCaml 的优点和缺点,尽管他们在很大程度上认为 OCaml 比他们考虑的大多数其他选项更好(即没有与 C++、Python 进行大量直接比较) ,你有什么)。
作者在 Jane Street Capital 工作,该公司在 OCaml 代码方面投入了大量资金。
更新:另请参阅线程什么算法交易软件是用编程语言编写的?。其中一条评论提到了Yaron Minsky 在卡内基梅隆大学发表了有关 Jane Street Capital 对 Caml 的使用的演讲。大约一个小时,非常有趣。
更新二:Yaron 编写了另一篇概述,这次是针对 ACM Queue,名为 面向大众的 OCaml。
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.
例如,请参阅编程语言大战以进行速度比较:
现在,我们都听到了有关谎言、该死的谎言和基准的说法,因此建议持保留态度——但这是一个相当不错的比较。归根结底,一个人如何处理自己的问题和数据很重要。
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.
首先要记住的是,尽管 OCaml 具有 REPL 和清晰、简洁的语法,但它并不是像 Python 或 Ruby 那样的动态语言。它具有静态类型并编译为本机代码。
对于定量分析,脚本语言更方便。您可以访问很多库,可以轻松地编写快速而肮脏的脚本来管理信息,即使对于非程序员来说,构建中小型程序也很容易。
为了创建实际参与交易的算法和系统,您需要像 OCaml 这样的东西。 OCaml 的主要优点是它的功能性、可读性(它的可读性几乎与 Python 等动态语言一样好)、可靠性,但主要是速度。 OCaml 比大多数人想象的要快得多 - 它比 C 快(实际上比 C 稍慢,但比动态语言快很多很多倍)。 OCaml 的速度足以创建 HFT 系统,这是 Python 或 Ruby 无法比拟的。
另外,请记住 Jane Street(最有声望的 OCaml 传播者)在 Scala 和 Clojure 出现之前就采用了 OCaml。
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.
作为一种函数式语言,它本质上是数学的,这可能非常适合这些公司需要解决的问题类型。正如其他人指出的那样,它具有良好的性能特征。
也许这就是微软为 F# 选择 OCaml 的原因
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#
因为它速度极快(而且比 C++ 简洁得多)。
Because it's blazingly fast (and far more succinct than C++).
Jane Street Captial 接手 Don 的帖子后,甚至还专门建立了一个 OCaml 页面,其中包含进一步链接到他们的 OCaml 参与(包括博客)。- OCaml 的性能通常是一个很大的争论,但是我认为“宽客”也喜欢它,因为函数范式非常适合他们的分析工作,所以我认为他们是早期采用者。然后公司发现它同样适合系统编程。
更新:链接大多已损坏并且无法轻松更新。如今,Jane Street 似乎不再直言不讳地谈论他们与 OCaml 的合作。
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.
我不在这样的地方工作,所以这些只是我为什么会在他们的位置上做这件事的猜测:
它通常比 Ruby 和 Python 这样的语言快很多,而且作为一种静态类型的函数语言,它通常是更容易推理代码并知道它不包含细微的错误。 (是的,单元测试也应该有助于发现这些问题,但是最好能额外保证您的财务数据不会搞砸。)此外,函数式编程与数学的联系非常紧密,比大多数高级语言更紧密地联系在一起范式(例如,不存在面向对象的数学分支),因此它擅长对它们实际所做的事情进行建模。
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.
与 Python/Ruby 相比,并行化微不足道?至少对于 F# 来说是这样,但出于同样的原因,Caml/OCaml 也应该如此。
尽管我很喜欢 Ruby,但它并不是我处理主要是数学或聚合的繁重任务的首选,而且 Python 和 Ruby 都还没有对多线程提供真正强大的支持。
由于模式匹配和对不变性的偏好,相对复杂的计算管道的简洁性(在 Ruby 中更难实施,在 Python 中稍微容易一些,但仍然比基于 ML 的语言更难)对于大型数据集的计算来说是最有价值的。
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.
根据我对定量分析的经验,它是使用 C# 的 VBA(即 Excel),有时也使用 f#。我个人不知道有任何 Quants 使用caml...
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...