## ~rickylinden/scripts

ref: e46dc6a3334961f03420d321485887d6ad5477ed scripts/compoundcalculator.py -rwxr-xr-x 1.6 KiB
e46dc6a3rickylinden Added compound calculator a month ago
`                                                                                `
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38```
```import math
from datetime import date

# total sum of the starting amount with interest over time
def initialCompound(p, r, t):
n = 12 # n is compounds per year
return p * (1 + r / n) ** (n * t)

# total sum of regular savings with interest over time
def regularCompound(pmt, r, t):
n = 12 # n is compounds per year
return pmt * (((1 + r / n) ** (n * t) - 1) / (r / n))

# interest per month at t
def interestMonthly(value, r):
return (value * r) / 12

# to round numbers at two decimals
def truncate(number, digits) -> float:
stepper = 10.0 ** digits
return math.trunc(stepper * number) / stepper

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.")
```