Skip to content

Instantly share code, notes, and snippets.

@fxn
Last active January 13, 2021 08:04
Show Gist options
  • Save fxn/6f8bca85d928425e3f34 to your computer and use it in GitHub Desktop.
Save fxn/6f8bca85d928425e3f34 to your computer and use it in GitHub Desktop.

Revisions

  1. fxn revised this gist Jan 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion irpf.rb
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@
    end
    end

    puts "%6d €, %6d €, %.1f%" % [base, irpf, 100.0*irpf/base]
    puts "%6d €, %6d €, %.1f%%" % [base, irpf, 100.0*irpf/base]


    __END__
  2. fxn created this gist Feb 1, 2015.
    216 changes: 216 additions & 0 deletions irpf.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,216 @@
    # Usage:
    #
    # ruby irpf.rb tax_base
    #
    # Example:
    #
    # ruby irpf.rb 65300
    # 65300 €, 22722 €, 34.8%
    #
    # Where 22,722 € is the IRPF to pay, and 34.8% is the real rate, that is,
    # how much does the tax really represent relative to the tax base (which
    # is smaller in general from the rate of the base's bracket due to how
    # the tax is computed).

    # Brackets for 2014.
    brackets = {
    17_707 => 0.2475,
    33_007 => 0.30,
    53_407 => 0.40,
    120_000 => 0.47,
    175_000 => 0.49,
    300_000 => 0.51,
    999_999 => 0.52,
    }

    base = ARGV.shift.to_i
    binf = 0
    irpf = 0

    brackets.each do |bsup, rate|
    irpf += ([bsup, base].min - binf)*rate

    if bsup < base
    binf = bsup
    else
    break
    end
    end

    puts "%6d €, %6d €, %.1f%" % [base, irpf, 100.0*irpf/base]


    __END__

    BASE IRPF ACTUAL RATE
    30000 €, 8070 €, 26.9%
    31000 €, 8370 €, 27.0%
    32000 €, 8670 €, 27.1%
    33000 €, 8970 €, 27.2%
    34000 €, 9369 €, 27.6%
    35000 €, 9769 €, 27.9%
    36000 €, 10169 €, 28.2%
    37000 €, 10569 €, 28.6%
    38000 €, 10969 €, 28.9%
    39000 €, 11369 €, 29.2%
    40000 €, 11769 €, 29.4%
    41000 €, 12169 €, 29.7%
    42000 €, 12569 €, 29.9%
    43000 €, 12969 €, 30.2%
    44000 €, 13369 €, 30.4%
    45000 €, 13769 €, 30.6%
    46000 €, 14169 €, 30.8%
    47000 €, 14569 €, 31.0%
    48000 €, 14969 €, 31.2%
    49000 €, 15369 €, 31.4%
    50000 €, 15769 €, 31.5%
    51000 €, 16169 €, 31.7%
    52000 €, 16569 €, 31.9%
    53000 €, 16969 €, 32.0%
    54000 €, 17411 €, 32.2%
    55000 €, 17881 €, 32.5%
    56000 €, 18351 €, 32.8%
    57000 €, 18821 €, 33.0%
    58000 €, 19291 €, 33.3%
    59000 €, 19761 €, 33.5%
    60000 €, 20231 €, 33.7%
    61000 €, 20701 €, 33.9%
    62000 €, 21171 €, 34.1%
    63000 €, 21641 €, 34.4%
    64000 €, 22111 €, 34.5%
    65000 €, 22581 €, 34.7%
    66000 €, 23051 €, 34.9%
    67000 €, 23521 €, 35.1%
    68000 €, 23991 €, 35.3%
    69000 €, 24461 €, 35.5%
    70000 €, 24931 €, 35.6%
    71000 €, 25401 €, 35.8%
    72000 €, 25871 €, 35.9%
    73000 €, 26341 €, 36.1%
    74000 €, 26811 €, 36.2%
    75000 €, 27281 €, 36.4%
    76000 €, 27751 €, 36.5%
    77000 €, 28221 €, 36.7%
    78000 €, 28691 €, 36.8%
    79000 €, 29161 €, 36.9%
    80000 €, 29631 €, 37.0%
    81000 €, 30101 €, 37.2%
    82000 €, 30571 €, 37.3%
    83000 €, 31041 €, 37.4%
    84000 €, 31511 €, 37.5%
    85000 €, 31981 €, 37.6%
    86000 €, 32451 €, 37.7%
    87000 €, 32921 €, 37.8%
    88000 €, 33391 €, 37.9%
    89000 €, 33861 €, 38.0%
    90000 €, 34331 €, 38.1%
    91000 €, 34801 €, 38.2%
    92000 €, 35271 €, 38.3%
    93000 €, 35741 €, 38.4%
    94000 €, 36211 €, 38.5%
    95000 €, 36681 €, 38.6%
    96000 €, 37151 €, 38.7%
    97000 €, 37621 €, 38.8%
    98000 €, 38091 €, 38.9%
    99000 €, 38561 €, 39.0%
    100000 €, 39031 €, 39.0%
    101000 €, 39501 €, 39.1%
    102000 €, 39971 €, 39.2%
    103000 €, 40441 €, 39.3%
    104000 €, 40911 €, 39.3%
    105000 €, 41381 €, 39.4%
    106000 €, 41851 €, 39.5%
    107000 €, 42321 €, 39.6%
    108000 €, 42791 €, 39.6%
    109000 €, 43261 €, 39.7%
    110000 €, 43731 €, 39.8%
    111000 €, 44201 €, 39.8%
    112000 €, 44671 €, 39.9%
    113000 €, 45141 €, 39.9%
    114000 €, 45611 €, 40.0%
    115000 €, 46081 €, 40.1%
    116000 €, 46551 €, 40.1%
    117000 €, 47021 €, 40.2%
    118000 €, 47491 €, 40.2%
    119000 €, 47961 €, 40.3%
    120000 €, 48431 €, 40.4%
    121000 €, 48921 €, 40.4%
    122000 €, 49411 €, 40.5%
    123000 €, 49901 €, 40.6%
    124000 €, 50391 €, 40.6%
    125000 €, 50881 €, 40.7%
    126000 €, 51371 €, 40.8%
    127000 €, 51861 €, 40.8%
    128000 €, 52351 €, 40.9%
    129000 €, 52841 €, 41.0%
    130000 €, 53331 €, 41.0%
    131000 €, 53821 €, 41.1%
    132000 €, 54311 €, 41.1%
    133000 €, 54801 €, 41.2%
    134000 €, 55291 €, 41.3%
    135000 €, 55781 €, 41.3%
    136000 €, 56271 €, 41.4%
    137000 €, 56761 €, 41.4%
    138000 €, 57251 €, 41.5%
    139000 €, 57741 €, 41.5%
    140000 €, 58231 €, 41.6%
    141000 €, 58721 €, 41.6%
    142000 €, 59211 €, 41.7%
    143000 €, 59701 €, 41.7%
    144000 €, 60191 €, 41.8%
    145000 €, 60681 €, 41.8%
    146000 €, 61171 €, 41.9%
    147000 €, 61661 €, 41.9%
    148000 €, 62151 €, 42.0%
    149000 €, 62641 €, 42.0%
    150000 €, 63131 €, 42.1%
    151000 €, 63621 €, 42.1%
    152000 €, 64111 €, 42.2%
    153000 €, 64601 €, 42.2%
    154000 €, 65091 €, 42.3%
    155000 €, 65581 €, 42.3%
    156000 €, 66071 €, 42.4%
    157000 €, 66561 €, 42.4%
    158000 €, 67051 €, 42.4%
    159000 €, 67541 €, 42.5%
    160000 €, 68031 €, 42.5%
    161000 €, 68521 €, 42.6%
    162000 €, 69011 €, 42.6%
    163000 €, 69501 €, 42.6%
    164000 €, 69991 €, 42.7%
    165000 €, 70481 €, 42.7%
    166000 €, 70971 €, 42.8%
    167000 €, 71461 €, 42.8%
    168000 €, 71951 €, 42.8%
    169000 €, 72441 €, 42.9%
    170000 €, 72931 €, 42.9%
    171000 €, 73421 €, 42.9%
    172000 €, 73911 €, 43.0%
    173000 €, 74401 €, 43.0%
    174000 €, 74891 €, 43.0%
    175000 €, 75381 €, 43.1%
    176000 €, 75891 €, 43.1%
    177000 €, 76401 €, 43.2%
    178000 €, 76911 €, 43.2%
    179000 €, 77421 €, 43.3%
    180000 €, 77931 €, 43.3%
    181000 €, 78441 €, 43.3%
    182000 €, 78951 €, 43.4%
    183000 €, 79461 €, 43.4%
    184000 €, 79971 €, 43.5%
    185000 €, 80481 €, 43.5%
    186000 €, 80991 €, 43.5%
    187000 €, 81501 €, 43.6%
    188000 €, 82011 €, 43.6%
    189000 €, 82521 €, 43.7%
    190000 €, 83031 €, 43.7%
    191000 €, 83541 €, 43.7%
    192000 €, 84051 €, 43.8%
    193000 €, 84561 €, 43.8%
    194000 €, 85071 €, 43.9%
    195000 €, 85581 €, 43.9%
    196000 €, 86091 €, 43.9%
    197000 €, 86601 €, 44.0%
    198000 €, 87111 €, 44.0%
    199000 €, 87621 €, 44.0%
    200000 €, 88131 €, 44.1%