title: how to convert any forex pair quote to usd value?
body: <p>Is it possible to convert any forex pair quote to usd value?</p>
  
  <p>I tried using following code but it gives incorrect results:</p>
  
  <pre><code>def calculate_instrument_value_in_account_currency(currency, current_prices, instruments):
  
      instrument_values = []
  
      #dictionary to keep prices for each currency, assuming that current_prices has prices in the same order as instruments list has instument names
      prices_for_currency = {}
  
      instrument_index = 0
      for instrument in instruments:
          prices_for_currency[instrument] = current_prices[instrument_index]
          instrument_index += 1
  
      #account currencu is USD
      if currency == 'USD':
          m = 0            
          for instrument in instruments:                                               
              first_currency = instrument[0:3]
              second_currency = instrument[4:7]
  
              #counter currency same as account currency
              if second_currency == 'USD':
                  instrument_value = current_prices[m]
              #base currency same as account currency    
              elif first_currency == 'USD':
                  instrument_value = 1 / current_prices[m]
              #none of the currency pair is the same as account currency
              #is needed the currency rate for the base currency/account currency
              else:
                  if second_currency == 'JPY':
                      JPY_to_USD = prices_for_currency[currency+"/"+second_currency]
                      USD_to_JPY = 1 / JPY_to_USD
                      instrument_value = current_prices[m] * USD_to_JPY
  
                  else: 
                      USD_to_GBP = prices_for_currency[second_currency+"/"+currency]
                      instrument_value =  current_prices[m] * USD_to_GBP
  
              instrument_values.append(instrument_value)
              m += 1    
  
      return instrument_values 
  </code></pre>