instead of plain compounding interest formula, compute interest per month + add interest of previous months to principle
parent
354bdd06d8
commit
12750ff357
|
|
@ -185,16 +185,21 @@ func RegisterWithCompoundingInterestPrediction(reg Register, window time.Duratio
|
|||
}
|
||||
}
|
||||
|
||||
addedSoFar := make(Balances)
|
||||
for _, predictionTime := range predictedTimes {
|
||||
k := predictionTime.Format("2006-01")
|
||||
for name := range lastBalances {
|
||||
if _, ok := addedSoFar[name]; !ok {
|
||||
addedSoFar[name] = make(Balance)
|
||||
}
|
||||
for currency := range result[k][name] {
|
||||
// A = P(1 + r/n)**nt
|
||||
p := result[k][name][currency]
|
||||
p := result[k][name][currency] + addedSoFar[name][currency]
|
||||
r := apy
|
||||
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)
|
||||
addedSoFar[name][currency] += (result[k][name][currency] - p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue