I always enjoy working with currency exchange rates because it gives me excuses to draw directed graphs. For example, an exchange rate EURUSD = 1.4 can be thought of as a directed edge from EUR to USD as shown below.

A fact of life when you work in finance is that you rarely have any say in the data available to you for analysis. When working with three currencies, e.g. USD, EUR, and KRW, it would be great if someone handed you a complete FX Matrix with all exchange rates filled in like

Instead, what is usually available is a list of exchange rates such as

With a little patience, you can usually figure out all the cross terms, e.g. it is obvious that from the given data we have

but we’d like to find a systematic way to do this that can be programmed.

So the thing I want to talk about here is starting with a list of exchange rates, i.e. FX Vector, we want to fill in as much of the FX Matrix as possible systematically. It turns out this process is identical to constructing a free category, i.e. quiver, from a directed graph.

In other words, we want to reinterpret the exchange rate as a morphism

Then, “filling in” the FX Matrix means finding all compositions of morphisms, e.g.

How would you do this? Here is what I did…

First, you take the given FX Vector and form an adjacency matrix. In the example above with EUR, USD, and KRW, the adjacency matrix looks like

but in general there will be more zeros.

We can also form an initial FX Matrix

This FX Matrix can be thought of as the currency exchanges that can occur in a single transaction.

An interesting property of the adjacency matrix is that when you raise it to the nth power, the matrix entries represent the number of paths between any two objects in the quiver that require n steps, i.e.

where is the number of paths of length or the number of ways to convert EUR to USD in transactions.

To fill out FX Matrix, we incrementally take powers of and find entries whose value is 1. Since it is getting late and I’m running out of energy, I’ll just write the procedure as a simple pseudo Matlab code:

FXMatrix = Zeros(Size(A)); For n = 1:NumCurrencies FXMatrix(A^n == 1) = FXMatrix1^n(A^n == 1); end

Although the explanation may seem a bit arduous, the final procedure is quite simple and easy to program.

Can you find a better way?

As a side note, this provides an algorithm for generating a quiver from a directed graph, i.e. it gives an adjoint functor to the forgetful functor .