ANALISIS DE PROGRESIVIDAD:

En enero de 2015 entra en vigor la reforma fiscal propuesta por el ministro Montoro. Esta reforma modifica varias figuras impositivas, en este artículo nos centramos en el IRPF.

¿Por que analizar el IRPF? Por que básicamente es el impuesto estrella del gobierno por su importancia en recaudación y en los efectos en el mercado laboral.


In [133]:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ---------------------------------------------------------------------------------
# CARGAR LIBRERIAS
# ---------------------------------------------------------------------------------

import numpy as np
import scipy as sc
import matplotlib.pyplot as plt
import seaborn as sns

# ESTO INCRUSTA LOS GRAFICOS EN LA MISMA PAGINA
%matplotlib inline 

sns.set_context(rc={"figure.figsize": (18, 13)})

print u"Introducimos datos para simular una serie de rentas para aplicar los tipos del IRPF y estudiar su comportamiento"
print u"La simulación por defecto crea una serie desde 5000 hasta 400000 con incrementos de 1000"

# r = raw_input(u"Para cambiar los parámetros de la simulación escriba 1, sino 0: ")


Introducimos datos para simular una serie de rentas para aplicar los tipos del IRPF y estudiar su comportamiento
La simulación por defecto crea una serie desde 5000 hasta 400000 con incrementos de 1000

INTRODUCCIÓN DE LOS DATOS DE IRPF PARA EL CASO DE ARAGON:


In [134]:
####################################################################################
####                          DATOS ACTUALES DE IRPF                         #######
####################################################################################

base_actual = [0, 17707.20, 33007.20, 53407.20, 120000.00, 175000.00, 300000.00]
cuota_actual = [0, 4382.53, 8972.53, 17132.53, 48431.15, 75381.15, 139131.15]
t_actual = [0.2475, 0.3000, 0.4000, 0.470, 0.490, 0.510, 0.520]

####################################################################################
#########                     DATOS REFORMA DE 2015:                        ########
####################################################################################

t_estatal = [.10, .125, .155, .195, .235]
t_aragon = [.10, .125, .1550, .19, .215]

t_2015 = [t_estatal[i] + t_aragon[i] for i in range(5)]
base_2015 = [0, 12450.00, 20200.00, 34000.00, 60000.00]
cuota_2015 = [0, 2490, 4427.5, 8705.5, 18715.5]

In [135]:
####################################################################################
##############             SIMULACIÓN E INCOGNITAS:             ####################
####################################################################################

# SIMULAMOS UNA SERIE DE RENTAS:

# calculamos una serie de bases liquidas para simular el comportamiento. Agregar # al principio de la linea para activar la siguiente.
try:
    if int(r) == 1:
        base_sim = range(int(raw_input(">Renta de inicio: ")), int(raw_input(">Renta final: ")), int(raw_input(">Incremento: "))) # eliminar el primer # para controlar la simulacion
    else:
        base_sim = range(5000, 400000, 1000)
except (RuntimeError, TypeError, NameError):
    base_sim = np.arange(1000, 400000, 100)
    
# DECLARAMOS LAS INCOGNITAS:

t_me_actual = []
t_mg_actual = []
ci_actual = []

ci_2015 = []
t_me_2015 = []
t_mg_2015 = []

CALCULOS DE LA SIMULACIÓN:

  • CUOTA
  • TIPOS MEDIOS Y MARGINALES

In [136]:
####################################################################################
#####      2014: CALCULO DE CUOTA, TIPOS MARGINALES Y MEDIO DEL ACTUAL IRPF:  ######
####################################################################################

'''
Para hallar las incognitas creo dos variables comp_actual e ind_actual,
el primero lo que hace es comparar la lista de las bases de cada tramo con la base
simulada y crea una lista que devuelve TRUE o FALSE para cada tramo, para saber
que indice es y poder aplicar los tipos y cuotas del tramo correspondiente aplicamos
ind_actual que busca el primer TRUE de y devuelve el indice al que corresponde el tramo.
'''

comp_actual = [[base_sim[i] <= base_actual[ii] for ii in range(len(base_actual))] for i in range(len(base_sim))]
ind_actual = []

for i in range(len(base_sim)):
	if True in comp_actual[i]:
	
		ind_actual.append(comp_actual[i].index(True) - 1)
	else: 
		ind_actual.append(len(base_actual) - 1)

for i in range(len(base_sim)):

	ci_actual.append(cuota_actual[ind_actual[i]] + (base_sim[i] - base_actual[ind_actual[i]]) * t_actual[ind_actual[i]])
	t_mg_actual.append(t_actual[ind_actual[i]])
	t_me_actual.append(ci_actual[i] / base_sim[i])

####################################################################################
#        2015: CALCULOS CUOTAS, TIPO MARGINAL Y TIPO MEDIO TRAS LA REFORMA 2015    #
####################################################################################

comp_2015 = [[base_sim[i] <= base_2015[ii] for ii in range(len(base_2015))] for i in range(len(base_sim))]
ind_2015 = []
for i in range(len(base_sim)):
	if True in comp_2015[i]:
	
		ind_2015.append(comp_2015[i].index(True) - 1)
	else: 
		ind_2015.append(len(base_2015) - 1)

for i in range(len(base_sim)):
	ci_2015.append(cuota_2015[ind_2015[i]] + (base_sim[i] - base_2015[ind_2015[i]]) * t_2015[ind_2015[i]])
	t_mg_2015.append(t_2015[ind_2015[i]])
	t_me_2015.append(ci_2015[i] / base_sim[i])

PRESENTACIÓN DE RESULTADOS

DATOS USADOS NORMATIVA 2014


