# finance.fx-revaluation
At a period end, monetary balances held in a foreign currency (bank accounts,
receivables, payables, loans) are restated at the closing rate, and the
difference from what the books carried them at is an unrealised exchange gain
or loss (IAS 21 paragraph 23 and FRS 102 section 30 require monetary items to be
translated at the closing rate). This works out that difference, one balance at
a time, and the net total to post.
Sign convention: an asset is a positive balance and a liability a negative one,
in both currencies. `gainLoss` is the revalued value less the booked value, so
it is positive for a gain and negative for a loss whichever side the balance is
on. A USD 10,000.00 receivable booked at GBP 7,800.00 and revalued at 0.75 is
GBP 7,500.00, a loss of 300.00; the same amount owed to a supplier (-10,000.00
booked at -7,800.00) is a gain of 300.00, because the pounds needed to settle it
fell.
Conversion is money.convert: the rate is an exact fraction in major units, the
decimal places of each currency are looked up (yen has none), and the one
rounding to the functional currency's minor unit is half-up, symmetric for
negative balances. Each line is rounded on its own, and the net is the sum of
the rounded lines, so it agrees with the postings.
Each foreign currency needs exactly one rate into the functional currency; a
missing or duplicated rate is an error rather than a guess, and so is a balance
already in the functional currency or a booked value that is not. Choosing the
closing rate (which source, which day) is the caller's decision.
Non-monetary items (stock, fixed assets, prepayments) stay at historical rates
and must not be passed here. After posting, the revalued value becomes the new
booked value for the next period.