Contributions to AutoContributions
This commit is contained in:
@@ -42,12 +42,12 @@ func NewInterestPredictor(namePattern string, currencyPattern string, apy float6
|
||||
}
|
||||
}
|
||||
|
||||
func NewContributionPredictor(reg ledger.Register) Predictor {
|
||||
monthlyRate := getMonthlyContributionRates(reg)
|
||||
return newContributionPredictor(monthlyRate)
|
||||
func NewAutoContributionPredictor(reg ledger.Register) Predictor {
|
||||
monthlyRate := getMonthlyAutoContributionRates(reg)
|
||||
return newAutoContributionPredictor(monthlyRate)
|
||||
}
|
||||
|
||||
func newContributionPredictor(monthlyRate map[string]ledger.Balance) Predictor {
|
||||
func newAutoContributionPredictor(monthlyRate map[string]ledger.Balance) Predictor {
|
||||
return func(given ledger.Balances, delta time.Duration) ledger.Balances {
|
||||
months := float64(delta) / float64(month)
|
||||
result := make(ledger.Balances)
|
||||
@@ -66,18 +66,18 @@ func newContributionPredictor(monthlyRate map[string]ledger.Balance) Predictor {
|
||||
}
|
||||
}
|
||||
|
||||
func getMonthlyContributionRates(reg ledger.Register) map[string]ledger.Balance {
|
||||
func getMonthlyAutoContributionRates(reg ledger.Register) map[string]ledger.Balance {
|
||||
window := 6 * month
|
||||
window = 12 * month
|
||||
contributions := getRecentContributions(reg, window)
|
||||
result := make(map[string]ledger.Balance)
|
||||
for name := range contributions {
|
||||
result[name] = getMonthlyContributionRate(contributions[name], window)
|
||||
result[name] = getMonthlyAutoContributionRate(contributions[name], window)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getMonthlyContributionRate(contributions []ledger.Balance, window time.Duration) ledger.Balance {
|
||||
func getMonthlyAutoContributionRate(contributions []ledger.Balance, window time.Duration) ledger.Balance {
|
||||
currencies := map[ledger.Currency]int{}
|
||||
for _, balance := range contributions {
|
||||
for currency := range balance {
|
||||
@@ -86,13 +86,12 @@ func getMonthlyContributionRate(contributions []ledger.Balance, window time.Dura
|
||||
}
|
||||
result := make(ledger.Balance)
|
||||
for currency := range currencies {
|
||||
result[currency] = getMonthlyContributionRateForCurrency(contributions, window, currency)
|
||||
result[currency] = getMonthlyAutoContributionRateForCurrency(contributions, window, currency)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// TODO better than average
|
||||
func getMonthlyContributionRateForCurrency(contributions []ledger.Balance, window time.Duration, currency ledger.Currency) float64 {
|
||||
func getMonthlyAutoContributionRateForCurrency(contributions []ledger.Balance, window time.Duration, currency ledger.Currency) float64 {
|
||||
values := []float64{}
|
||||
for i := range contributions {
|
||||
if v, ok := contributions[i][currency]; ok {
|
||||
|
||||
Reference in New Issue
Block a user