In [137]:
# ---------------------------------------------------------------------------------
# VISUALIZAR DATOS
# ---------------------------------------------------------------------------------
def ver_datos_ac():

	print "{:^45}".format("DATOS IRPF GLOBAL 2014 PARA ARAGON")
	print "{:^45}".format("=" * 45)
	print "{:^10}\t{:^10}\t{:^10}".format("BASE", "CUOTA", "GRAVAMEN")
	print "{:^10}\t{:^10}\t{:^10}".format("-" * 10, "-" * 10, "-" * 10)
	for i in range(len(base_actual)):
		print "{:>10.1f}\t{:>10.2f}\t{:>10.3f}".format(base_actual[i], cuota_actual[i], t_actual[i])
	print "{:^45}".format("=" * 45)
	print ""


	plt.figure(figsize=(15,6), dpi=800)
	plt.suptitle(u"IRPF GLOBAL 2014 PARA ARAGÓN", fontsize=15)
	plt.plot(base_sim, t_mg_actual, linewidth=2)
	plt.fill_between(base_sim, t_mg_actual, 0, alpha=0.3)
	plt.yticks(t_actual, fontsize=12)
	plt.xticks(base_actual, fontsize=12)
	plt.xlabel("Base")
	plt.ylabel("Tipo Impositivo")
	plt.margins(0.03)
	plt.xlim(0,350000)

	plt.show()

ver_datos_ac()


     DATOS IRPF GLOBAL 2014 PARA ARAGON      
=============================================
   BASE   	  CUOTA   	 GRAVAMEN 
----------	----------	----------
       0.0	      0.00	     0.247
   17707.2	   4382.53	     0.300
   33007.2	   8972.53	     0.400
   53407.2	  17132.53	     0.470
  120000.0	  48431.15	     0.490
  175000.0	  75381.15	     0.510
  300000.0	 139131.15	     0.520
=============================================

RESULTADOS DE LA SIMULACION CON LA NORMATIVA DE 2014


In [138]:
####################################################################################
######                  PRESENTACION DE DATOS VISUALES                     #########
####################################################################################


# ---------------------------------------------------------------------------------
#  CALCULOS ACTUAL:
# ---------------------------------------------------------------------------------
def ver_calculos_ac():

	

	print "{:^70}".format("CALCULOS IRPF 2014 PARA ARAGON, MUESTRA FILTRADA")
	print "{:^70}".format("="*70)
	print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("BASE","CUOTA","t\'","t*")
	print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("-"*10, "-"*10, "-"*10, "-"*10)
	for i in range(0, len(base_sim), 150):
	    print "{:>10.0f}\t{:>10.2f}\t{:^10.3f}\t{:^10.3f}".format(base_sim[i], ci_actual[i], t_mg_actual[i], t_me_actual[i])
	print "{:^70}".format("="*70)
    
ver_calculos_ac()


           CALCULOS IRPF 2014 PARA ARAGON, MUESTRA FILTRADA           
======================================================================
   BASE   	  CUOTA   	    t'    	    t*    
----------	----------	----------	----------
      1000	    247.50	  0.247   	  0.247   
     16000	   3960.00	  0.247   	  0.247   
     31000	   8370.37	  0.300   	  0.270   
     46000	  14169.65	  0.400   	  0.308   
     61000	  20701.15	  0.470   	  0.339   
     76000	  27751.15	  0.470   	  0.365   
     91000	  34801.15	  0.470   	  0.382   
    106000	  41851.15	  0.470   	  0.395   
    121000	  48921.15	  0.490   	  0.404   
    136000	  56271.15	  0.490   	  0.414   
    151000	  63621.15	  0.490   	  0.421   
    166000	  70971.15	  0.490   	  0.428   
    181000	  78441.15	  0.510   	  0.433   
    196000	  86091.15	  0.510   	  0.439   
    211000	  93741.15	  0.510   	  0.444   
    226000	 101391.15	  0.510   	  0.449   
    241000	 109041.15	  0.510   	  0.452   
    256000	 116691.15	  0.510   	  0.456   
    271000	 124341.15	  0.510   	  0.459   
    286000	 131991.15	  0.510   	  0.462   
    301000	 139651.15	  0.520   	  0.464   
    316000	 147451.15	  0.520   	  0.467   
    331000	 155251.15	  0.520   	  0.469   
    346000	 163051.15	  0.520   	  0.471   
    361000	 170851.15	  0.520   	  0.473   
    376000	 178651.15	  0.520   	  0.475   
    391000	 186451.15	  0.520   	  0.477   
======================================================================

- TRAS LA REFORMA


DATOS DE LA REFORMA DEL IRPF 2015


In [139]:
# ---------------------------------------------------------------------------------
# VISUALIZAR DATOS REFORMA 2015
# ---------------------------------------------------------------------------------
def ver_datos_2015():

	print "{:^45}".format("DATOS IRPF GLOBAL 2015 PARA ARAGON")
	print "{:^45}".format("=" * 45)
	print "{:^10}\t{:^10}\t{:^10}".format("BASE", "CUOTA", "GRAVAMEN")
	print "{:^10}\t{:^10}\t{:^10}".format("-" * 10, "-" * 10, "-" * 10)
	for i in range(len(base_2015)):
	    print "{:>10.1f}\t{:>10.2f}\t{:>10.3f}".format(base_2015[i], cuota_2015[i], t_2015[i])
	print "{:^45}".format("=" * 45)
print ""

ver_datos_2015()

plt.figure(figsize=(15,6), dpi=800)
plt.suptitle(u"DATOS IRPF GLOBAL 2015 PARA ARAGÓN", fontsize=15)
plt.plot(base_sim, t_mg_2015)
plt.fill_between(base_sim, t_mg_2015, 0, alpha=0.3)
plt.yticks(t_2015, fontsize=12)
plt.xticks(base_2015, fontsize=12)
plt.xlim(0,65000)
plt.xlabel("Base")
plt.ylabel("Tipo Impositivo")
plt.margins(0.03)


plt.show()


     DATOS IRPF GLOBAL 2015 PARA ARAGON      
=============================================
   BASE   	  CUOTA   	 GRAVAMEN 
----------	----------	----------
       0.0	      0.00	     0.200
   12450.0	   2490.00	     0.250
   20200.0	   4427.50	     0.310
   34000.0	   8705.50	     0.385
   60000.0	  18715.50	     0.450
=============================================

RESULTADOS SIMULADOS TRAS LA REFORMA:


