#### Need to know

• More banks and other financial firms are turning to functional programming as an alternative to the dominant approach known as imperative.
• Advocates of the functional style say it results in code with fewer bugs as it is stricter, and easier to check and to test. And fewer flaws mean fewer weaknesses for hackers to exploit.
• The fans argue functional languages are better for performing multiple tasks at the same time, due to in-built concurrency constructs, and are also a good fit for distributed ledgers.
• Distributed ledgers may find a wide application in the derivatives industry with the adoption of Isda’s common domain model, designed with the emerging technology in mind.
• But the spread of functional programming may be constrained by a relatively small pool of skilled developers, as well as its memory and speed drawbacks.

Would you like your software to be more reliable, harder to hack and cheaper to run? Then, if you aren’t already in on the act, it may be time to embrace functional programming – a maths-based approach that is challenging the status quo at financial firms.

Proponents of functional languages say they are better at handling certain financial operations than the dominant, so-called imperative languages. They will become even more relevant, these fans argue, with greater adoption of the distributed ledger technology (DLT) in finance, spurred in part by the International Swaps and Derivatives Association’s common domain model (CDM).

“Functional programming has been gaining popularity in banking for the past decade, but the pace is accelerating,” says Neil Mitchell, who has worked with functional languages at Credit Suisse, Standard Chartered and Barclays. He is now a senior product architect at Digital Asset, which builds DLT products for financial firms and counts ASX, the Australian securities exchange, and the Depository Trust & Clearing Corporation (DTCC) among its clients.

“It’s likely a combination of success stories, greater compatibility with existing systems and more experienced senior engineers with functional programming skills,” he explains.

For banks and trading firms using functional programming, its appeal lies in a number of ‘magical properties’ that are absent or less common among imperative languages.

For instance, the so-called strong typing feature prevents mundane coding errors such as the programmer accidentally typing in a letter where there should be a number, while easier testing catches other mistakes before a program is run.

Code written in the functional style also tends to be more concise because functional programming works by telling the computer what the desired result is, rather than by spelling out the steps it should take to achieve the result – as imperative languages do. Simpler and shorter code is easier to check for bugs.

Fewer flaws in the code mean fewer weaknesses for hackers to exploit.

“The ability of the [strong] type system to catch [mundane] errors allows us to spend more time thinking about other, deeper issues in our code and drives down our error rate, making it possible to move faster while still maintaining safe and reliable systems,” says Yaron Minsky, co-head of the technology group at liquidity provider Jane Street.

The firm, as it puts it, writes “everything that we can in OCaml”, a functional language, and employs 300 OCaml developers.

OCaml has another advantage: it is better-suited for concurrent computing than imperative languages, such as C, Java and Ruby. The same goes for the other languages on the functional spectrum used in the financial industry, such as Clojure, F#, Haskell and Scala.

Concurrent programs excel at complex tasks, involving many simultaneous actions. They are faster than sequential ones if run on a parallel computer – a computer with more than one processing unit or core – and most computers today are multi-core. Concurrent programs also make better use of available hardware, whether it has only one or many cores, and reduce the need to buy or rent additional servers.

### Bulletproof code

Functional programming is not new – the first functional language was developed in the late 1950s. But historically, imperative languages had substantial memory and speed advantages when applied on hardware that existed at the time. And so, in a nutshell, imperative programming came to dominate.

But as technology advanced, hardware became much less of a constraint, prompting a closer look at functional programming. Fast forward to today, and the previously niche approach has made its mark at a number of banks and trading firms, including Goldman Sachs, Trafigura and AQR.

“When I started functional programming commercially, at a bank in 2008, I knew everyone in the Haskell community. It was hundreds, maybe a thousand people – I at least knew their institution. Now I don’t know most of the people,” says Mitchell at Digital Asset.

As other devotees of functional programming, he singles out the strong typing present in main functional languages – F#, Haskell and Scala – although it also exists in some conventional languages.

The feature alerts the programmer when an inappropriate data type has been entered into a memory field – say, a decimal number where a whole number should be. Importantly, the mistake is reported before the program is run, allowing it to be fixed before it does any damage.

“It is similar to ‘spell check’, which flags spelling and grammatical errors,” says Mitchell. “If you are running finance applications, you’d much rather have the developer get a compile error before they push their code, rather than have your system operator get a runtime error at 4am because the entire reconciliation batch just failed.”

Digital Asset is using a proprietary functional language inspired by Haskell in its work to replace ASX’s clearing and settlement system for the Australian equity market. The exchange, which expects the new system to go live in March or April 2021, has described the project as “a once-in-a-generation opportunity to deliver material benefits for the securities industry and the broader economy”.

Like Mitchell, Mas Nakichi of financial technology firm Axoni stresses the reliability of functional programs – essential for mission-critical applications, “such as aerospace engineers launching rockets, which is where a lot of functional programming is home to right now”.

A project Axoni is participating in, which will process “trillions of dollars” of contracts, calls for the same kind of bulletproof quality, according to Axoni’s head of strategy and business development.

#### 7 days in 60 seconds

###### Compounding, venue disruptors and the Fed’s stress buffer

The week on Risk.net, January 11–17, 2020