vince
vince

Reputation: 2848

how to calculate interest

We have a web app that among other things, allow users to leave a cash balance on their account (which can be cashed out anytime or used to purchase items on the site). Users can withdraw and deposit funds to their account anytime. It was never intended for it, but we now have users who leave large sums on their account and they're now requesting that we provide some interest on their account balance which is totally reasonable. Problem is we have no idea how to calculate interest on an account where users can withdraw and deposit funds anytime, but all the banks obviously do it so I was wondering if there's a standard way (or ruby gem) to calculate interest. Any pointers or help is greatly appreciated.

The db table setup is pretty simple.

User has one Account

Accounts(user_id, balance)

Account has many activities

Activities(account_id, type, amount, description, created_at)

Where type can be either "Deposit" or "Withdrawal".

Upvotes: 0

Views: 2149

Answers (2)

rizidoro
rizidoro

Reputation: 13418

Take a look at the Exonio gem: https://github.com/Noverde/exonio.

This gem implements some of the Excel financial formulas, including the Interest calculation that you are asking for.

From their docs:

What is the interest part of a payment in the 8th period (i.e., 8th month), having a $5,000 loan to be paid in 2 years at an annual interest rate of 7.5%?

Exonio.ipmt(0.075 / 12, 8, 12 * 2, 5_000.00) # ==> -22.612926783996798

So, in the 8th payment, $22.61 are the interest part.

Upvotes: 1

Alastair
Alastair

Reputation: 328

For the answer on what interest calculation to use I agree with Ray Toal that you are going to have to ask your client what interest calculation to use and what their payment scheme is like.

Usually speaking, financial institutions that offer interest on a chequing account are calculated with compounding interest calculated daily [at the close?] of each business day and paid monthly at the end of each month by a deposit directly into the account.

Notably, banks and other financial institutions will tell their clients the interest rate on a yearly basis (APR) and not the interest rate per-day. It is an elementary mistake that I have made in the past.

Upvotes: 1

Related Questions