FMP

# Analyze the impact of exchange rates in companies using Python

## Analyze the impact of exchange rates in companies using Python

Sep 11, 2023 5:33 PM - Rajnish Katharotiya

#### Image credit: Shubham Dhage

Currency exposure may be one of the biggest headaches for big companies. From an investor perspective, it is important to understand the implications that changes in exchange rates have in company financials. In this post, we will first understand how exchange rates affect company profits. Then, we will analyse and plot multiple currency exchange rates with Python.

Photo by Disha Shera on Pexels

## How exchange rates impact companies

Exchange rates are an important factor to take into account when analysing a company. A company may have USD as functional currency (i.e. currency that a company prepares financial results) but have operations (e.g. sales, loans, suppliers, etc.) in a different currency.

When presenting financial results, firms must distinguish between monetary and non-monetary assets/liabilities:

• Monetary assets/ liabilities are those assets that are readily convertible to cash. These assets are retranslated from other currencies to the functional currency of the company at the reporting date. Any gains or losses on the revaluation will impact the profits of the company. For instance, receivables, payables, cash balances and loans are considered as monetary assets/liabilities.

• Non-monetary assets/liabilities are those that are not retranslated at the reporting date. They are shown in the financial statements using the historical rate (i.e. rate used when the asset was acquired). For instance, inventory, PP&E and intangible assets are considered as non-monetary assets.Exchange rate impact on Accounts PayablesAccount Payables are amounts that companies own to their creditors or suppliers.

To understand the impact of exchange rates in a company accounts payables, lets use company ABCD as an example.

Imagine that company ABCD, which reports their numbers in USD is:

• Buying 10,000€ in materials from an European supplier.

• The exchange rate at the transaction date is EURUSD = 1.10. Meaning that \$1.10 are needed to buy 1€.

• The purchase will only be payable in 4 months time.

• At the time of the purchase, company ABCD shows \$11,000 (10,000€ *1,10) as account payables in the balance sheet.

• Suppose that three months later, when company ABCD is preparing the financial statements, the exchange rate EURUSD has gone down from 1.10 to 0.90. Meaning that we only need \$0.90 to buy 1€. Due to the exchange rate change, company ABCD bottom line will be impacted. Now, it only requires \$9,000 (10,000€ *0.90) to pay back the initial 10,000€.

Therefore, company ABCD will reduce the liability account payables in the balance sheet by \$2,000 and show a \$2,000 increase in profits through an unrealised gain.

## Exchange rate impact on Loans

Similarly, if a company has a loan denominated in foreign currency and the exchange rates fluctuates, there will be an impact in the company profit and loss.

Suppose that company ABCD has a 10,000€ loan. When the EURUSD exchange rates was 1.10, the company was showing \$11,000 as loan in the Balance Sheet. However, when the EURUSD moves from 1.10 to 0.90, company ABCD will report a loan of only 9,000\$ in the balance sheet. At the same time, it will report an unrealised gain of \$2,000 in profit and losses.

The gain will be realised once the loan is paid back to the bank.

## Impact on Exchange Rates in Sales

Interesting, right? Based on the previous two examples, it seems that a company reporting in USD will always benefit when the USD appreciates against other currencies.

Well, this is not always true. Companies selling to countries where currencies are losing value (i.e. depreciating) makes them less competitive. The impact of a firm losing competitive power may be translated into a significant drop on sales volumes.

Imagine company ABCD in the scenario where the USD has appreciated against the EUR. Now a European company will need to pay a higher price in euros to buy 1 product from ABCD. This may lead to the European firm to stop buying from company ABCD and find an alternative supplier in Europe.

## Exchange Rates with Python

Now we understand why exchange rates are so important when analysing a company. Next, let's learn how to calculate and plot exchange rates with Python.

We will build a Python script to retrieve historical forex data from multiple currencies and plot them using matplotlib. In the following link is possible to find all currencies for which data is available. For our example, we will extract exchange rates for below four currencies:

• EURUSD

• CHFUSD

• AUDUSD

• GBPUSD

