r/lisp • u/nalaginrut • 1h ago
r/lisp • u/nanowillis • 13h ago
Common Lisp Portfolio/scenario simulation and plotting in fincl
aatmunbaxi.github.ioFor those that don't know, fincl is a quantitative finance library I've been working on for common lisp (I can only safely say SBCL at the moment). Its emphasis is on option pricing, with the goal of being an expressive and extensible DSL for a domain notoriously full of jargon and impenetrable programming constructs. It is a bit rough around the edges, but it's been a fun toy to play with so far.
I've written up some worked example of one of fincl's new features: simulation along synthetic paths. This allows users to take assumptions of how they think future markets might move and test strategies and log data against potentially thousands of possible futures; essentially a Monte Carlo simulation. In some sense, this is the opposite of backtesting.
The main piece is a macro that handles time grid generation, stepping logic, tracking of local variables, updating of markets, and recording of data. The data can then be fed to fincl's sister package fincl-viz, which writes simulation results to json to be fed into plotly. An example of this is in the write-up as well.