rename based on plans
This commit is contained in:
42
ana/legacy_bpi.go
Normal file
42
ana/legacy_bpi.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package ana
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"gogs.inhome.blapointe.com/ana-ledger/ledger"
|
||||
)
|
||||
|
||||
func BPIsWithFixedGrowthPrediction(bpis ledger.BPIs, window time.Duration, pattern string, apy float64) (ledger.BPIs, error) {
|
||||
last := map[ledger.Currency]struct {
|
||||
t string
|
||||
v float64
|
||||
}{}
|
||||
for currency, bpi := range bpis {
|
||||
for date, value := range bpi {
|
||||
if date > last[currency].t {
|
||||
was := last[currency]
|
||||
was.t = date
|
||||
was.v = value
|
||||
last[currency] = was
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result := make(ledger.BPIs)
|
||||
p := regexp.MustCompile(pattern)
|
||||
for currency, v := range bpis {
|
||||
result[currency] = maps.Clone(v)
|
||||
if p.MatchString(string(currency)) {
|
||||
for _, predictionTime := range predictionTimes(window) {
|
||||
k2 := predictionTime.Format("2006-01")
|
||||
was := last[currency]
|
||||
was.v *= 1.0 + (apy / 12.0)
|
||||
result[currency][k2] = was.v
|
||||
last[currency] = was
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user