Question

We are developing a system that will do financial statements and other financial-related things. We are developing the app in Java/Java EE, specifically in JBoss Seam (Richfaces, a4j) + Javascript and other technologies.

Now we have a lot or formulas to calculate the financial statement accounts. We need to build something that can be used to store formulas and use them in a simple way, or in a data structure so the formulas don't kill the app with fixed numbers/references in all the code. (Maintainability concern.)

Now we have the formulas in a MS Excel sheet. There we have the common formulas from Excel (=A30+B40). Each row in excel is an account which we will store ultimately in a SQL server db table (account), but the main point here is how to storage/manage the formulas for a better use than hardcoded somewhere.

I know financial system do it, but I couldn't find to much information about it.

Was it helpful?

Solution

If your primary concern is maintainability of formulas, I can think of two different approaches that might help.

  • Keep the formulas in Excel and use something like Apache POI to write values to the spreadsheet, then read back the evaluated formulas. (See http://poi.apache.org/spreadsheet/eval.html.) Not sure how well that scales or performs, but the distinct advantage is that if your client is constantly tweaking formulas in the Excel sheet, the changes take effect right away rather than constantly playing catch-up.

  • Translate the formulas into Java POJOs, but keep them all consolidated in a single class or package of pure business logic with no Java EE, Seam or JSF dependencies. Even though you'll have to re-translate to Java every time the Excel version changes, at least it's all in one place with a clear mapping between the original Excel source. You could also use a scripting language to let you change the formulas without a restart/redeploy cycle.

OTHER TIPS

We did something similiar once where we stored KPI formulas in a SQL table. Our C program would read and run the SQL from the table.

Our KPIs uses weighting on the various factors contributing to the statistic. This way, we could change the weighting and formula (adding or removing factors) without having to change the program.

It sounds like a great application for a function, either in your application code, or as a sql function. I would highly recommend storing your functions in java code vs. sql as it is much easier to test and change. True, embedded sql functions can perform better and can executed in batch but performance is not everything as you will know when you will debug or change them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top