Framework for developing optimal cross-chain capital allocation strategies

Instrumental Finance
13 min readMar 18, 2022

--

Written by Juan P. Madrigal-Cianci, Jesper Kristensen, and 0xmoonscraper

Advanced Blockchain Research & Instrumental Finance

SB-MATH-CSQI, École Polytechnique Fédérale de Lausanne, Switzerland Instrumental Finance.

March 14, 2022

Introduction

We build a framework for developing cross-chain yield-optimizing strategies. The cross-chain aspect will be implicitly modeled via a cost-function introduced to handle the cost of changing pools (bridging when relevant, specifically). This framework is being used at Instrumental Finance to develop and deploy alpha strategies. While we focus on the framework and introduce a few simple capital allocation strategies here, we will present more complex allocation methods in follow-up articles.

We consider the problem of the dynamic equity allocation across several cross-chain yield-producing pools. More precisely, given initial equity x0 ∈R+ and a set of P ∈ Nyield-generating pools, we investigate the problem of obtaining the optimal allocation of capital across pools and times. Said differently, we aim to obtain a set of strategies for transferring money between pools that would maximize the total profit, measured as total yield gains minus transaction costs. In this work we:

1. Formulate the problem of optimal capital allocation across yield-generating pools in a mathematically sound way.

2. Propose and investigate the performance of some strategies on real-world data.

3. Use machine learning techniques (Gaussian processes) to simulate a probabilistic environment mimicking the (unknown) process that generates the yields at each time-step and use this to construct a Monte Carlo simulation to test the robustness of the presented strategies under different scenarios.

Set up

We begin with a mathematical setup of the problem at hand. Let x0 ∈ R+ denote an initial amount of equity (in, e.g., USD) and suppose we have a set of N ∈Nrecorded times {tn}Nn=1, tn ∈R+, n = 1,…,N, and P ∈Npools, where for each pool p, we have N datapoints {ynp }Nn=1, ynp ∈R+ representing the yield (in percentage) of pool p, p = {1,2,…,P}, at time tn, n = 1,…,N. Notice that, clearly, allocating the initial amount of equity x0 across yield-generating pools over time, induces the equity at time tn, denoted by xn n = 1,…,N. In general, one can split their total equity xn at time tn across all P pools; this in turn motivates the definition of the weight vector at time tn, w = (wn1 ,…,wnP ), with wnp ∈ [0,1] and ∑Pp=1 wnp = 1, for n = 1,…,N and p = 1,…,P, as the proportion of the equity allocated to each pool. Thus, one clearly has that xn := ∑Pp=1 xnp, with xnp := wnp xn the amount of equity at time tn allocated to pool p.

Clearly, an active portfolio management should move amounts of equity across pools at different times. Denote by ∆wnp := wnp −wn−1p the change of weights allocated to pool p between times tn−1 and tn, with the convention that w0p = 0, and furthermore define the vector ∆wn := (∆wn1,…,∆wnP ), ∆wn ∈ RP+. Typically, there is a fee f ∈ R+ (perhaps as a percentage of the equity amount being moved) associated with each transaction. This can capture bridge fees as well when capital is transferred cross-chain and cross-layer. This means then that the operation of changing the weights across pools (i.e., moving money in an out) at time tn has a transaction cost Cn ∈ R+ of Cn := f ∑Pp=1 |∆wnp |xn. Thus, at each step n, we have that the total equity at time tn+1 is given by

with yn = (yn1 ,…,ynP ) and 1p ∈ RP the vector with all entries equal to one. Lastly, given a sequence of yields across all pools until time N denoted by {yn}Nn=1, we define a strategy S as a collection of weights S = {w1,…,wN }, and denote by S the space of all admissible strategies. We remark that, in general, the weights at time step n, will depend on the weights (and yield) at the previous times, i.e., Sn = Sn(w1,…,wn−1). The problem of portfolio optimization in this case can be understood as finding the strategy S∗ ∈ S that maximizes the equity up until time tN , i.e, S∗ = arg maxS∈SxN (S).

