Back to LinkedIn posts

LinkedIn post 290

๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐—ฎ๐—ป๐˜ ๐—–๐—ผ๐—ป๐˜๐—ฒ๐˜…๐˜: ๐—ช๐—ฒ ๐—ถ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฒ๐—ฑ ๐˜๐—ต๐—ถ๐˜€ ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๏ฟฝ...

๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐—ฎ๐—ป๐˜ ๐—–๐—ผ๐—ป๐˜๐—ฒ๐˜…๐˜: ๐—ช๐—ฒ ๐—ถ๐—ป๐—ต๐—ฒ๐—ฟ๐—ถ๐˜๐—ฒ๐—ฑ ๐˜๐—ต๐—ถ๐˜€ ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป *years ago*. ๐——๐˜‚๐—ฒ ๐˜๐—ผ ๐˜๐—ถ๐—ด๐—ต๐˜ ๐—ฝ๐—ฟ๐—ผ๐—ท๐—ฒ๐—ฐ๐˜, ๐—ฐ๐—ผ๐˜€๐˜ ๐—ฎ๐—ป๐—ฑ ๐˜๐—ถ๐—บ๐—ฒ ๐—ฐ๐—ผ๐—ป๐˜€๐˜๐—ฟ๐—ฎ๐—ถ๐—ป๐˜๐˜€, ๐˜„๐—ฒ ๐—ฐ๐—ผ๐˜‚๐—น๐—ฑ๐—ปโ€™๐˜ ๐—ฝ๐˜‚๐—ฟ๐˜€๐˜‚๐—ฒ ๐—ฎ๐—ป๐˜† ๐—ผ๐˜๐—ต๐—ฒ๐—ฟ ๐—บ๐—ผ๐—ฟ๐—ฒ ๐—ผ๐—ฝ๐˜๐—ถ๐—บ๐—ฎ๐—น ๐˜€๐—ผ๐—น๐˜‚๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐˜€๐˜‚๐—ฐ๐—ต ๐—ฎ๐˜€ ๐˜๐—ต๐—ฒ ๐—ผ๐—ป๐—ฒ๐˜€ ๐˜€๐˜‚๐—ด๐—ด๐—ฒ๐˜€๐˜๐—ฒ๐—ฑ ๐—ถ๐—ป ๐˜๐—ต๐—ฒ ๐—ฐ๐—ผ๐—บ๐—บ๐—ฒ๐—ป๐˜๐˜€.

Imagine a capital investment model with columns for months and years, and many rows for revenues, expenses, profit, capital investment, annual cash flow, cumulative cash flowโ€”plus a few rows for NPV and IRR. The image shows a vastly simplified model.

Now imagine implementing all of this in Salesforce for a big oil company. Not just the basic model, but also sensitivity analysis: what-if scenarios with, say, +10% expenses or -10% revenues โ€” all this requiring recalculations of the entire model for every scenario. Needless to say, triggers weren't cutting it; recalculating everything was slow and even led to timeouts.

Almost a decade ago, we inherited this implementation and needed to fix it.

I suspected there was potential to leverage derivatives for sensitivity analysis to provide a faster and more efficient solution. But due to project and time constraints, we had to implement the entire recalculation approach instead - so there was some frustration because this was a sort of brute force approach.

Ultimately, we used asynchronous Apex to handle the heavy lifting, avoiding timeouts. But it was a pity that we couldn't optimize it further by determining the derivatives for NPV and IRR โ€” a missed opportunity for a more elegant and faster solution.

For example, with the NPV formula, the derivative with respect to a cash flow would give an estimate of the change in NPV more directly, without recalculating everything. Using ฮ”NPV โ‰ˆ ฮ”C_t / (1 + i)^t would approximate the impact of changes in revenues or expenses, significantly speeding up sensitivity analysis (IRR would be more complicated though).

Have you ever faced a scenario where an optimal approach had to be put aside due to constraints? How did you handle it?

table