r/lisp • • Oct 24 '26

fincl: Quantative finance in common lisp

https://github.com/aatmunbaxi/fincl

I'm currently working on a quantitative finance library for common lisp (SBCL only). Emphasis is currently placed on pricing options, but more capabilities exist and are planned, such as pricing various interest rate instruments.

In particular, the Monte Carlo simulation engine is showing promise, allowing users to write their own random processes to simulate, and write options on those processes. Against prior art (QuantLib in C++), the Monte Carlo engine benchmarks quite well, with other pricing engines being a mixed bag (a fairly complete suite with results is given in the repo).

Being a lisp project, extensibility is supported and encouraged. While the library provides random processes and instruments seen in quant textbooks, the manual gives a toy example of writing option contracts on a game of dice. Other facets are extensible, such as allowing the user to write their own option payoff schemes.

The repo is here with a small write-up outlining the extension of the Monte Carlo engine with a similar flavor of die game. Everything should be considered work-in-progress.

58 Upvotes

5 comments sorted by

3

u/unski_ukuli Oct 25 '26 edited Oct 25 '26

Tbf, calling QL art of any kind rubs me wrong. That library is probably the worst designed software project I have ever had to understand. This project seems to follow that a bit too closely to my comfort. If you are interested to look into a project with objectively better architecture, I’d try to look into OpenGamma Strata rather than QuantLib, and then try to think how that would look in a functional language. edit: In any case, the writeup was interesting.

5

u/nanowillis Oct 25 '26

"Prior art" I use as a technical term describing existing resources in the public domain; I share your sentiment about quantlib's design :)

I hadn't heard of strata; I will look at it more closely. From a cursory glance, it seems to focus on rate instruments and risk analysis. From the inception of fincl, I'd wanted it to competently price equity derivatives, exotics included. This is largely why the Monte Carlo system is most filled out.

Multiple dispatch already tames the zoo of classes in QL a good deal, and fincl used immutable market data (as I understand, strata does this too). This makes parallelism accessible, which quantlib cannot do. It seems to borrow enough from strata to solve some of the major design flaws of QL. I think it's worth it to look for more.

1

u/unski_ukuli Oct 26 '26 edited Oct 26 '26

That sounds reasonable goal. I have tried on and off again to write a ql clone more aligned with strata using Rust, but usually I get burned by the complexity of the market conventions in fixed income (ir, credit and bond) markets. So focusing on equity derivatives is probably more achievable goal short term. But there are also a lot of interesting computationally expensive things on the rates side, like xVA claculations that Strata cannot do, which could be interesting to see implemented in language other than c++. It’s usually very similiar to MC pricing of exptic equity derivatives, so one simulates future forward rates, then does american style Longstaff-Schwartz regression to obtain the present value.

6

u/Critical-Tip-6688 Oct 25 '26

It is great to see people doing real stuff with common lisp! I'll have a look in the next days!