Back to LinkedIn posts

LinkedIn post 297

πŸ“ˆ Another example of non-trivial Math in Salesforce: XIRR Calculation with Newton-...

πŸ“ˆ Another example of non-trivial Math in Salesforce: XIRR Calculation with Newton-Raphson πŸ’‘

Throwback to when I needed to calculate XIRR (Extended Internal Rate of Return) in Salesforce for a big energy company.

While XIRR is available as a formula in Excel, Salesforce doesn’t have it. So, I implemented it via Apex, using the Newton-Raphson method to get it done.

XIRR is a financial metric used to calculate the annualized rate of return for a series of cash flows that occur at irregular intervals. It helps you evaluate investments where the amounts and timing of transactions vary (think mutual funds, venture capital, or large real estate investments).

The Newton-Raphson method is an iterative approach to find the root of a function by using tangent lines. The algorithm refines an initial guess by dividing the function by its derivative, gradually improving the accuracy with each iteration until the value converges to the correct rate of return.

This experience was a great reminder that when the platform lacks a built-in solution, there’s always a way to code it! πŸ˜‰πŸ’‘

LINKS:
I no longer have that code but these are the open source snippets I've found - πŸ™πŸΌ thanks to Luke Mcfarlane and Schubert Tonarelli ! πŸ™πŸΌ
πŸ”— https://lnkd.in/gy9ZAtqP
πŸ”— https://lnkd.in/gzcxYp9p

chart, line chart