I have an issue with calculating interest rates in bubble.
First of all, I need to use the act/360 method. In German it is also called Eurozinsmethode and it is often used in real estate stuff.
We are calculating compound interest rates.
Let’s say someone invests 10.000 €
The interest rate is 4%
The period of the investment is 66 months and the starting date is the 10th of August 2021.
The last day of the investment would then be the 10th of February 2027.
To calculate the compound interest rate we need to calculate the remaining days of 2021, which are 143. Then we calculate 10000* 4% * 143 days / 360 to get the new value of 10.158,89€.
In year 2 we have 365 days and we get 10.570,89€ at the end of the year. Leap years with 366 days are also considered.
In the last year, we calculate with the remaining 41 days to get our final value.
The big issue I have is, that I have to show the interest for each year and the period is changeable. In programming my output would be something like an array with an expandable length.
Any ideas on how to do that with bubble? Do I need to make a plugin?
Okay, does the math.js plugin allow for “array-results” with variable length?
Is there any good documentation or video, that could help me getting into the math.js plugin?
The plugin works exactly like described here in the website https://mathjs.org/. I advise you to first write down the formula in math form, and use the math.js plugin(you can use multiple of them to calculate different steps of your formula) to get the results.
I mean I don’t only need a formula. I also need a lot of logic.
In the starting year, I have to calculate the remaining days of the year.
In 2022 I take 365, in 2023 366, in 2024 365, in 2025 365 and in 2026 there are like 41 days remaining or so. I have to automatically identify those 6 periods and calculate accordingly for each period.
The calculation also needs to work when my investment period isn’t 66 months, but 30 or 150.
I looked through the whole documentation of math.js but couldn’t find anything about loops and other stuff. I could also be thinking to complicated…
you’re much better off writing your own javascript functions then.
You need a series of functions that returns the number of days in the investment period. You can do this with
a function that calculates the number of days in the remaining year
a function that calculates the number of days in subsequent years. you can use an if statement for leap years.
You’ll then need a function that takes in a (starting_investment_amount, interest_percentage, and number_of_days) and returns the interest rate.
It’s a rather straightforward, small JS project – there should be plenty of examples on stack overflow if you get stuck. You can go on youtube and find out how to send variables into a server script, and how to retrieve them into bubble.