instead of plain compounding interest formula, compute interest per month + add interest of previous months to principle

main
Bel LaPointe 2023-10-26 07:29:06 -06:00
parent 354bdd06d8
commit 12750ff357
1 changed files with 7 additions and 2 deletions

View File

@ -185,16 +185,21 @@ func RegisterWithCompoundingInterestPrediction(reg Register, window time.Duratio
} }
} }
addedSoFar := make(Balances)
for _, predictionTime := range predictedTimes { for _, predictionTime := range predictedTimes {
k := predictionTime.Format("2006-01") k := predictionTime.Format("2006-01")
for name := range lastBalances { for name := range lastBalances {
if _, ok := addedSoFar[name]; !ok {
addedSoFar[name] = make(Balance)
}
for currency := range result[k][name] { for currency := range result[k][name] {
// A = P(1 + r/n)**nt // A = P(1 + r/n)**nt
p := result[k][name][currency] p := result[k][name][currency] + addedSoFar[name][currency]
r := apy r := apy
n := 12.0 n := 12.0
t := float64(predictionTime.Sub(time.Now()) / (time.Hour * 24 * 365)) t := 1.0 / 12.0
result[k][name][currency] = p * math.Pow(1.0+(r/n), n*t) result[k][name][currency] = p * math.Pow(1.0+(r/n), n*t)
addedSoFar[name][currency] += (result[k][name][currency] - p)
} }
} }
} }