In [140]:
# ---------------------------------------------------------------------------------
# VISUALIZAR LOS RESULTADOS IRPF 2015:
# ---------------------------------------------------------------------------------
# formatear como tabla '{0:>10}\t{1:>10}\t{2:^10}\t{3:^10}'.format("Base", "Cuota", "tme", "tmg")
# formatear como tabla numeros  '{:>10.0f}\t{:>10.1f}\t{:^10.3f}\t{:^10.3f}'.format(base_sim[i], round(ci_2015[i], 3), round(t_me_2015[i], 3), round(t_mg_2015[i],3))

def ver_calculos_2015():

	print "{0:^58}".format("RESULTADO CALCULOS IRPF 2015, MUESTRA FILTRADA")
	print "=" * 58
	print '{0:>10}\t{1:>10}\t{2:^10}\t{3:^10}'.format("Base", "Cuota", "tme", "tmg")
	print '{0:>10}\t{0:>10}\t{0:>10}\t{0:>10}'.format("-"*10)
	for i in range(0, len(base_sim), 500):
		print '{:>10.0f}\t{:>10.1f}\t{:^10.3f}\t{:^10.3f}'.format(base_sim[i], round(ci_2015[i], 3), round(t_me_2015[i], 3), round(t_mg_2015[i],3))
	print "=" * 58

ver_calculos_2015()


      RESULTADO CALCULOS IRPF 2015, MUESTRA FILTRADA      
==========================================================
      Base	     Cuota	   tme    	   tmg    
----------	----------	----------	----------
      1000	     200.0	  0.200   	  0.200   
     51000	   15250.5	  0.299   	  0.385   
    101000	   37165.5	  0.368   	  0.450   
    151000	   59665.5	  0.395   	  0.450   
    201000	   82165.5	  0.409   	  0.450   
    251000	  104665.5	  0.417   	  0.450   
    301000	  127165.5	  0.422   	  0.450   
    351000	  149665.5	  0.426   	  0.450   
==========================================================

ANÁLISIS GRÁFICO DE LA REFORMA:

LAS SOMBRAS SON EL AREA ENTRE LAS CURVAS RESPECTO DE TIPO MEDIO Y MARGINAL PARA EL CASO QUE NO SE GRAFICA.


In [141]:
# ---------------------------------------------------------------------------------
#                    GRAFICO DE IRFP 2014:
# ---------------------------------------------------------------------------------


plt.figure(dpi=900)
plt.suptitle(u"Análisis Gráfico: Cuota y Base", fontsize=15)
plt.subplot(3,2,1)
plt.plot(ci_actual, t_mg_actual, label = "cuota_tmg_2014")
plt.plot(ci_actual, t_me_actual, label = "cuota_tme_2014")
plt.fill_between(ci_2015, t_mg_2015, t_me_2015, color = 'black', interpolate = True, alpha=0.1)
plt.margins(0.1)
plt.xlabel("Base")
plt.ylabel("Tipo Impositivo")
plt.legend(loc = 0)

plt.subplot(3,2,3)
plt.plot(base_sim, t_mg_actual, label = "base_tmg_2014")
plt.plot(base_sim, t_me_actual, label = "base_tme_2014")
plt.fill_between(base_sim, t_mg_2015, t_me_2015, color = 'black', interpolate = True, alpha=0.1)  
plt.margins(0.1)
plt.xlabel("Base")
plt.ylabel("Tipo Impositivo")
plt.legend(loc = 0)

plt.subplot(3,2,5)
plt.plot(t_me_actual, base_sim, label = "base_tme_2014")
plt.plot(t_me_actual, ci_actual, label = "cuota_tme_2014")
plt.fill_between(t_me_2015, base_sim, ci_2015, color = 'black', interpolate = True, alpha=0.1)
plt.margins(0.1)
plt.xlabel("Tipo Impositivo")
plt.ylabel("Base, Cuota")
plt.legend(loc = 0)
plt.xticks([round(t_actual[i], 2) for i in range(len(t_actual))])

# Pinta poligonos color verde entre las lineas cuando y1 < y2 

# ---------------------------------------------------------------------------------
#                    GRAFICO DE LOS RESULTADOS DE LA REFORMA 2015:
# ---------------------------------------------------------------------------------

plt.subplot(3,2,2)
plt.plot(ci_2015, t_mg_2015, label = "cuota_tmg_2015")
plt.plot(ci_2015, t_me_2015, label = "cuota_tme_2015")
plt.fill_between(ci_actual, t_mg_actual, t_me_actual, color = 'black', interpolate = True, alpha=0.1)
plt.margins(0.031)
plt.xlabel("Base")
plt.ylabel("Tipo Impositivo")
plt.legend(loc = 0)

plt.subplot(3,2,4)
plt.plot(base_sim, t_mg_2015, label = "base_tmg_2015")
plt.plot(base_sim, t_me_2015, label = "base_tme_2015")
plt.fill_between(base_sim, t_mg_actual, t_me_actual, color = 'black', interpolate = True, alpha=0.1)  
plt.margins(0.031)
plt.xlabel("Base")
plt.ylabel("Tipo Impositivo")
plt.legend(loc = 0)

plt.subplot(3,2,6)
plt.plot(t_me_2015, base_sim, label="base_tme_2015")
plt.plot(t_me_2015, ci_2015, label="cuota_tme_2015")
plt.fill_between(t_me_actual, base_sim, ci_actual, color = 'black', interpolate = True, alpha=0.1)
plt.margins(0.031)
plt.legend(loc = 0)
plt.xlabel("Tipo Impositivo")
plt.ylabel("Base, Cuota")
plt.xticks([round(t_2015[i], 2) for i in range(len(t_2015))])

plt.show()


ANÁLISIS DE PROGRESIVIDAD:


In [142]:
####################################################################################
#                       ANALISIS DE LA PROGRESIVIDAD 2015: 
####################################################################################

lp_actual = []
arp_actual = []
LP_2015 = [] # indice LP_2015
ARP_2015 = [] # indice ARP_2015


