2 people like it.

Progressive tax calculator

Calculates progressive tax on an annual income.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
/// Calculates progressive tax on an annual income
let calcProgressiveTax taxBrackets income =
  taxBrackets @ [ (System.Double.MaxValue, 0.0) ]
  |> Seq.windowed 2
  |> Seq.fold
       (fun (incomeLeft, tax) x ->
         let bracketLow, rate = x.[0]
         let bracketHight = fst x.[1]
         let bracketW = bracketHight - bracketLow
         match incomeLeft, incomeLeft <= bracketW with
         | 0.0, _            -> (0.0, tax)
         | incomeLeft, true  -> (0.0, incomeLeft * rate + tax)
         | incomeLeft, false -> (incomeLeft - bracketW, bracketW * rate + tax)
       )
       (income, 0.0)
  |> snd


// Example
let incomeTaxBelgium2016 =  //   Taxable Income    Tax Rate on 
  [                         //   Bracket, EUR      Income in Bracket
  (    0.00, 0.25);         //      0 .. 10,860      25%
  (10860.00, 0.30);         // 10,860 .. 12,470      30%
  (12470.00, 0.40);         // 12,470 .. 20,780      40%
  (20780.00, 0.45);         // 20,780 .. 38,080      45%
  (38080.00, 0.50);         // 38,080 ..  over       50%
  ]
  
calcProgressiveTax incomeTaxBelgium2016 100000.00
// Returns: 45,267.00
val calcProgressiveTax : taxBrackets:(float * float) list -> income:float -> float

Full name: Script.calcProgressiveTax


 Calculates progressive tax on an annual income
val taxBrackets : (float * float) list
val income : float
namespace System
type Double =
  struct
    member CompareTo : value:obj -> int + 1 overload
    member Equals : obj:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member GetTypeCode : unit -> TypeCode
    member ToString : unit -> string + 3 overloads
    static val MinValue : float
    static val MaxValue : float
    static val Epsilon : float
    static val NegativeInfinity : float
    static val PositiveInfinity : float
    ...
  end

Full name: System.Double
field float.MaxValue = 1.79769313486e+308
module Seq

from Microsoft.FSharp.Collections
val windowed : windowSize:int -> source:seq<'T> -> seq<'T []>

Full name: Microsoft.FSharp.Collections.Seq.windowed
val fold : folder:('State -> 'T -> 'State) -> state:'State -> source:seq<'T> -> 'State

Full name: Microsoft.FSharp.Collections.Seq.fold
val incomeLeft : float
val tax : float
val x : (float * float) []
val bracketLow : float
val rate : float
val bracketHight : float
val fst : tuple:('T1 * 'T2) -> 'T1

Full name: Microsoft.FSharp.Core.Operators.fst
val bracketW : float
val snd : tuple:('T1 * 'T2) -> 'T2

Full name: Microsoft.FSharp.Core.Operators.snd
val incomeTaxBelgium2016 : (float * float) list

Full name: Script.incomeTaxBelgium2016

More information

Link:http://fssnip.net/7PY
Posted:3 years ago
Author:Dmitry Achkasov
Tags: finance , tax