FX Modeling with Matrix Product States

Generative Modeling of Foreign Exchange Rates with Matrix Product States

In the following project I am applying the Matrix Product State (MPS) training method from the paper Unsupervised Generative Modeling Using Matrix Product States [1] to a financial dataset that consists of foreign exchange rates (FX). The code can be found in my quantum-research github repository.

Data Preprocessing

The dataset consists of four FX pairs: EURUSD, GBPUSD, USDCAD, USDJPY. In recent literature about generative modeling in finance, this dataset is a popular choice. [2] For each of the four currencies we observe the daily mid price PiP_i.

Currencies

For preprocessing our dataset we first compute the log returns.

Li=log(Pi+1PiPi+1)L_i = log(\frac{P_{i+1}-P_i}{P_i}+1)

The we substract the mean and divide by the standard deviation.

Si=LiμLσLS_i = \frac{L_i - \mu_L}{\sigma_L}

The resulting series can be seen in belows plot.

Log Returns

Following histograms represent the marginal distributions of the target distribution that is objective to be learnt.

Log Return Histograms

Since the Matrix Product State model only takes binary values we need to binarize our features. For that purpose the algorithm from [2] is used.

To transform from real to binary we use

xint=(2N1)xxminxmaxxminxbinx_{int} = \lfloor (2^N - 1) \frac{x-x_{min}}{x_{max}-x_{min}} \rfloor \leftrightarrow x_{bin}

To transform from binary to real we use

xreal=xmin+(xintxmaxxmin2N1)x_{real}=x_{min} + (x_{int} \frac{x_{max}-x_{min}}{2^N - 1})

The binarized features represent the actual distribution that we are going to model. Ideally we could use a sufficient amount of bits per feature such that the target distributions could be rather closely recovered. In this experiment we limit ourselves to using f bits per feature to let the mps training finish in reasonable time, although it is possible to scale up using more compute resources.

Binary Histograms

MPS Training

During training the bond dimensions are adjusted from all 2 to [ 2 4 8 15 21 33 46 71 74 43 23 12 8 4 2 1].

The NLL Loss decreases notably within the first five iterations and changes minimal in all subsequent iterations.

Loss

Results

For assessing how close the target distribution was actually modeled, we generate 100000 samples from the trained MPS with adjusted bond dimensions and compare them visually to the target marginal distributions.

EURUSD Results GBPUSD Results USDCAD Results USDJPY Results

References

[1] Zhao-Yu Han, et al., Unsupervised Generative Modeling Using Matrix Product States, Phys. Rev. X 8, 031012, (17 July 2018). https://doi.org/10.1103/PhysRevX.8.031012
[2] Kondratyev, Oleksiy and Schwarz, Christian, The Market Generator (May 8, 2019). http://dx.doi.org/10.2139/ssrn.3384948