for i in range(len(base_sim)):

    LP_2015.append(t_mg_2015[i] / t_me_2015[i]) 
    ARP_2015.append((t_mg_2015[i] - t_me_2015[i]) / base_sim[i])

    lp_actual.append(t_mg_actual[i] / t_me_actual[i])
    arp_actual.append((t_mg_actual[i] - t_me_actual[i]) / base_sim[i])

In [143]:
# ---------------------------------------------------------------------------------
# VISUALIZAR LOS RESULTADOS PROGRESIVIDAD 2015:
# ---------------------------------------------------------------------------------


def ver_calculos_prog():

	print "{0:^80}".format("ANALISIS DE PROGRESIVIDAD, MUESTRA FILTRADA")
	print "{0:<80}".format("="*78)
	print "{0:>10}\t{1:^10}\t{2:>10}\t{3:10}\t{4:10}".format("Base", "LP_14", "LP_15", "ARP_14 * 10^6", "ARP_15 * 10^6")
	print "{0:10}\t{0:10}\t{0:10}\t{0:10}\t{0:10}".format("-"*10)
	for i in range(0, len(base_sim), 500):
	    print "{0:>10.0f}\t{1:^10.3f}\t{2:10.3f}\t{3:10.5f}\t{4:10.4f}".format(base_sim[i], round(t_mg_2015[i], 4), 
	    	round(t_me_2015[i], 3), lp_actual[i], LP_2015[i], 1000000 * arp_actual[i], 1000000 * ARP_2015[i])
	print "{0:<80}".format("="*78)

ver_calculos_prog()


                  ANALISIS DE PROGRESIVIDAD, MUESTRA FILTRADA                   
==============================================================================  
      Base	  LP_14   	     LP_15	ARP_14 * 10^6	ARP_15 * 10^6
----------	----------	----------	----------	----------
      1000	  0.200   	     0.200	   1.00000	    1.0000
     51000	  0.385   	     0.299	   1.26162	    1.2875
    101000	  0.450   	     0.368	   1.20174	    1.2229
    151000	  0.450   	     0.395	   1.16298	    1.1388
    201000	  0.450   	     0.409	   1.15646	    1.1008
    251000	  0.450   	     0.417	   1.12151	    1.0792
    301000	  0.450   	     0.422	   1.12079	    1.0651
    351000	  0.450   	     0.426	   1.10183	    1.0554
==============================================================================  

REPRESENTACION DE LOS INDICES ARP Y LP ANTES Y DESPUES DE LA REFORMA:


In [144]:
def graf_indices_lp_arp():
    plt.figure("indices", figsize=(15,8), dpi=900)
    plt.suptitle(u"Índice de Progresividad: LP y ARP", fontsize=15)

    plt.subplot(2,1,1)
    plt.plot(base_sim, arp_actual, label = "ARP 2014", linewidth=2.0)
    plt.plot(base_sim, ARP_2015, label = "ARP 2015", linewidth=2.0)
    plt.fill_between(base_sim, arp_actual, ARP_2015, color = 'black', interpolate = True, alpha = 0.03) 
    plt.legend()
    plt.margins(0.01)
    plt.xticks(np.arange(0, 400000, 20000))
    plt.ylabel(u"Valor del índice")
    plt.xlabel("Base")

    plt.subplot(2,1,2)
    plt.plot(base_sim, lp_actual, label = "LP 2014", linewidth=2.0)
    plt.plot(base_sim, LP_2015, label = "LP 2015", linewidth=2.0)
    plt.fill_between(base_sim, lp_actual, LP_2015, color = 'black', interpolate = True, alpha=0.03) 
    plt.legend()
    plt.ylabel(u"Valor del índice")
    plt.xlabel("Base")
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    # plt.xlim(0,310000)
    plt.show
graf_indices_lp_arp()


CALCULO DE GANACIA RELATIVA DE PROGRESIVIDAD:

POR ENCIMA DE 0 ESTAMOS ANTES GANANCIAS DE PROGRESIVIDAD (MAS INTENSO) RESPECTO DEL MODELO DE 2014 POR DEBAJO DE 0 PERDIDAS DE PROGRESIVIDAD RESPECTO DEL AÑO 2014


In [145]:
# CALCULO DE GANANCIA O PERDIDA DE PROGRESIVIDAD CON LOS INDICES LP Y ARP NORMALIZADOS



def graf_prog_1():
    inc_arp = []
    inc_lp = []
    for i in range(len(base_sim)):
        try:
            inc_arp.append(float(((ARP_2015[i] / arp_actual[i]) - 1) * 100))
            inc_lp.append((float((LP_2015[i] / lp_actual[i]) - 1) * 100))
        except:
            inc_arp.append(0)
            inc_lp.append(0)

    plt.figure("prog_relativa", figsize = (15,4), dpi = 900)
    plt.suptitle("INCREMENTO DE PROGRESIVIDAD RESPECTO DE 2014", fontsize=15)
    plt.plot(base_sim, inc_lp, label = "Progresividad relativa LP", linewidth=2)
    plt.plot(base_sim, inc_arp, label = "Progresividad relativa ARP", linewidth=2)
    plt.fill_between(base_sim, inc_lp, 0, color = "b", alpha = 0.1,)
    plt.fill_between(base_sim, inc_arp, 0, color = "g", alpha = 0.1,)
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.xlabel("Base", fontsize=14)
    plt.ylabel("Incremento relativo (%)", fontsize=14)
    plt.legend()

graf_prog_1()


GRAFICOS DE LOS INDICES ARP Y LP INDIVIDUALIZADOS:


In [146]:
# ---------------------------------------------------------------------------------
#                        GRAFICO DEL INDICE LP 2014 2015
# ---------------------------------------------------------------------------------
plt.figure(dpi=900)
plt.suptitle(u'ANÁLISIS DE PROGRESIVIDAD', fontsize=14)

