wip
parent
aa9b795abd
commit
e511da2e70
|
|
@ -0,0 +1,3 @@
|
||||||
|
package ana
|
||||||
|
|
||||||
|
type Prediction []Predictor
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package ana
|
||||||
|
|
||||||
|
import (
|
||||||
|
"maps"
|
||||||
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gogs.inhome.blapointe.com/ana-ledger/ledger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Predictor func(ledger.Balances, time.Duration) ledger.Balances
|
||||||
|
|
||||||
|
func NewInterestPredictor(namePattern string, currencyPattern string, apy float64) Predictor {
|
||||||
|
nameMatcher := regexp.MustCompile(namePattern)
|
||||||
|
currencyMatcher := regexp.MustCompile(currencyPattern)
|
||||||
|
return func(given ledger.Balances, delta time.Duration) ledger.Balances {
|
||||||
|
result := maps.Clone(given)
|
||||||
|
for k, v := range result {
|
||||||
|
result[k] = maps.Clone(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
for name := range result {
|
||||||
|
if !nameMatcher.MatchString(name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for currency := range result[name] {
|
||||||
|
if !currencyMatcher.MatchString(string(currency)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result[name][currency] *= 1.0 + apy/12.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue