## ~rickylinden/scripts

e46dc6a3334961f03420d321485887d6ad5477ed — rickylinden 2 months ago
```Added compound calculator
```
```3 files changed, 41 insertions(+), 3 deletions(-)

A compoundcalculator.py
```
`M README.md => README.md +3 -0`
```@@ 1,6 1,9 @@
# Random scripts
Scripts I have either found, found and edited or written myself.

+## compoundcalculator.sh
+Calculates compound interest on investment over time.
+
## backup.sh
Backs up home folder to external drive using rsync.

```
`A compoundcalculator.py => compoundcalculator.py +38 -0`
```@@ 0,0 1,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.")

```
`M passmenu => passmenu +0 -3`
```@@ 23,6 23,3 @@ else
pass show "\$password" | { IFS= read -r pass; printf %s "\$pass"; } |
xdotool type --clearmodifiers --file -
fi
-
-
-

```