plt.subplot(2,2,3) # Divide en dos el lienzo por la vertical primer 2 y segundo 2 por la horizontal
plt.plot(base_sim, lp_actual, label = u"Índice LP_2014") 
# plt.scatter(base_sim, lp_actual) # añade los puntos en cada base
plt.xlabel("Base")
plt.ylabel("Valor del indice")
plt.margins(0.01)
plt.legend()


plt.subplot(2,2,4)
plt.plot(base_sim, LP_2015, label = "LP_2015")
# plt.scatter(base_sim, LP_2015)
plt.xlabel("Base")
plt.ylabel("Valor del indice")
plt.margins(0.01) # AGREGA UN MARGEN PARA VISUALIZAR EL GRÁFICO COMPLETO EN LOS LIMITES
plt.legend()


# ---------------------------------------------------------------------------------
#                        GRAFICO INDICE ARP 2014 2015
# ---------------------------------------------------------------------------------

plt.subplot(2,2,1)
plt.plot(base_sim, arp_actual, label = u"Índice ARP_2014")
# plt.scatter(base_sim, arp_actual, label = "ARP 2014")
plt.margins(0.01) # AGREGA UN MARGEN PARA VISUALIZAR EL GRÁFICO COMPLETO EN LOS LIMITES
plt.xlabel("Base")
plt.ylabel("Valor del indice")
plt.legend()

plt.subplot(2,2,2)
plt.plot(base_sim, ARP_2015, label = u"Índice ARP_2015")
# plt.scatter(base_sim, ARP_2015, label = "ARP 2015")
plt.legend()
plt.xlabel("Base")
plt.ylabel("Valor del indice")
plt.margins(0.01)
plt.show()


PONDERACIÓN POR FRECUENCIA DE DECLARANTES PARA TRAMOS DE BASE IMPOSNIBLE:

DATOS MEMORIA DE LA ADMINISTRACION TRIBUTARIA DE 2012.


In [147]:
from tabular_csv import *
declarantes = tabular_csv("distribución_declarantes.csv", ";") # imprime una muestra de comprobacion, intervalo de base imp

cols_declarantes = []

for i in range(len(declarantes)):
    cols_declarantes.append(declarantes[i].pop(0).decode("utf-8"))

In [147]:


In [147]:


In [148]:
print cols_declarantes


[u'tramos_bi', u'declaraciones', u'M\u20ac']

In [149]:
declarantes[1] = map(lambda x: float(x), declarantes[1])
declarantes[0] = declarantes[0][1:-1]
declarantes[1] = declarantes[1][1:-1]

aux_int = [elem.split("-") for elem in declarantes[0]]
for f,a in enumerate(aux_int):
    for e,aa in enumerate(aux_int[f]):
        aux_int[f][e] = float(aux_int[f][e])

marca_clase_bi = []
for i in aux_int:
    marca_clase_bi.append(np.mean(i))


base_sim_pond = marca_clase_bi

In [150]:
print "{:^55}".format("RESUMEN: DISTRUBUCIÓN DE DECLARANTES")
print "{:^50}".format("=" * 50)
print "{:^15}\t{:^15}\t{:^15}".format("intervalo bi", "marca de clase", "frec. declarantes")
print "{:^15}\t{:^15}\t{:^15}".format("-" * 14, "-" * 14, "-" * 14)

for i,e in enumerate(declarantes[0]):

    print "{:^15}\t{:^15.0f}\t{:^15.0f}".format(declarantes[0][i], marca_clase_bi[i], declarantes[1][i])
print "{:^50}".format("=" * 50)


         RESUMEN: DISTRUBUCIÓN DE DECLARANTES         
==================================================
 intervalo bi  	marca de clase 	frec. declarantes
-------------- 	-------------- 	-------------- 
    0-1500     	      750      	    407290     
   1500-3000   	     2250      	    539524     
   3000-4500   	     3750      	    717394     
   4500-6000   	     5250      	    898090     
   6000-7500   	     6750      	    766347     
   7500-9000   	     8250      	    760135     
  9000-10500   	     9750      	    746759     
  10500-12000  	     11250     	    863372     
  12000-13500  	     12750     	    905155     
  13500-15000  	     14250     	    874090     
  15000-16500  	     15750     	    816509     
  16500-18000  	     17250     	    754658     
  18000-19500  	     18750     	    738593     
  19500-21000  	     20250     	    658835     
  21000-22500  	     21750     	    596591     
  22500-24000  	     23250     	    550488     
  24000-25500  	     24750     	    498870     
  25500-27000  	     26250     	    454135     
  27000-28500  	     27750     	    407720     
  28500-30000  	     29250     	    386336     
  30000-33000  	     31500     	    678559     
  33000-36000  	     34500     	    562774     
  36000-39000  	     37500     	    400143     
  39000-42000  	     40500     	    292051     
  42000-45000  	     43500     	    221302     
  45000-48000  	     46500     	    176624     
  48000-51000  	     49500     	    145084     
  51000-54000  	     52500     	    120427     
  54000-57000  	     55500     	    101432     
  57000-60000  	     58500     	     85355     
  60000-66000  	     63000     	    134768     
  66000-72000  	     69000     	    101496     
  72000-78000  	     75000     	     76068     
  78000-84000  	     81000     	     57670     
  84000-90000  	     87000     	     44099     
  90000-96000  	     93000     	     33781     
 96000-120000  	    108000     	     78813     
 120000-144000 	    132000     	     37280     
 144000-168000 	    156000     	     20387     
 168000-192000 	    180000     	     12443     
 192000-216000 	    204000     	     8400      
 216000-240000 	    228000     	     5403      
 240000-360000 	    300000     	     12101     
 360000-480000 	    420000     	     4145      
 480000-600000 	    540000     	     1951      
==================================================

In [151]:
def graf_declarantes():
    plt.figure(figsize=(15,4), dpi=800)
    plt.suptitle("Distribucion de declarantes por tramo de base")
    plt.plot(marca_clase_bi, declarantes[1], label="Numero de declarantes", linewidth=3)
    plt.xlabel("BASE")
    plt.ylabel("DECLARANTES")
    plt.fill_between(marca_clase_bi, declarantes[1], 0, color="b", alpha=0.07)
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.legend()
    plt.show()

