electricitymaps / bloom-contrib

Making carbon footprint data available to everyone.
https://www.bloomclimate.com
MIT License
436 stars 104 forks source link

Fix co2eq cpi conversion. #447

Closed pierresegonne closed 4 years ago

pierresegonne commented 4 years ago

Looking at the CO2e transparency flow, I realised the massive mistake I did in the past when implementing the CPI conversion.

The conversion used to be done with

const eurAmountAdjusted = eurAmount * (CPIcurrent / CPIreference);

where CPIcurrent refers to the CPI for the year of the datetime of the activity and CPIreference to the CPI for the year of the reference year (2011 for EXIOBASE data). It should be instead:

const eurAmountAdjusted = eurAmount * (CPIreference / CPIcurrent);

To show why, imagine 10€ in 2020€ spent in DE. The CPI for 2011 is 95.2, the CPI for 2020 is 105.5. With the old model, the adjusted price would thus be 10 (105.5 / 95.2) = 11.08€. With the new model it becomes 10 (95.2 / 105.5) = 9.02€. To check, think about old prices re-adjusted for current money, the old prices are always lower than current prices (at least for most countries on the long scale, see for example https://www.bankofengland.co.uk/monetary-policy/inflation/inflation-calculator )

A sanity check on the homgeneity of the formula shows it too:

X{€,2011} = X{€,2020} * (CPI{2011} / CPI{2020})

martincollignon commented 4 years ago

Good job on finding this!