pub fn progressive_tax(
agi: Decimal,
deductions: Decimal,
rate_table: &[(Decimal, Decimal)],
) -> Option<Decimal>
Expand description
Progressive Income Tax
§Arguments
agi
- Adjusted Gross Income (AGI) for the tax year, your total income minus any above-the-line deductionsdeductions
- Any below-the-line deductions for the tax year (i.e. standard or itemized deductions)rate_table
- A slice of tuples representing the upper income of each bracket and its rate for the tax year(bracket, rate)
, the last tuple should represent a number to infinity and the highest rate. In practice, the final bracket would the maximum number representable by the Decimal type (Decimal::MAX
).
§Returns
- An option containing the total tax owed for the tax year based on the progressive rate table. If AGI is less than deductions, zero is returned (no tax owed).
If the rate table is not valid, i.e. the brackets are not sorted in ascending order or the last bracket
is not set to infinity (Decimal::MAX), None is returned. See progressive_tax_unchecked
for an unchecked
(unsafe) version of this function that skips the rate table validation.
§Examples
use rust_finprim::amort_dep_tax::progressive_tax;
use rust_decimal_macros::*;
use rust_decimal::Decimal;
let rate_table = vec![
(dec!(9_875), dec!(0.10)),
(dec!(40_125), dec!(0.12)),
(dec!(85_525), dec!(0.22)),
(dec!(163_300), dec!(0.24)),
(dec!(207_350), dec!(0.32)),
(dec!(518_400), dec!(0.35)),
(Decimal::MAX, dec!(0.37))
];
let agi = dec!(100_000);
let deductions = dec!(12_000);
let tax = progressive_tax(agi, deductions, &rate_table);