graf_declarantes()



In [169]:


In [153]:
# DECLARAMOS LAS INCOGNITAS PARA PONDERAR CON LOS DATOS DE DECLARANTES:

t_me_ac_pond = []
t_mg_ac_pond = []
ci_ac_pond = []

ci_2015_pond = []
t_me_2015_pond = []
t_mg_2015_pond = []

In [154]:
comp_actual_pond = [[base_sim_pond[i] <= base_actual[ii] for ii in range(len(base_actual))] for i in range(len(base_sim_pond))] # hayar el intervalo
ind_actual_pond = [] # agregamos el intervalo correspondiente

for i in range(len(base_sim_pond)):
	if True in comp_actual_pond[i]:
	
		ind_actual_pond.append(comp_actual_pond[i].index(True) - 1)
	else: 
		ind_actual_pond.append(len(base_actual) - 1)

for i in range(len(base_sim_pond)):

	ci_ac_pond.append(cuota_actual[ind_actual_pond[i]] + (base_sim_pond[i] - base_actual[ind_actual_pond[i]]) * t_actual[ind_actual_pond[i]])
	t_mg_ac_pond.append(t_actual[ind_actual_pond[i]])
	t_me_ac_pond.append(ci_actual[i] / base_sim_pond[i])

####################################################################################
#        2015: CALCULOS CUOTAS, TIPO MARGINAL Y TIPO MEDIO TRAS LA REFORMA 2015    #
####################################################################################

comp_2015_pond = [[base_sim_pond[i] <= base_2015[ii] for ii in range(len(base_2015))] for i in range(len(base_sim_pond))]
ind_2015_pond = []

for i in range(len(base_sim_pond)):
	if True in comp_2015_pond[i]:
	
		ind_2015_pond.append(comp_2015_pond[i].index(True) - 1)
	else: 
		ind_2015_pond.append(len(base_2015) - 1)

for i in range(len(base_sim_pond)):
	ci_2015_pond.append(cuota_2015[ind_2015_pond[i]] + (base_sim_pond[i] - base_2015[ind_2015_pond[i]]) * t_2015[ind_2015_pond[i]])
	t_mg_2015_pond.append(t_2015[ind_2015_pond[i]])
	t_me_2015_pond.append(ci_2015[i] / base_sim_pond[i])

VARIABLES IMPORTANTES:

  • base_sim_pond
  • marca_clase

    • t_me_ac_pond
    • t_mg_ac_pond
    • ci_ac_pond

    • ci_2015_pond

    • t_me_2015_pond
    • t_mg_2015_pond

In [155]:
####################################################################################
######                  PRESENTACION DE DATOS VISUALES                     #########
####################################################################################


# ---------------------------------------------------------------------------------
#  CALCULOS ACTUAL:
# ---------------------------------------------------------------------------------
def ver_calculos_ac_pond():
    print "{:^60}".format("CALCULOS IRPF 2014 PARA ARAGON")
    print "{:^60}".format("=" * 60)
    print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("Clase: BI", "Cuota", "tmg", "tme")
    print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("-" * 10, "-" * 10, "-" * 10, "-" * 10)
    for i in range(len(base_sim_pond)):
        print "{:^10.0f}\t{:^10.2f}\t{:^10.4f}\t{:^10.4f}".format(base_sim_pond[i], ci_ac_pond[i], t_mg_ac_pond[i], t_me_ac_pond[i])
    print "{:^60}".format("=" * 60)

ver_calculos_ac_pond()


               CALCULOS IRPF 2014 PARA ARAGON               
============================================================
Clase: BI 	  Cuota   	   tmg    	   tme    
----------	----------	----------	----------
   750    	  185.62  	  0.2475  	  0.3300  
   2250   	  556.88  	  0.2475  	  0.1210  
   3750   	  928.12  	  0.2475  	  0.0792  
   5250   	 1299.38  	  0.2475  	  0.0613  
   6750   	 1670.62  	  0.2475  	  0.0513  
   8250   	 2041.88  	  0.2475  	  0.0450  
   9750   	 2413.12  	  0.2475  	  0.0406  
  11250   	 2784.38  	  0.2475  	  0.0374  
  12750   	 3155.62  	  0.2475  	  0.0349  
  14250   	 3526.88  	  0.2475  	  0.0330  
  15750   	 3898.12  	  0.2475  	  0.0314  
  17250   	 4269.38  	  0.2475  	  0.0301  
  18750   	 4695.37  	  0.3000  	  0.0290  
  20250   	 5145.37  	  0.3000  	  0.0281  
  21750   	 5595.37  	  0.3000  	  0.0273  
  23250   	 6045.37  	  0.3000  	  0.0266  
  24750   	 6495.37  	  0.3000  	  0.0260  
  26250   	 6945.37  	  0.3000  	  0.0255  
  27750   	 7395.37  	  0.3000  	  0.0250  
  29250   	 7845.37  	  0.3000  	  0.0245  
  31500   	 8520.37  	  0.3000  	  0.0236  
  34500   	 9569.65  	  0.4000  	  0.0222  
  37500   	 10769.65 	  0.4000  	  0.0211  
  40500   	 11969.65 	  0.4000  	  0.0202  
  43500   	 13169.65 	  0.4000  	  0.0193  
  46500   	 14369.65 	  0.4000  	  0.0186  
  49500   	 15569.65 	  0.4000  	  0.0180  
  52500   	 16769.65 	  0.4000  	  0.0174  
  55500   	 18116.15 	  0.4700  	  0.0169  
  58500   	 19526.15 	  0.4700  	  0.0165  
  63000   	 21641.15 	  0.4700  	  0.0157  
  69000   	 24461.15 	  0.4700  	  0.0147  
  75000   	 27281.15 	  0.4700  	  0.0139  
  81000   	 30101.15 	  0.4700  	  0.0131  
  87000   	 32921.15 	  0.4700  	  0.0125  
  93000   	 35741.15 	  0.4700  	  0.0120  
  108000  	 42791.15 	  0.4700  	  0.0105  
  132000  	 54311.15 	  0.4900  	  0.0088  
  156000  	 66071.15 	  0.4900  	  0.0076  
  180000  	 77931.15 	  0.5100  	  0.0067  
  204000  	 90171.15 	  0.5100  	  0.0061  
  228000  	102411.15 	  0.5100  	  0.0055  
  300000  	139131.15 	  0.5100  	  0.0043  
  420000  	201531.15 	  0.5200  	  0.0031  
  540000  	263931.15 	  0.5200  	  0.0025  