We aim at defining and exploring several strategies for the maximization of xN. Notice that these strategies can also be understood as a collection of instructions about when and how we should allocate money at a given time tn.

Strategies

We now present some strategies for capital allocation. We remark that, in the current work, we will only consider a handful of strategies and aim to expand this list of techniques in future work. We begin by defining a benchmark strategy against all other strategies that will be compared.

Benchmark strategy

We begin by defining an (unachievable) optimal strategy. Suppose, for the sake of the argument, that there are no transaction costs across all pools and for all times. Suppose, furthermore, that the set of time-dependent yields {ynp } are known a priori across all pools p = 1,2,…,P and for all times n = 0,1,…,N. Given this information, it follows that the optimal strategy consists of moving the totality of capital xn to the pool p that would provide the highest yield at time tn. In the notation of Section 2, denoting by ̄yn = max{yn1 ,…,ynP } the maximum yield across all pools at time tn, the benchmark strategy S∗ is given by

with w∗,n ∈ Rp+ having components w∗,np = δ ̄yn(ynp ), where δ·(·) is the Dirac delta; this means that w∗,np = 1 if the pth pool is the one generating the highest yield, and w∗,np = 0 otherwise. Clearly, since

(i) there are no transaction fees and

(ii) we are always in the pool generating the highest yield, there is no other strategy that could generate a larger return. Such a strategy is purely theoretical since in general, there is a fee associated with moving funds between pools, and the information about the yield yn is only available (at least) after tn+1. However, such a strategy could be well approximated if one were trading on a market for which the transaction costs are much smaller than the returns if one were able to predict yn based on the previous values {y1,…,yn}.

Fixed strategy

We now present the simplest possible strategy. In this case, one picks a pool p among all possible P choices and keeps the totality of the initial equity locked in that pool indefinitely. Clearly, since there are no transactions associated with this strategy, it will always generate positive revenue. This is a good strategy in the case where one of the pools consistently outperforms the others. However, from a practical point of view, finding such a pool becomes increasingly difficult to find as both N and P grow. In the notation of Section 2, once a pool p has been chosen, this strategy can be (trivially) written as

where each component p′ of wf,n ∈ RP is given by wf,n p′= δp(p′) for all n = 1,2,…,N. Notice that such a strategy can be easily extended to the case where a fixed proportion of x0 is allocated across various (or all) pools and kept there indefinitely.

Lag-K greedy strategy

An additional strategy is chase the pool with the highest possible yield. Typically, however, information regarding the yield across all pools is available with a delay of K hours. This strategy begins by keeping the initial allocation of capital fixed for the first K hours. Once a sufficiently long time has passed, the algorithm moves to the pool that gave the largest yield at time tn−K . This strategy is presented in Algorithm 1. Notice that since this strategy generates a transaction whenever there’s a change on the highest-yielding pool, this strategy will lead to losses for sufficiently large transaction fee f.

This strategy can also be easily modified to limit the number of jumps in a given time span.

Lag-K risk-averse

We consider a risk-averse variation of the strategy presented above. In this setting, instead of automatically jumping chains whenever there is a change in the highest-yielding pool, a jump is 1only performed if xn−1 −x0 > xn−1f, i.e., if the realized gains up until step n−1 are large enough to cover the transaction fees.

Data acquisition and analysis

Before describing the strategies that we will consider in this article, we briefly describe our data acquisition process and analyze the collected data. We used Dune Analytics to obtain data representing the Hourly Percentage Yield (HPY) of Trycripto2 in the Polygon and Ethereum mainnet pools, on the Curve protocol. The HPY can be understood as the percentage gain that a liquidity provider would make by staking their money in a pool. As an example, if a given pool p has an HPY of y0 = 0.1% between times t0 = 0 and t1 = 1 (in hours), that means that, in that hour, a liquidity provider would have increased their initial equity from x0 to x1 = x0 (1 + y/100)= x0(1.001), by just leaving their equity in that pool. In particular, our data comprised 4,138 data points of the HPY obtained between 21.08.2022 and 18.02.2022.

