## ~rickylinden/scripts

6fa08ef3ffb03d91bcb1b987af9aa8ea86719246 — rickylinden 14 days ago
```If version of compound calculator
```
```1 files changed, 38 insertions(+), 17 deletions(-)

M compoundcalculator.py
```
`M compoundcalculator.py => compoundcalculator.py +38 -17`
```@@ 1,3 1,5 @@
+# Inspired by this: https://www.thecalculatorsite.com/articles/finance/compound-interest-formula.php
+
import math
from datetime import date

@@ 11,7 13,12 @@ def regularCompound(pmt, r, t):
n = 12 # n is compounds per year
return pmt * (((1 + r / n) ** (n * t) - 1) / (r / n))

-# interest alone per month
+# total sum of regular savings with interest over time
+def findMonthly(m, t, r):
+	n = 12 # n is compounds per year
+	return m / (((1 + r / n) ** (n * t) - 1) / (r / n))
+
+# interest per month at t
def interestMonthly(value, r):
return (value * r) / 12

@@ 20,21 27,35 @@ def truncate(number, digits) -> float:
stepper = 10.0 ** digits
return math.trunc(stepper * number) / stepper

+def year(t):
+	return str(date.today().year + t)
+
print("+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+")
print("|c|o|m|p|o|u|n|d| |i|n|t|e|r|e|s|t| |c|a|l|c|u|l|a|t|o|r|")
-print("+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+\n")
-
-p=float(input('Enter your investment amount when starting out (defaults to 0): ') or "0")
-pmt=float(input('Monthly contribution to investment (defaults to 1000): ') or "1000")
-r = float(input("Enter the interest rate (defaults to 0.05, meaning 5%): ") or "0.05")
-t=int(input('The amount of years you will invest (defaults to 30): ') or "30")
-
-y = str(date.today().year + t)
-
-value = initialCompound(p, r, t) + regularCompound(pmt, r, t)
-
-print("\nSo after " + str(t) + " years you should in total have: ~" +
-str(truncate(value, 2)) + "€")
-print("Which means every month in " + y + " you get from interest alone ~" +
-str(truncate(interestMonthly(value, r), 2)) + "€")
-print("\nThese calculations are based off of: https://www.thecalculatorsite.com/articles/finance/compound-interest-formula.php \nPlease note taxes/fees are not taken into consideration.")
+print("+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+")
+print("(NOTE: Taxes/fees are not taken into consideration.)\n")
+
+print("a) You want to see how much money your monthly investment becomes after certain amount of years.")
+print("b) You know how much money you want and would like to know how long it takes to get it by investing.")
+
+	p=float(input('\nEnter your investment amount when starting out (defaults to 0 if empty): ') or "0")
+	pmt=float(input('Monthly contribution to investment (defaults to 1000€ if empty): ') or "1000")
+	t=int(input('The amount of years you will invest (defaults to 30 years if empty): ') or "30")
+	r = float(input("The average interest rate during these years (defaults to 0.05, meaning 5%, if empty): ") or "0.05")
+	y = year(t)
+
+	value = initialCompound(p, r, t) + regularCompound(pmt, r, t)
+
+	print("\nAfter " + str(t) + " years you should in total have: ~" + str(truncate(value, 2)) + "€.")
+	print("Which means that in the year " + y + " you get, more or less depending on that months interest, " + str(truncate(interestMonthly(value, r), 2)) + "€/month in interest alone.")