Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Jane Street Tech Blog 14 min read Deep dive mediumAdept

Computations that differentiate, debug, and document themselves

Jane Street's OCaml library Gradient_calculator represents numerical cost computations (margin, financing, capital) as expression trees, so one definition can be evaluated, automatically differentiated, debugged and documented. It uses forward-mode automatic differentiation. The evaluation cost stays roughly proportional to the cost of the function itself, and the team chose it over reverse-mode because their computations involve few nested chain-rule applications. The same tree structure produces expect-test-friendly printouts of every intermediate value, which catch bugs on unexercised branches, and generates LaTeX formulas so documentation stays in sync with the code. Existing tools like JAX, OWL and ocaml-torch were rejected for poor OCaml interop or a tensor-centric model that didn't fit equation-style computations.

Assumes: OCaml basicspartial derivativesgradient descent

Related posts

  • Writing a DSL for high performance parallel programming in OxCaml

    Jane Street Tech Blog hardMaster

    A Jane Street intern built a JIT compiler for an SPMD-style DSL in OxCaml so SIMD kernels for options pricing and risk checks can be written once as ordinary-looking OxCaml functions instead of architecture-specific C intrinsics. Kernels describe the computation for a single output index, and the compiler generates the loop, which keeps each iteration writing exactly one output and makes vectorization safe. The front end builds a GADT-typed DAG that tracks uniform vs. varying rates and provides three control-flow forms (select, if_, if_var) with different evaluation semantics. The backend uses OxCaml's runtime metaprogramming (quotes and splices) to emit OxCaml code, partially evaluating runtime-known values such as the chosen distance metric away and relying on the OxCaml compiler for further optimization.

  • What the interns have wrought, 2021 edition

    Jane Street Tech Blog mediumAdept

    Jane Street's 2021 dev internship (87 interns across New York, London and Hong Kong) is showcased through three projects. One extended the OCaml syntax extension ppx_typed_fields, which uses GADTs to make record fields first-class values. It now supports parameterized and nested records, and a new typed-variants extension does the same for variant types. A second built filterable cross-day time-series exports of historical atop process data for the CLI and web UI. A third added memoization of intermediate computations to Datafetcher, a Haxl-like OCaml DSL for data-fetching jobs that run in production, test or record mode.

  • What the interns have wrought, 2025 edition

    Jane Street Tech Blog hardMaster

    Jane Street's 2025 intern projects include an index-aware evaluator for JSQL, the company's internal SQL dialect, which over-approximates key ranges from WHERE clauses and specializes execution to Map, Hashtbl or multi-index containers, giving ~700x and ~30x speedups on 3.8M-row benchmarks. A redesigned ocamltorch API uses OxCaml's local mode and refcount scopes to free GPU tensors deterministically instead of forcing Gc.full_major calls. A third project is a shared-memory library that passes pointers between trading processes instead of serializing data, using atomic refcounts and OxCaml visibility modes (read_write, read, local) to enforce race-free, borrow-checker-like access.

  • Flex Model: an event-driven feature engineering system

    Jane Street Tech Blog mediumAdept

    Flex Model is Jane Street's OCaml framework that turns market events into feature vectors for neural-network trading models, replacing a 17k-line monolith where adding one feature touched nineteen files. Incremental was rejected because its cutoffs and update coalescing silently drop history-dependent events. Flex Model instead splits each feature into per-event handlers that update state and eval functions that compute values on demand, giving up runtime graph changes to keep history inside the graph. A startup planner compiles feature dependencies into per-event-kind action lists run without cutoffs, avoiding unpredictable branches and letting teams add new event types without touching the core. The hot path is allocation-free, checked with [@zero_alloc]. Unboxed floats from OxCaml cut tail latency by about 25% in one test replay.

  • What the interns have wrought, 2022 edition

    Jane Street Tech Blog mediumAdept

    Three Jane Street intern projects from 2022 show substantial tooling work in OCaml. magic-trace gained a sampling mode that can cover 20 seconds to 20 minutes on Intel or AMD hardware, plus multi-process tracing, CPU-frequency transition reporting and a perf dlfilter backend that speeds trace decoding by 10–50%. Datafetcher jobs can now be compiled into Incremental computations, using a Response_or_waiting type to represent async state and mandatory memoization of fetch nodes. Quickcheck gained a [@@contract] syntax for deriving property tests from interface signatures, along with early support for bisimulation testing of two implementations of the same API.

The quest for software engineering knowledge.

Look:
Layout: