FinTech, Insights
Mosaic Feature: Loan Reporting
We have introduced a new and strategically important feature into our proprietary platform (Mosaic); the ability to report on loans held within investment portfolios. A common feature in many portfolios, often in the form of a Lombard Loan (a loan secured against the liquid assets within a portfolio, typically to increase market exposure / leverage).
Key Design Considerations
In order to leverage as much of our existing codebase as possible, we decided to build the functionality of the ‘loan portfolios’ on top of the consolidated portfolio functionality that already existed in Mosaic.
We started by adding a new category of portfolio that could be included in a consolidated portfolio, a ‘loan portfolio’. Next, we added algorithms to calculate the net, gross, and loan balances of a consolidated portfolio. This additional calculations allow us to easily generate:
As well as calculate the leverage ratio by taking the ratio of either the net or gross balance against the loan balance.
Integrations with other parts of Mosaic
The most impactful integration of our loan functionality with another feature in Mosaic is the use of the leverage ratio within our investment restrictions module. We are now able to specify a leverage ratio limit against which a portfolio can be programmatically tested.
Challenges
We ran into an interesting issue when developing the leverage ratio part of this feature due to Ruby’s (a programming language that we use) slightly unexpected behaviour when dealing with dividing numbers with a decimal component (Floats, short for floating point numbers) by zero. Usually, it is pretty reliable that, if you divide any number by zero, you will get an error.
For instance, running the line 1 / 0 in Ruby will raise a ZeroDivisionError and crash the program.
Knowing this, we can account for cases where this might happen in our code and, when trying to calculate the leverage ratio, we can rescue any ZeroDivisionErrors and simply change the output to be something like ‘N/A’.
Unfortunately, Floats, unlike integers, in Ruby can return lots of different values depending on their value, e.g.
1.0 / 0 # returns Infinity
-1.0 / 0 # returns -Infinity
0.0 / 0 # returns NaN (not a number)
This ends up being pretty frustrating because we always want to say that the leverage ratio isn’t applicable if the loan value is zero without having to account for all of these various possibilities. Fortunately, there is a pretty useful feature in Ruby called ‘refinements’, which allow us to alter the way one of the base classes in Ruby work but, crucially, only within the scope that we choose. In this case, we refine Floats to always fail when being divided by zero within the scope of our consolidated portfolio code without altering its behaviour anywhere else. This is important as, if we altered the behaviour everywhere (commonly know as ‘monkey-patching’), we could create lots of bugs because other sections of the code base and developers adding new code might, and would, expect the normal behaviour.
This is what the resulting refinement code looks like:
module FloatRefinement
refine Float do
def /(denominator)
raise ZeroDivisionError if denominator.zero?
super
end
end
end
Then we simply specify within our consolidated portfolio code that we are using the refined version of Float by adding:
using FloatRefinement
Conclusion
By making use of functionality already present in Mosaic, we were able to simply and elegantly incorporate an entirely new feature which allows Enhance to provide more accurate and relevant reporting to an even larger subset of portfolios than we were previously able. The development team were only slightly hampered by some slightly unexpected language behaviour, but we were able to overcome the issue with a little creative use of a more advanced feature in Ruby.