moneymanagerex / mmex-ios

Manage your finances on-the-go, encrypted for security, and sync via your storage
https://ios.moneymanagerex.org/
11 stars 2 forks source link

Currency conversion rates #228

Open georgeef opened 5 days ago

georgeef commented 5 days ago

Currency conversion rates are stored in:

MMEX Desktop assumes that a base currency is always defined and it interprets the conversion rate of a currency C as the rate with respect to the base currency B, i.e.,

This formula assumes that B.rate is always equal to 1.

Problems

If the base currency is changed from B1 to B2, all conversion rates must be scaled with 1/B2.rate, in order to maintain the invariant that the rate of the base currency is always equal to 1.

Depending on the source, conversion rates may not be available for all currency pairs. Typically they are readily available with respect to USD. If conversion rates with respect to the base currency B are not available, the rates of all wanted currencies can be downloaded with respect to USD, and then divided with the rate of B with respect to USD.

Proposed behavior of conversion rates

A base currency may or may not be defined. The conversion rates are interpreted as the rates with respect to an arbitrary (undefined) unit and only the ratio of two conversion rates is important. In practice the unit is the most convenient reference currency for the source of conversion rates, but this choice is not important.

Scaling all conversion rates with the same scale factor has no impact to balance and report calculations.

The exchange formula between two currencies C and B becomes:

The flow of a set of transactions, expressed in currency B, is defined as

where t is one side of a transaction, ±t.amount is the signed amount (positive for deposit and for the "to" side of a transfer, negative for withdrawal and for the "from" side of a transfer), t.a is the account of t, and t.a.c is the currency of t.a.

The flow calculation may be optimized by factoring out common terms, e.g.,

where

As seen in the above formulas, only the ratio C.rate/B.rate is significant.

georgeef commented 5 days ago

@guanlisheng as FYI