============================================================

In [155]:


In [156]:
# ---------------------------------------------------------------------------------
# VISUALIZAR LOS RESULTADOS IRPF 2015:
# ---------------------------------------------------------------------------------


def ver_calculos_2015_pond():

    print "{:^60}".format("RESULTADO CALCULOS IRPF 2015")
    print "{:^60}".format("=" * 60)
    print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("Clase: BI", "Cuota", "tmg", "tme")
    print "{:^10}\t{:^10}\t{:^10}\t{:^10}".format("-" * 10, "-" * 10, "-" * 10, "-" * 10)
    for i in range(len(base_sim_pond)):
        print "{:^10.0f}\t{:^10.2f}\t{:^10.4f}\t{:^10.4f}".format(base_sim_pond[i], ci_2015_pond[i], t_mg_2015_pond[i], t_me_2015_pond[i])
    print "{:^60}".format("=" * 60)


ver_calculos_2015_pond()


                RESULTADO CALCULOS IRPF 2015                
============================================================
Clase: BI 	  Cuota   	   tmg    	   tme    
----------	----------	----------	----------
   750    	  150.00  	  0.2000  	  0.2667  
   2250   	  450.00  	  0.2000  	  0.0978  
   3750   	  750.00  	  0.2000  	  0.0640  
   5250   	 1050.00  	  0.2000  	  0.0495  
   6750   	 1350.00  	  0.2000  	  0.0415  
   8250   	 1650.00  	  0.2000  	  0.0364  
   9750   	 1950.00  	  0.2000  	  0.0328  
  11250   	 2250.00  	  0.2000  	  0.0302  
  12750   	 2565.00  	  0.2500  	  0.0282  
  14250   	 2940.00  	  0.2500  	  0.0267  
  15750   	 3315.00  	  0.2500  	  0.0254  
  17250   	 3690.00  	  0.2500  	  0.0243  
  18750   	 4065.00  	  0.2500  	  0.0235  
  20250   	 4443.00  	  0.3100  	  0.0227  
  21750   	 4908.00  	  0.3100  	  0.0221  
  23250   	 5373.00  	  0.3100  	  0.0215  
  24750   	 5838.00  	  0.3100  	  0.0210  
  26250   	 6303.00  	  0.3100  	  0.0206  
  27750   	 6768.00  	  0.3100  	  0.0202  
  29250   	 7233.00  	  0.3100  	  0.0198  
  31500   	 7930.50  	  0.3100  	  0.0190  
  34500   	 8898.00  	  0.3850  	  0.0180  
  37500   	 10053.00 	  0.3850  	  0.0171  
  40500   	 11208.00 	  0.3850  	  0.0163  
  43500   	 12363.00 	  0.3850  	  0.0156  
  46500   	 13518.00 	  0.3850  	  0.0151  
  49500   	 14673.00 	  0.3850  	  0.0145  
  52500   	 15828.00 	  0.3850  	  0.0141  
  55500   	 16983.00 	  0.3850  	  0.0137  
  58500   	 18138.00 	  0.3850  	  0.0133  
  63000   	 20065.50 	  0.4500  	  0.0127  
  69000   	 22765.50 	  0.4500  	  0.0119  
  75000   	 25465.50 	  0.4500  	  0.0112  
  81000   	 28165.50 	  0.4500  	  0.0106  
  87000   	 30865.50 	  0.4500  	  0.0101  
  93000   	 33565.50 	  0.4500  	  0.0097  
  108000  	 40315.50 	  0.4500  	  0.0085  
  132000  	 51115.50 	  0.4500  	  0.0071  
  156000  	 61915.50 	  0.4500  	  0.0062  
  180000  	 72715.50 	  0.4500  	  0.0054  
  204000  	 83515.50 	  0.4500  	  0.0049  
  228000  	 94315.50 	  0.4500  	  0.0045  
  300000  	126715.50 	  0.4500  	  0.0035  
  420000  	180715.50 	  0.4500  	  0.0025  
  540000  	234715.50 	  0.4500  	  0.0020  
============================================================

 CALCULAMOS EL VOLUMEN TOTAL DE LAS CUOTAS PARA 2014 Y 2015:


In [157]:
ci_ac_pond = np.multiply(ci_ac_pond, declarantes[1])
ci_2015_pond = np.multiply(ci_2015_pond, declarantes[1])

In [158]:
# faltan los tipos medios ponderados:

In [159]:
print "{:^35}".format("Cuota por numero de declarantes")
print "{:^35}".format("(unidades  x 10^6)")
print "{:^35}".format("=" * 35)
print "{:^15}\t{:^15}".format("2014", "2015")
print "{:^15}\t{:^15}".format("-" * 15, "-" * 15)
for e,ee in enumerate(ci_2015_pond):
    print "{:^15.4f}\t{:^15.2f}".format(ci_ac_pond[e] / 10 ** 6, ee / 10 ** 6)
print "{:^35}".format("=" * 35)


  Cuota por numero de declarantes  
        (unidades  x 10^6)         
===================================
     2014      	     2015      
