Two things were wrong with this code:
1. The exchange rate conversion was backward. Since we work in USD, I
removed the conversion and used value_usd instead.
2. The calculation of pscale.factor was incorrect. If the old value is
1000, and we need to get to 1020, the record to be inserted must have
a value of 20, thus the value for factor needs to be:
(1020 - 1000) / 1000 = (1020 / 1000) - 1 = 0.02
0.02 * 1000 = 20, which is inserted in the new record.
The subtraction was missing before, which of course caused WAY wrong
numbers that should have been caught a long time ago. It was doing:
1020 / 1000 = 1.02
1.02 * 1000 = 1020 was inserted, doubling the intended adjustment.