• Post Reply Bookmark Topic Watch Topic
  • New Topic

calculating interest using java  RSS feed

 
Adam no
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm days into my highschool course and i recently got an assignment to calculate interest, and I'm just completely confused.
hw.PNG
[Thumbnail for hw.PNG]
This is basically what I have to do, and what i've somewhat have gotten so far :/
 
Adam no
Greenhorn
Posts: 2
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Adam,

welcome to the Ranch!

Don't panic, it is not very difficult.

Say you have an interestperunage of i, meaning that when you start with €1, you have (1 + i) euros after one year, (1 + i)^2 euros after two years, et cetera, (this is what is called "compund interest"), then what equation do you get when your initial € 1 has doubled after n years?

And do you know how to solve that equation, for n = 10, 20 and 30?

 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how they are expecting you to solve this programmatically. You could pick a rate and run it through a compound interest formula then IF it is more than double, reduce the rate and try again. IF it is less than double then increase the rate. Another way is to algebraically take the compound interest formula and solve for rate (this is a paper and pencil exercise), then implement the new formula in Java.

amount = principle * Math.pow(1 + rate/12, 12*years)

If you know that amount is two times the principle and you know the number of years, solve for rate.

Does this help at all?

 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google: "compound interest solve for rate"
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enough time has passed so I don't think posting the answer should be an issue.

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since OP did not respond anymore, I wouldn't have given a solution. But why are you using such a restrictive formula? Way back, we used to tease the students with interest based on a quarter year, but granted at the end of every fourth month, et cetera.
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:. . . interest based on a quarter year, but granted at the end of every fourth month, et cetera.
So you worked in Iceland in 2008?
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... if you earn 50,- per hour, and your salary is granted once every month, is your employer from Iceland?
 
Campbell Ritchie
Marshal
Posts: 56562
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have forgotten what happened in Iceland in 2008.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:Since OP did not respond anymore, I wouldn't have given a solution.

I agree.  No complete solutions until the OP has posted their own.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Piet Souris wrote:. . . interest based on a quarter year, but granted at the end of every fourth month, et cetera.
So you worked in Iceland in 2008?

Campbell Ritchie wrote:You have forgotten what happened in Iceland in 2008.

No, I haven't forgotten. And if the Icelanders did what you suggest, I doubt if they would have gone bust.

The idea is of course to go from an interest rate per quarter to an interest rate per a period of four months, and then calculate with periods of four months. That is why I said that Carey's formula is a bit limited, although the idea is the same: recalculate the (what we call 'apparent') interest per year to an interest per month, and calculate in month periods. So it is easier to simply have an interest per some period, and leave the definition of what that might be to the market, or to the loan supplier, or to the one who gives the assignment.

Interest calculus is an incredibly interesting subject, with a range of questions that resembles OCAJP with ease and that one can make as simple or as complicated as one likes. With all the todays valuation according to say Solvency II, we have that every period has its own "yearly" interest rate. So a period of one month has an interest rate of i1 per year, a period of two months has an interest rate of i2 per year, ad infinitum so to speak, making interest calculations even more interesting than they already were.

But I better stop now, before loosing the one person reading this too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!