Skip to content

Why Yet Anohter Cashflow Engine

Shawn Zhang edited this page Jun 20, 2022 · 13 revisions

Why yet another cashflow engine

Why Haskell ?

I've tried with clojure and python to develop cashflow engine for structured finance while it is quite challenging:

cashflow in structured finance involves hundreds of data types(either asset types in the pool or tranches type), it also involves with differnt fee types and account types. all of these combination types will boost the complexity of computation and poses a huge burden on brain.

I tried with clojucture/clojure which prevails in nested data structure using specter, it is a killer in dealing with deal/transaction as it has nested components like pool assets bond/liabilities fees etc. But I failed to continue expanding as the code base as it is heavily relying on core.match/pattern match, unfortunately that package seems slowing and no-one is fixing backlog issues.

PyABS/python has introduced the pattern matching in 3.10 to solve that and having a great community support like numpy/pandas library. While it failed in maintenance cost : it is hard to refactor and scale up the code base in line with the complexity world of structured finance. A minor changes in code may secretly introduce bugs if there isn't any rigorous testing framework in place.

Both two languages created a lot of headache with dynamic programming language: every time a new feature introduced, there were some landmines created and will explode in runtime some day.

After months of hunting(actually years) => haskell is quite nice fit IMHO.

  • Modelling capability => Most important For example, Account may or may not bear interest. In Python

    {"name":"Acc1", "Interest":{"rate":0.1}}  // account with interest rate 
    {"name":"Acc1", "Interest":None}   // account without interest rate 1
    {"name":"Acc1", } // account without interest rate 2

    Then, the code will create branching to deal both cases:

    if "Interest" in acc :
        int_rate = acc["Interest"]
    else:
        pass ...

    this if/else or branching will grow rapidly when more characteristics came in, like reserve taget balance etc. In haskell it handles it nicely: data Account = String (Maybe InterestRate)

    calcAcc (Account name Nothing) = ..
    calcAcc (Account name (InterestRate rate)) = ..

    it just would ease the way to handle the complexity of building cashflow models for ABS/MBS

Why Another Cashflow Engine ?

Clone this wiki locally