Phorgy Phynance

Archive for March 2010

Currency exchange rates, directed graphs, and quivers

with 4 comments

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

\text{FX Matrix} = \left[\begin{aligned} &\text{EUREUR\quad} &\text{EURUSD\quad} &\text{EURKRW\quad} \\ &\text{USDEUR\quad} &\text{USDUSD\quad} &\text{USDKRW\quad} \\ &\text{KRWEUR\quad} &\text{KRWUSD\quad} &\text{KRWKRW\quad}\end{aligned}\right]

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

\text{FX Vector} = \left[\begin{aligned} \text{EURUSD} \\ \text{USDKRW}\end{aligned}\right]

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

\text{EURKRW} = \text{EURUSD}\times\text{USDKRW},

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

\text{EURUSD}: \text{EUR}\to\text{USD}.

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

\text{EURKRW} = \text{USDKRW}\circ\text{EURUSD}.

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

A = \left[\begin{aligned}1\quad & 1\quad & 0\\1\quad & 1\quad & 1\\ 0\quad & 1\quad & 1\end{aligned}\right],

but in general there will be more zeros.

We can also form an initial FX Matrix

(\text{FX Matrix})_1 = \left[\begin{aligned} 1\quad &\text{EURUSD}\quad &0\quad \\ (\text{EURUSD})^{-1}\quad & 1\quad & \text{USDKRW}\quad \\ 0\quad & (\text{USDKRW})^{-1}\quad & 1\quad\end{aligned}\right]

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.

A^n = \left[\begin{aligned} \#(\text{EUREUR})_n\quad & \#(\text{EURUSD})_n\quad & \#(\text{EURKRW})_n \\ \#(\text{USDEUR})_n\quad &\#(\text{USDUSD})_n\quad & \#(\text{USDKRW})_n \\ \#(\text{KRWEUR})_n\quad & \#(\text{KRWUSD})_n\quad & \#(\text{KRWKRW})_n\end{aligned}\right]

where \#(\text{EURUSD})_n is the number of paths of length n or the number of ways to convert EUR to USD in n transactions.

To fill out FX Matrix, we incrementally take powers of A 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);

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 U:Cat\to Grph.


Written by Eric

March 1, 2010 at 1:30 am