28
Opening up the French tax software http://www.openfisca.fr/ https://framagit.org/openfisca https://github.com/openfisca @OpenFisca Michel Blancard [email protected] PyData – June 14, 2016

Opening up the French tax software

  • Upload
    etalab

  • View
    300

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Opening up the French tax software

Opening up the French tax software

http://www.openfisca.fr/https://framagit.org/openfiscahttps://github.com/openfisca

@OpenFisca

Michel [email protected]

PyData – June 14, 2016

Page 2: Opening up the French tax software

I - What is OpenFisca?

Page 3: Opening up the French tax software

Legislation

It's growing!

In French (that most French people don't understand),

not in python!

NoticesBulletin Officiel des Finances

Publiques-Impôts (BOFiP)

Décrets

How to compute the French tax and benefits?

Page 4: Opening up the French tax software

It's complex!

4

How to compute the French tax and benefits?

Page 5: Opening up the French tax software

It's complex, because the reality is complex.

IndividualsHousingFamilyTaxation

How to compute the French tax and benefits?

Page 6: Opening up the French tax software

OpenFisca aims to :● cover both tax and benefits policies● be efficient

● one family simulation● simulation on the whole country

● be understandable● be open source

What is OpenFisca?

Page 7: Opening up the French tax software

OpenFisca is used for :● improving readability

to the public● designing reforms● simulating one's

situation● understanding the tax

and social system

mes-aides.gouv.fr

Why compute the French tax and benefits?

Page 8: Opening up the French tax software

OpenFisca is used for :● improving readability

to the public● designing reforms● simulating one's

situation● understanding the tax

and social system

How to compute the French taxes ?

tax difference between/after marriage

Page 9: Opening up the French tax software

OpenFisca is used for :● improving readability

to the public● designing reforms● simulating one's

situation● understanding the tax

and social system

How to compute the French taxes ?

personal simulationui.openfisca.fr

Page 10: Opening up the French tax software

OpenFisca is used for :● improving readability

to the public● designing reforms● simulating one's

situation● understanding the

tax and social system

How to compute the French taxes ?

tax percentage as a function of income

Page 11: Opening up the French tax software

The history of OpenFisca

2011 2014 2016

2 economists

python scripts with QT frontend

2 developers join the project

tax calculator of the tax administration

released

increasing demand for an open simulator

OpenFisca reaches the sky and beyond...

(see later)

France StratégieFrance StratégieIPPEtalab

Page 12: Opening up the French tax software

II – The French tax calculator

Page 13: Opening up the French tax software

● direct demand (aug 2014)● 6 months later : seisine of the CADA● 2 months later : positive notice from the CADA● 2 months later : beginning of judicial proceedings● 10 months later : release of the source code !● 10 months later + ε : the court issues a positive decision

The quest for the source code

(want to speed up the process ? → ouvre-boite.org)

Page 14: Opening up the French tax software

● April 1-2, 2016 at the Mozilla Fundation● presence of 3 Ministers● developers, civil servants, economists,

citizens... all sitting at the same table !

A hackathon to celebrate : CodeImpôt

Page 15: Opening up the French tax software

Preparation by Etalab and DGFiP :● understand the Domain Specific

Language (DSL) : M● parse using Clean PEG (Igor

Dejanović's Arpeggio)● simplify the Abstract Syntax Tree

(AST)

→ Direct Acyclic Graph of trees

Preparationregle 10214:application : iliad,batch ;CSGAC = max(0,CSGC ­ CICSG);

CSNET = max(0,(CSGC + PCSG ­ CICSG ­ CSGIM)) ;

RDSAC = max(0,RDSC ­ CIRDS);RDNET = max(0,(RDSC + PRDS ­ 

CIRDS ­ CRDSIM));

PRSNET = max(0,(PRSC + PPRS ­ CIPRS ­ PRSPROV))  ;

CVNAC  =  CVNSALC;CVNNET  =  max(0,(CVNSALC + PCVN 

­ COD8YT));

REGVNET  = BREGV + PREGV ;

CDISAC = CDISC ;CDISNET = max(0,(CDISC + PCDIS ­ 

CDISPROV))  ;CGLOAAC = CGLOA ;CGLOANET = max(0,(CGLOA + PGLOA­

COD8YL ))  ;

Page 16: Opening up the French tax software

Preparation by Etalab and DGFiP :● understand the Domain Specific

Language (DSL) : M● parse using Clean PEG (Igor

Dejanović's Arpeggio)● simplify the Abstract Syntax Tree

(AST)

→ Direct Acyclic Graph of trees

Preparation

comment = r'\#.*'

symbol = r'\w+'symbol_enumeration = symbol 

("," symbol)*float = r'\d+\.\d+'integer = r'\d+'string = '"' r'[^"]*' '"'interval = symbol ".." symbolbrackets = "[" symbol "]"

...

Page 17: Opening up the French tax software

Preparation by Etalab and DGFiP :● understand the Domain Specific

Language (DSL) : M● parse using Clean PEG (Igor

Dejanović's Arpeggio)● simplify the Abstract Syntax Tree

(AST)

→ Direct Acyclic Graph of trees

Preparation

Python object / JSON

Page 18: Opening up the French tax software

● Directed Acyclic Graph (DAG) traversal (400ms)

● Arithmetic computations at each node (0.4ms in total for a single simulation)

During the hackathonEfficient computation

vs400ms + 0.4ms = 400.4ms

for 1 simulation

400ms + 10.000x0.4ms = 4.4s

for 10.000 simulation

Long live Numpy and vectorized computations !

Page 19: Opening up the French tax software

During the hackathonVisualise

Page 20: Opening up the French tax software

During the hackathonSimplify the graph for common fiscal situations

Page 21: Opening up the French tax software

During the hackathonTranspile to other languages

var functionsMapping = {

    '+':function sumTab(tabValeurs){         return tabValeurs.reduce(function(a,b){            return a+b;        });    },

    '*':function mulTab(tabValeurs){        return tabValeurs.reduce(function(a,b){            return a*b;        });    },

    . . .

Step 1 : Define an implementation of the operations

Page 22: Opening up the French tax software

During the hackathonTranspile to other languages

function computeFormula(node, values){    if(node.nodetype ==='symbol'){        var value = values[node.name];        if(typeof(value)==='undefined'){            value = 0;        };        return value    }else if(node.nodetype ==='float'){        return node.value;    }else if(node.nodetype==='call'){        var name = node.name;        var func = functionsMapping[name];        var args = [];        for(i in node.args){            args.push(computeFormula(node.args[i],values));        }        return func(args);    }}

Step 2 : Code a DAG traversal

Page 23: Opening up the French tax software

III – From code to data

Page 24: Opening up the French tax software

II – The French tax calculator

Tax rules vs implementation

Rule of least power

different concerns

storageversioning

editing

speedsimplicity

(technologies evolve fast)

Page 25: Opening up the French tax software

Python Code Quality Authority

Parsing the current code

Baron

Redbaron

Astroid Custom pythonpython → julia

2to3

Page 26: Opening up the French tax software

The future

Tax rules written in

DSL(s)

Unique internal graph

representation

Implementation(s)

The glue ? Python ? A functional language ?

Page 27: Opening up the French tax software

Take-away message

Language choice is not definitive !(if you start with python)

Page 28: Opening up the French tax software

Thank you !

http://www.openfisca.fr/https://framagit.org/openfiscahttps://github.com/openfisca

@OpenFisca

Michel [email protected]

PyData – June 14, 2016

We are hiring !