---------------	---------------
    75.6032    	     61.09     
   300.4474    	    242.79     
   665.8313    	    538.05     
   1166.9557   	    942.99     
   1280.2785   	    1034.57    
   1552.1007   	    1254.22    
   1802.0228   	    1456.18    
   2403.9514   	    1942.59    
   2856.3297   	    2321.72    
   3082.8062   	    2569.82    
   3182.8541   	    2706.73    
   3221.9180   	    2784.69    
   3467.9674   	    3002.38    
   3389.9498   	    2927.20    
   3338.1474   	    2928.07    
   3327.9036   	    2957.77    
   3240.3452   	    2912.40    
   3154.1356   	    2862.41    
   3015.2403   	    2759.45    
   3030.9489   	    2794.37    
   5781.5737   	    5381.31    
   5385.5502   	    5007.56    
   4309.4001   	    4022.64    
   3495.7483   	    3273.31    
   2914.4699   	    2735.96    
   2538.0251   	    2387.60    
   2258.9071   	    2128.82    
   2019.5186   	    1906.12    
   1837.5569   	    1722.62    
   1666.6542   	    1548.17    
   2916.5340   	    2704.19    
   2482.7085   	    2310.61    
   2075.2222   	    1937.11    
   1735.9331   	    1624.30    
   1451.7896   	    1361.14    
   1207.3717   	    1133.88    
   3372.4986   	    3177.39    
   2024.7197   	    1905.59    
   1346.9925   	    1262.27    
   969.6973    	    904.80     
   757.4377    	    701.53     
   553.3274    	    509.59     
   1683.6260   	    1533.38    
   835.3466    	    749.07     
   514.9297    	    457.93     
===================================

In [160]:
plt.figure("cuotas_ponderadas", figsize=(15,7), dpi=800)
plt.suptitle("CUOTA ABSOLUTA", fontsize=15)
plt.plot(base_sim_pond, ci_ac_pond, label="cuota_total_2014")
plt.plot(base_sim_pond, ci_2015_pond, label="cuota_total_2015")
plt.fill_between(base_sim_pond, ci_ac_pond, 0, color="b", alpha=0.07)
plt.fill_between(base_sim_pond, ci_2015_pond, 0, color="g", alpha=0.07)
plt.margins(0.01)
plt.xlabel("BASE")
plt.ylabel("VOLUMEN DE CUOTA")
plt.xticks(range(0,int(base_sim_pond[-1]), 25000))
plt.axhline(y=np.mean(ci_ac_pond), alpha=0.5, label="Media CI 2014")
plt.axhline(y=np.mean(ci_2015_pond), color="g", alpha=0.5, label="Media CI 2015")
plt.legend()


Out[160]:
<matplotlib.legend.Legend at 0x11643ce10>

In [170]:
def graf_recaudacion():    
    var_cuota_pond = np.divide(ci_2015_pond, ci_ac_pond) - 1

    plt.figure(figsize=(15,8), dpi=800)
    plt.subplot(2,1,1)
    plt.suptitle("CUOTA ABSOLUTA", fontsize=15)
    plt.plot(base_sim_pond, ci_ac_pond, label="cuota_total_2014")
    plt.plot(base_sim_pond, ci_2015_pond, label="cuota_total_2015")
    plt.fill_between(base_sim_pond, ci_ac_pond, 0, color="b", alpha=0.07)
    plt.fill_between(base_sim_pond, ci_2015_pond, 0, color="g", alpha=0.07)
    plt.legend()
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.xlabel("BASE")
    plt.ylabel("VOLUMEN DE CUOTA")

    plt.subplot(2,1,2)
    plt.suptitle("VARIACION RELATIVA ENTRE NORMATIVA 2014-2015", fontsize=15)
    plt.plot(base_sim_pond, var_cuota_pond * 100, label="variacion de la cuota")
    plt.legend()
    plt.xlabel("BASE")
    plt.ylabel("VARIACION DE LA CUOTA (%)")
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.fill_between(base_sim_pond, var_cuota_pond * 100, 0, color="b", alpha=0.07)

graf_recaudacion()



In [162]:
# faltan los marginales de la renta ponderada
#

In [163]:
lp_actual_pond = []
arp_actual_pond = []
LP_2015_pond = [] # indice LP_2015
ARP_2015_pond = [] # indice ARP_2015


for i in range(len(base_sim_pond)):

    LP_2015_pond.append(t_mg_2015_pond[i] / t_me_2015_pond[i]) 
    ARP_2015_pond.append((t_mg_2015_pond[i] - t_me_2015_pond[i]) / base_sim_pond[i])

    lp_actual_pond.append(t_mg_ac_pond[i] / t_me_ac_pond[i])
    arp_actual_pond.append((t_mg_ac_pond[i] - t_me_ac_pond[i]) / base_sim[i])

In [171]:
def graf_prog_recaudacion():
    plt.figure(figsize=(15,8), dpi=800)

    plt.subplot(2,1,1)
    plt.plot(base_sim_pond, lp_actual_pond, linewidth=2, label="LP 2014")
    plt.plot(base_sim_pond, LP_2015_pond, linewidth=2, label="LP 2015")
    plt.fill_between(base_sim_pond, lp_actual_pond, 0, color="b", alpha=0.09)
    plt.fill_between(base_sim_pond, LP_2015_pond, 0, color="g", alpha=0.09)
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.legend()

    plt.subplot(2,1,2)
    plt.suptitle("INDICE LP Y ARP")
    plt.plot(base_sim_pond, arp_actual_pond, linewidth=2, label="ARP 2014")
    plt.plot(base_sim_pond, ARP_2015_pond, linewidth=2, label="ARP 2015")
    plt.fill_between(base_sim_pond, arp_actual_pond, 0, color="b", alpha=0.09)
    plt.fill_between(base_sim_pond, ARP_2015_pond, 0, color="g", alpha=0.09)
    plt.xticks(np.arange(0, 400000, 20000))
    plt.xlim(0,400000)
    plt.legend()

graf_prog_recaudacion()


COMPAREMOS:


In [172]:
graf_declarantes()
graf_indices_lp_arp()
graf_prog_1()
graf_recaudacion()
graf_prog_recaudacion()


¿cuanto debería ser el tmg 2015 para el ultimo tramo si queremos que se mantenga el mismo nivel de progresividad?


In [165]:
# LP_15 = LP_14 = tmg_15* / tme_15

In [165]:

INDICIANDO LAS TARIFAS: INFLACION DEL ULTIMO DATO DE IPC.


In [165]: