Reforms#

To define a reform, simply define a class inheriting from Reform with an apply(self) function. Inside it, self is the tax-benefit system attached to the simulation with loaded data self.simulation: Simulation. From this, you can run any kind of modification on the Simulation instance that you like- modify parameters, variable logic or even adjust simulation data.

from policyengine_core.country_template import Microsimulation
from policyengine_core.model_api import *

baseline = Microsimulation()


class reform(Reform):
    def apply(self):
        simulation = self.simulation

        # Modify parameters

        simulation.tax_benefit_system.parameters.taxes.housing_tax.rate.update(
            20
        )

        # Modify simulation data

        salary = simulation.calculate("salary", "2022-01")

        new_salary = salary * 1.1

        simulation.set_input("salary", "2022-01", new_salary)


reformed = Microsimulation(reform=reform)
reformed.calculate("salary", "2022-01"), baseline.calculate(
    "salary", "2022-01"
)
(   value     weight
 0  110.0  1000000.0
 1    0.0  1000000.0
 2  220.0  1200000.0,
    value     weight
 0  100.0  1000000.0
 1    0.0  1000000.0
 2  200.0  1200000.0)
reformed.calculate("housing_tax", 2022), baseline.calculate(
    "housing_tax", 2022
)
(   value     weight
 0  200.0  1000000.0
 1  200.0  1200000.0,
    value     weight
 0  200.0  1000000.0
 1  200.0  1200000.0)