FMP

FMP

Enter

Currency exposure may be one of the biggest headaches for big companies. From an investor perspective, it is important to understand the implications that chang

Analyze the impact of exchange rates in companies using Python

-

twitterlinkedinfacebook
blog post cover photo

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 = {}

key = 'your api key'

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']:

adj_close = item['adjClose']

trade_date = item['date']

exchange_rates_Python[currency][trade_date] = adj_close

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

Nov 25, 2023 6:39 AM - Parth Sanghvi

DCF Valuation vs. Comparable Companies Analysis: Choosing the Right Valuation Method

Choosing the Right Valuation Method: DCF vs. Comparable Companies Analysis Introduction: Valuation methods play a pivotal role in determining the fair value of a company, aiding investors in making informed investment decisions. Two commonly used methods, DCF Valuation and Comparable Companies A...

blog post title

Dec 25, 2023 2:31 AM - Parth Sanghvi

Decoding the Discounted Cash Flow (DCF) Model: A Comprehensive Guide for Strategic Investment Analysis

Introduction: The Discounted Cash Flow (DCF) model stands as a cornerstone in investment analysis, offering a robust framework for estimating the intrinsic value of an investment. In this comprehensive guide, we delve into the fundamentals of DCF analysis, providing step-by-step instructions, key...

blog post title

Jan 4, 2024 1:56 AM - Parth Sanghvi

Optimizing DCF Model Accuracy: Advancements through Big Data and AI Integration

The Discounted Cash Flow (DCF) model remains a cornerstone in financial analysis, offering a strategic way to assess the intrinsic value of an investment. With advancements in technology, the integration of Big Data and Artificial Intelligence (AI) presents a transformative approach to enhance the p...

blog post title
FMP

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.
twitterlinkedinfacebookinstagram
2017-2024 © Financial Modeling Prep