We present an exploratory data analysis of our collected data is presented in Table 1 as well as in Figures 1, 2, and 3.

In Table 1, we show, for both the Ethereum and Polygon pools, the (empirical) average HPY, denoted by ˆY , its standard deviation, denoted by ˆσ as well its minimum and maximum value over all collected data points. We can obtain two important pieces of information from this table; the first one is that, on average, the yield of the Polygon pool is larger than that of the Ethereum pool; however, its standard deviation is also larger. Loosely speaking, this means that there are larger jumps in HPY in the Polygon pool and that, on average, it is around twice as profitable for a liquidity provider to keep all their money in the Polygon pool rather than on the Ethereum one. These results can be further verified in Figures 1 and 2. In Figure 1 (left), we plot the traces of HPY of both pools for the last 2000 data points.

It is clear from this picture that the yields of the Polygon pool tend to outperform those of the Ethereum pool most of the time. This can also be seen in Figure 1 (right), where a larger proportion of the samples are above the yPoly = yEth line, where we have used yPoly,yEth ∈R+ to denote the HPY of the Polygon and Ethereum pools, respectively.

Furthermore, such a figure reveals a noticeable positive correlation between the HPY on both pools. This is interesting from a modeling perspective as it suggests that yPoly, yEth are not independent of each other. Notice furthermore that the histograms of the HPY’s of both pools concentrate most of their mass around the interval [0,0.02]; however, while the Ethereum pool has a larger concentration of HPY towards the lower end of the interval, it can be seen that the Polygon pool has some mass allocated to values of HPY larger than 0.02. This is in agreement with the results obtained in Table 1.

Lastly, we investigate whether the (unknown) random process generating the HPYs has any hidden structure behind it. We will use the lag-K autocorrelation function of our data to that end. Recall that, given N,K ∈Nwith N ≥K, and a sequence of data points {ynp }Nn=1, the lag-K Autocorrelation Function (ACF)

Figure 1: (Left). Traces of Ethereum (red) and Polygon (blue) for the last 2,000 datapoints. (Right). Yield of Polygon vs. Yield of Ethereum, in log-log scale. Blue line represents the curve yPol = yEth, also in log-log scale.

The ACF can be understood to measure the linear relationship between an observation at time N and the observations at previous times. yNp with all the previous observations up until that point, i.e., {y0p,y1p,…,yN−1p }. Define K∗ = min{K ≤ N : ρ(·,K) = 0}. Loosely speaking, two samples of the underlying process become (essentially) statistically dependent on each other after K∗ steps of the process. Using this, we plot the lag-K Autocorrelation Function (ACF) for the HPY’s in Figure 3, with K = 168 (i.e., the number of hours in one week). As can be seen from both plots, the ACF for both HPY decays rather slowly; this suggests a strong temporal correlation between the intra-pool yields. This is important from a modeling perspective, as it evidences that the obtained {ynp }Nn=1 are not independent of each other, and suggest that there might be some hidden structure behind the process generating the yields ynp , which could be potentially inferred or learned (more about this in the conclusions) and subsequently exploited in the creation of strategies.

Numerical experiments

We implement the described strategies in different scenarios. Denote by {x∗,n}Nn=0 the equity generated by the optimal benchmark strategy, and by {xn(S)}Nn=0 the total equity generated by strategy S at times tn, n = 0,1,…,N. In addition to evaluating the performance of a given strategy in terms of its annualized

returns, we also define the following metrics of efficiency:

Deterministic case

