ENH actually use percents

This commit is contained in:
Nathan Dwarshuis 2023-05-08 00:12:01 -04:00
parent 9a1dd1ac3e
commit b3276132e3
1 changed files with 7 additions and 4 deletions

View File

@ -327,7 +327,7 @@ allocatePre precision gross = L.mapAccumR go M.empty
p = preValue faValue
v =
if prePercent faValue
then roundPrecision 3 p * gross
then (roundPrecision 3 p / 100) * gross
else roundPrecision precision p
in (mapAdd_ c v m, f {faValue = v})
@ -359,7 +359,7 @@ allocateTax precision gross deds = fmap (fmap go)
go TaxValue {tvCategories, tvMethod} =
let agi = gross - sum (mapMaybe (`M.lookup` deds) tvCategories)
in case tvMethod of
TMPercent p -> roundPrecision 3 p * agi
TMPercent p -> roundPrecision 3 p / 100 * agi
TMBracket TaxProgression {tpDeductible, tpBrackets} ->
foldBracket precision (agi - roundPrecision precision tpDeductible) tpBrackets
@ -371,14 +371,17 @@ allocatePost
allocatePost precision aftertax = fmap (fmap go)
where
go PosttaxValue {postValue, postPercent} =
let v = postValue in if postPercent then aftertax * roundPrecision 3 v else roundPrecision precision v
let v = postValue
in if postPercent
then aftertax * roundPrecision 3 v / 100
else roundPrecision precision v
foldBracket :: Natural -> Rational -> [TaxBracket] -> Rational
foldBracket precision agi bs = fst $ foldr go (0, agi) $ L.sortOn tbLowerLimit bs
where
go TaxBracket {tbLowerLimit, tbPercent} (acc, remain) =
let l = roundPrecision precision tbLowerLimit
p = roundPrecision 3 tbPercent
p = roundPrecision 3 tbPercent / 100
in if remain < l then (acc + p * (remain - l), l) else (acc, remain)
data FlatAllocation v = FlatAllocation