First, we import all require packages and make a get request to the API end point returning historical exchange rates for the last few years. Note that we loop through each of the currencies. In each loop, we get the historical prices for a single currency pair.

import requests

import pandas as pd

import matplotlib.pyplot as plt

exchange_rates_Python = {}

currencies = ['EURUSD', 'CHFUSD=X', 'AUDUSD', 'GBPUSD']

for currency in currencies:

forex = requests.get(f'https://financialmodelingprep.com/api/v3/historical-price-full/forex/{currency}?apikey={key}')

forex = forex.json()

print(forex)

The response contains a dictionary with historical prices. Note that the key historical includes a list with all closing prices from the last few years. Therefore, we can loop through it in order to parse the date and the adj. close for each of the currency pairs. We store the values in an empty dictionary called exchange_rates_Python:

exchange_rates_Python[currency] = {}

for item in forex['historical']:

Finally, we convert the dictionary into a Pandas DataFrame so that is easy to plot the data using matplotlib. In addition, we convert the index (i.e. dates) into a datetime object:

currencies_df = pd.DataFrame.from_dict(exchange_rates_Python, orient='index')

currencies_df=currencies_df.T

currencies_df.index = pd.to_datetime(currencies_df.index)

## Plotting Exchange Rates with Python

Now that we have the exchange rates in a nice Pandas DataFrame, we are ready to plot them. We will use the library matplotlib to create a subplot for each of the currencies.

We will only plot the exchange rate for the last 90 days:

#take last 30 days

currencies_df = currencies_df.iloc[:90,:]

fig, axes = plt.subplots(nrows=2, ncols=2)

currencies_df[currencies[0]].plot(ax=axes[0,0])

axes[0,0].set_title(currencies[0])

currencies_df[currencies[1]].plot(ax=axes[0,1])

axes[0,1].set_title(currencies[1])

currencies_df[currencies[2]].plot(ax=axes[1,0])

axes[1,0].set_title(currencies[2])

currencies_df[currencies[3]].plot(ax=axes[1,1])

axes[1,1].set_title(currencies[3])

plt.tight_layout()

plt.show()

## Wrapping Up

Just with a few lines of code, we are able to retrieve and plot exchange rates with Python.

For instance, we might be able to see that for the last three months, USD is much stronger than for example GBP. In December 2019, we needed around \$1.33 to buy 1£, however in April of 2020, we only needed 1.22\$ to buy 1£.

That means that companies having large amounts of open payables or loan in £ are in a much better position to repay the amounts than 4 months ago. However, sales may be affected if British companies decide not to buy products in USD due to the appreciation of the currency.

As we have seen during the post, it is very important to understand a firm's currency exposure before making investment decisions. I recommend you to analyse company sales, loans and payables in terms of currency exposure.

### Other Blogs

Sep 11, 2023 - Rajnish Katharotiya

## P/E Ratios Using Normalized Earnings

Price to Earnings is one of the key metrics use to value companies using multiples. The P/E ratio and other multiples are relative valuation metrics and they cannot be looked at in isolation. One of the problems with the P/E metric is the fact that if we are in the peak of a business cycle, earni...

Sep 11, 2023 - Rajnish Katharotiya

## What is Price To Earnings Ratio and How to Calculate it using Python

Price-to-Earnings ratio is a relative valuation tool. It is used by investors to find great companies at low prices. In this post, we will build a Python script to calculate Price Earnings Ratio for comparable companies. Photo by Skitterphoto on Pexels Price Earnings Ratio and Comparable Compa...

Oct 17, 2023 - Davit Kirakosyan

## VMware Stock Drops 12% as China May Hold Up the Broadcom Acquisition

Shares of VMware (NYSE:VMW) witnessed a sharp drop of 12% intra-day today due to rising concerns about China's review of the company's significant sale deal to Broadcom. Consequently, Broadcom's shares also saw a dip of around 4%. Even though there aren’t any apparent problems with the proposed solu...

FMP

Financial Modeling Prep API provides real time stock price, company financial statements, major index prices, stock historical data, forex real time rate and cryptocurrencies. Financial Modeling Prep stock price API is in real time, the company reports can be found in quarter or annual format, and goes back 30 years in history.