I am working on a project right now that is having me calculate monthly interest on a bank account. The way the interest is supposed to be calculated is as follows:
Use the daily average to calculate interest. The daily average balance of an account is calculated by the taking the average of the end of the day balance for every day in the month. So, at the end of the every month, calculate the daily average balance for that month and use this to calculate interest.
The basic gist of my software is as follows: it’s a Desktop Java Application with a Swing GUI and a serialized text file to store information about bank accounts when the software is not running.
What is a good way to go about calculating this daily average and applying interest at the correct time?
NOTE: If possible, I really really do not want to have to implement some sort of centralized data base with SQL or something similar. This would require me to rewrite a lot of code, and I don’t know really anything about SQL as it is..
Additional Info
I will be using Joda-Time to keep track of the time/date.
I have contemplated just doing some sort of calculation on the time, date and balance every time I close/open the program. But what if the software is left running for, say 15 days straight?
Let’s say I just wanted to implement some code to calculate the average balance for the month whenever the program is opened, and not worry about the program being run for days at a time. How could I go about doing this? I was thinking about having some sort of lastAccessed
field that would store the date of the last time the program was opened. Then calculate the the average every time the software was opened using that last accessed field somehow.
6
First I am going to put a disclaimer:
I really hope this is a school assignment project because storing account numbers and maintaining funds balance in a desktop application with a text file is unbelievably insecure and prone to error. I vehemently recommend more of a client/server/database design with security built between all layers.
With that being said, I will give you some advice as to how many banking and accounting systems manage funds and account balances.
Maintain a master account record with a master balance. Throughout the day when debits or credits are initiated in your application you will correspond these to a separate record that maintains Hold’s against account numbers.
What is a hold? It is a temporary hold of money on an account. For an account that is being debited funds, you put a hold on that account for the amount to transfer. The account receiving the credit will also have a Hold that signifies it will eventually be credited with the amount of the transfer.
Before initiating a transaction you have to do a balance check on the accounts to authorize the transaction. Take into account the master account balance +/- all debit and credit holds on the account.
At the end of the day at a specified time, or after the application starts up you need to do what is called “Hard charging”. This is where you calculate the new master balance of the accounts in the ledger with all of the holds that have been previously placed. This new balance will be your starting point now for the remainder of the day.
Why this complexity? This allows for easier integration with accounting packages and software as well as with payments going out to a bank or other financial institution.