We simulate our described strategies in the dataset described in Section 4. In particular, we implement the following strategies: Fixed Ethereum, fixed Polygon, greedy lag 1h, greedy lag 24h, greedy lag 24h limited to one swap a week, greedy lag 24h limited to one swap a day called risk-averse 24h, and risk-averse 1h limited to one swap per day. We implement our results assuming a fee of f = 0.5% of the transaction amount. We present our results in Table 2 and Figure 4. As we can see, all the greedy approaches return losses for the chosen transaction fee. This is understandable since, in this setting, the fees are relatively too large. Notice that the drawdown associated with those methods (c.f.Figure 4) is also significantly larger than the others. Thus, the greedy approach is not the right choice if the fees are too large. One could use simple optimization and root finding routines ( see, e.g., the Python package scipy.optimize) to show that the maximum fee possible so that the greedy approach would not incur any losses is given by f = 2.05 ×10−5 –which is extremely small for practical applications. It seems that the best strategies are either the risk-averse one or staying fixed at a given pool. As the number of pools increases, the probability of randomly choosing the highest yielding one decreases; we believe that the risk-averse approach is the most robust one.

Figure 4: From left to right: equity, fees, D and ̃D for different strategies. From top to bottom: Fixed Ethereum, Fixed Polygon, Greedy lag 24h, Greedy lag 24h, limited to one swap a week,

Probabilistic modeling and uncertainty quantification

To investigate the robustness of the strategies, we investigate the uncertainty associated with them. To that end, we model the time-dependent yield of pool

p as

with μp(t) an exponential weighted moving average of the true yield at pool p, γp is the standard deviation of the yields at pool p, and Wt is a standard Wiener process. Notice that this can be thought of as a rather simple Gaussian process with a covariance matrix given by Cov(t,s) = min(t,s). A plot of a realization of the process in (1), together with the real data used to generate it, is shown in Figure 5.

There, it is shown that the process described in (1) can accurately mimic the behavior of the random process generating the yields at each time. Once such a model has been constructed, we can generate random paths from Equation (1) and use them in a Monte Carlo approach to quantify the uncertainty associated with our strategies. We investigate the behaviors of our algorithm concerning their provided APY and drawdowns, as discussed at the beginning of Section 5. We present our results in Table 3. From there, we can see that the best strategies are to either stay fixed at a given pool or to use the risk-averse strategy.

Conclusions and future work

To summarise, in this work, we have investigated the problem of optimal cross-chain pool allocation. We have formulated the problem in a mathematically

sound way, made some interesting empirical observations on the data, proposed and tested different metrics, studied their robustness using Monte Carlo methods. We can draw a handful of conclusions from this. First, we remark that the formulation of our problem (given in terms of a sequence of weights) could be alternatively presented in terms of “policies” and “actions”; thus, we believe that the formulation of our problem is equivalent to that of a Markov Decision Process (MDP). One could then exploit several developments in Reinforcement Learning (RL) to tackle the optimal allocation problem. We intend to explore this approach in future work.

Second, our exploratory data analysis suggests that the (seemingly random) yield data appears to have a hidden structure underneath it instead of being purely random. This can be evidenced from both the ACF (Figure 3) and joint plots (Figure 1, right). In future work, we aim to exploit this hidden structure using, e.g., Long, Short Time Memory (LSTM) models — a powerful machine learning technique for modeling and forecasting time series. Third, we presented and tested a handful of admittedly simple strategies focusing for now on the framework. In future work, as mentioned, we aim at delivering more of them with higher complexities borrowing techniques from the artificial intelligence community. Furthermore, we introduced a simple probabilistic model to test out several strategies. Naturally, quantifying the uncertainty in a strategy is quite important, as by doing this, one can effectively estimate its risks/benefits.

For all things Instrumental, follow our socials:

Medium | Twitter | Discord | Telegram

--

--

Instrumental Finance

Cross-chain, cross-layer yield optimiser. Tapping into several chains to provide the maximised yield for our users.