IAMconsortium / units

Common unit definitions for integrated assessment research
GNU General Public License v3.0
20 stars 11 forks source link

Conversion of monetary units #25

Open danielhuppmann opened 3 years ago

danielhuppmann commented 3 years ago

As discussed in other contexts, it would be highly useful to add a module to convert between different currencies taking into account deflation and the year (or more granular?) of conversion.

I.e., converting from 2010-USD to 2020-EUR would yield different results depending on whether you first deflate from 2010 to 2020 and then convert, or vice versa.

khaeru commented 3 years ago

Good suggestion!

Some thoughts:

gidden commented 3 years ago

Hi all, luckily enough, I ran into this use case a few years ago (oh jesus, just saw it was 4 years ago in the commit log..) and wrote a small tool to help deal with it.

Salamanca treats inflation/deflation for both MER/PPP exchange calculations. It offers both an API and CLI for currency conversions specifically. Because it is based on WB data, only year-granularity is supported. An interface into the WB rest API is also provided (@coroa just helped updating it to v2) as both API and CLI.

I've been meaning to at least get the module back on its feet in terms of CI/setuptools-scm, etc. If this would help here, happy to put some time into it.

Note in addition to users at CA, I believe Ed and Miguel both use some of salamanca in other use cases. But best to check with them on that.

gidden commented 3 years ago

To note, I developed this module during the course of working on downscaling and inequality, so there's also some handy tools/conversions there as well (e.g., between Ginis and Theils).

khaeru commented 3 years ago

@gidden thanks for mentioning that!

The two packages seem to have slightly different aims, e.g. this one is narrowly aimed at making it possible to do some things via pint-parseable units, with those other (useful) tasks out of scope. So perhaps it would be most straightforward to copy/use part of the Salamanca code as reference (with appropriate credit) when addressing this issue.

Whoever tackles this enhancement can decide the best course.

danielhuppmann commented 3 years ago

One use case encountered in openENTRANCE and several IAM projects is to convert combined units, like 2010-USD/kW (for investment cost) to 2020-EUR/kW or EJ/2010-USD (for energy per GDP) to GWh/2020-EUR. It would be super-nice to combine the generality of pint & iam-units with the currency-specific features of salamanca...

gidden commented 3 years ago

Hi all, fresh new rtd, pypi tag, fully tested on all 3 oses with py 3.7/3.8. To note, currency conversion and wb rest api querying is about 2/3 of total code size (or more) as it was one of the primary purposes of the library at the time.

On Sun, Feb 28, 2021, 17:42 Daniel Huppmann notifications@github.com wrote:

One use case encountered in openENTRANCE and several IAM projects is to convert combined units, like 2010-USD/kW (for investment cost) to 2020-EUR/kW or EJ/2010-USD (for energy per GDP) to GWh/2020-EUR. It would be super-nice to combine the generality of pint & iam-units with the currency-specific features of salamanca...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/IAMconsortium/units/issues/25#issuecomment-787480985, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKUAEJZI6MY5XCW645ABOTTBJW6ZANCNFSM4YKAAIAQ .

khaeru commented 1 year ago

In #43:

I see that above I already shared some thoughts. At this point I think I see one of two options:

  1. User calls a specific method (like convert_currency()) to perform currency conversions and iam-units selects a particular context in which to do so; or
  2. User calls a specific method (like setup_currency()) to configure currency conversions, and the package inserts/updates the appropriate definitions in iam_units.registry, to then be used through ordinary pint behaviour.

In the case of (2), the method could be called by default, with a deprecation warning; and then in future releases that default call would disappear. This would avoid downstream code breakage from #43.

I'd be able to take this on, but not until middle of next week.