I am trying to calculate the price of a volume of any pair in a standard currency, which is the broker’s account currency. Let’s assume:
AC: Account Currency, this is the broker account currency, e.g. USD, EUR, etc…
Symbol: The currency pair being traded, e.g. AUDJPY
Base: Is the base of the Symbol. i.e. in AUDJPY it is AUD
Quote: Is the quote of the Symbol. i.e. in AUDJPY it is JPY
Rate: is the rate of the symbol. i.e. for AUDJPY it is 77.12
Vol: Volume being traded
Price: The price of the traded volume in the AC currency (this is what we need to calculate)
Sometimes, where the traded currency does not include the AC, we will have to introduce an intermediate exchange pair. So, if the AC is in EUR and the traded currency is AUDJPY, then the exchange currency is EURJPY.
ExSymbol: The intermediate exchange currency
ExBase: Base of the ExSymbol
ExQuote: Quote of the ExQuote
ExRate: Is the price of the symbol
I would like to validate if this pseudo-code is the right calculation?
Case 1: if AC = Base
Price = Vol
Case 2: if AC = Quote
Price = Vol x Rate
if not one of the above two cases, introduce an exchange pair
Case 3: if ExBase = Base
Price = Rate * Vol * ExRate
Case 4: if ExBase = Quote
Price = Rate * Vol / ExRate
Case 5: if ExQuote = Base
Price = Vol * ExRate;
Case 6: if ExQuote = Quote
Price = Vol / ExRate;
Let me give an example of each case:
Case 1:
AC: AUD
Symbol: AUDJPY
Case 2:
AC: JPY
Symbol: AUDJPY
Case 3:
AC: GBP
Symbol: EURUSD
ExSymbol: EURGBP
Case 4:
AC: JPY
Symbol: EURGBP
ExSymbol: GBPJPY
Case 5:
AC: EUR
Symbol: AUDJPY
ExSymbol: EURAUD
Case 6:
AC: GBP
Symbol: AUDUSD
ExSymbol: GBPUSD
I am aware that some cases, between 3 to 6 can be eliminated by picking a different exchange currency.
To make this a reference for me and everybody, could you please help me with the calculation?