In this post I measure the correlations between Thorchain’s three tokens: Rune, XRune and Thor. I then build a model that predicts the price of each token based on the price of another token.

Gathering the data

To obtain pricing data on the tokens, I queried Thorchain’s blockchain using Flipside Crypto.

The following function is used to pull my query results from Flipside:

PullVelocityData <- function(endpoint.url){
  raw.results <- readLines(endpoint.url)
  to.return <- data.table(jsonlite::fromJSON(raw.results))
  setnames(to.return, tolower(names(to.return)))
  return(to.return)
}
thor.data <- PullVelocityData("https://api.flipsidecrypto.com/api/v2/queries/d90bb9ae-f67c-4543-be25-2e1a0a45ed4e/data/latest")

This dataset includes the hourly prices of each of the three tokens. Note that this pricing data starts on November 03, 2021 at 14:00 UTC. That is when the Thor token launched. All prices are in USD.

head(thor.data, 3)
##                   hours rune_price thor_price xrune_price
## 1: 2021-12-11T23:00:00Z   6.379779   1.096275   0.2362494
## 2: 2021-12-11T22:00:00Z   6.365454   1.093810   0.2357110
## 3: 2021-12-11T21:00:00Z   6.320693   1.084577   0.2340391

There is a noteworthy aspect to this dataset. Thor began trading above 6$ in early November and fell below 3$ two days later . This sudden and sharp decrease in the value of Thor will affect our correlation coefficients.

We have more historical pricing data on Xrune and Rune. That is because these two tokens have been around for longer than Thor. We import another dataset of the hourly prices of Rune and XRune this time going back to August 01 2021.

xrune.data <- PullVelocityData("https://api.flipsidecrypto.com/api/v2/queries/d90bb9ae-f67c-4543-be25-2e1a0a45ed4e/data/latest")

Correlations Between the Tokens

R language is a great tool to perform statistical analysis. It includes boilerplate functions to calculate correlations.

My previous post on Aave 29 provides a good definition of correlation:

Correlation is the tendency for the values of two or more variables to vary together in a related way. It can be seen as a pattern in a scatter plot graph. Correlation coefficients are standardized. Values can range from -1 to 1 where a negative value means that the two variables move in opposite directions. A value of 1 indicates a perfectly linear relationship.

Below are three scatter plots of the historical pricing data. Each point on the plots represent an observation at a specific time. The R value is the correlation coefficient between the two tokens represented on the plot.

b3 <- ggplot(thor.data, aes(x = rune_price, y = thor_price))
d3 <- ggplot(xrune.data, aes(x = rune_price, y = xrune_price))
c3 <- ggplot(thor.data, aes(x = xrune_price, y = thor_price))
plot_grid(b3 + geom_point(color = "red")+ labs(
    subtitle = "November 03 to December 11, 2021") + 
stat_cor(method = "pearson", labels = "AUTO"), 
  d3 + geom_point(colour = "dark green")+ labs(
    subtitle = "August 01 to December 11, 2021")+
stat_cor(method = "pearson", 
), labels = "AUTO")

c3 + geom_point(color = "blue")+ labs(
    subtitle = "November 03 to December 11, 2021") +
stat_cor(method = "pearson", labels = "AUTO")

There is a strong association (R = 0.82) between the price of Rune and the Price of Thor. There is a moderate association (R = 0.7) between the price of Rune and the price of XRune. Finally, there is a weak association (R = 0.37) between the price of XRune and the price of Thor. All results are statistically significant with p-values under 0.01.

Just for fun we can visualize the prices of all three tokens in a single scatter plot. The particularity of this plot is that the price of Thor is represented by a color gradient.

ggplot(thor.data, aes(x = rune_price, y = xrune_price)) + 
    geom_point(aes(color = thor_price)) + labs(
    subtitle = "November 03 to December 11, 2021")

    theme(legend.position = "top")
## List of 1
##  $ legend.position: chr "top"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi FALSE
##  - attr(*, "validate")= logi TRUE

We observe on the y-axis that as the price of Rune increases the price of Thor also increases. On the x-axis the association is not so strong. The price of XRune and Thor do not move in sync in the same manner. This is consistent with the correlation values identified above (0.82 for Thor and Rune vs only 0.37 for Thor and Xrune).

Calculating correlations is a good way to understand our data. When we find a strong correlation between variables, is there something useful that we can do with that information?

Part 2: Predicting Prices

We have already established that there is a strong correlation between some of the tokens (mainly Rune and Thor). If we knew the price of one of these tokens, could we not predict the price of the other?

Let’s use our pricing data to build predictive models. These models will use a simple technique called a linear regression.

A linear regression finds the best fitting straight line through a set of data.

For example:

reg0 <- lm(xrune_price~rune_price,data=thor.data) 

    with(thor.data,plot(rune_price, xrune_price))
    abline(reg0)

When correlations are strong, a linear regression can predict one variable based on the other correlated variable.

I build a regression model for each pair of tokens in the dataset.

reg3 <- lm(thor_price~rune_price,data=thor.data) 
    coef(reg3)
## (Intercept)  rune_price 
##  -1.5897387   0.3474548

For every one dollar increase in the price of Rune, the model predicts an increase of $0.347 in the price of Thor.

reg2 <- lm(xrune_price~rune_price,data=xrune.data) 
    coef(reg2)
## (Intercept)  rune_price 
##   0.1880197   0.0150552

For every one dollar increase in the price of Rune, the model predicts an increase of $0.015 in the price of XRune.

reg1 <- lm(xrune_price~thor_price,data=thor.data) 
    coef(reg1)
## (Intercept)  thor_price 
##  0.30351646  0.01876361

For every one dollar increase in the price of Thor, the linear model predicts an increase of $0.018 in the price of Xrune.

Using the models to make predictions.

Let’s use the regression models to make price predictions.

When the price of Rune reaches 20$, what will be the expected price of XRune?

newdata = data.frame(rune_price=20)
predict(reg2, newdata, interval="confidence")
##         fit       lwr      upr
## 1 0.4891236 0.4780162 0.500231

Answer: When the price of Rune is $20, the price of XRune will be between $0.4780 and $0.5002 at a 95% confidence interval.

When the price of Rune is $20, what will be the expected price of Thor?

newdata2 = data.frame(rune_price=20)
predict(reg3, newdata2, interval="confidence")
##        fit      lwr     upr
## 1 5.359356 5.182663 5.53605

Answer: When the price of Rune is $20, the price of Thor will be between $5.18 and $5.53 at a 95% confidence interval.

Takeaways

There is: - a strong association between the price of Thor and the price of Rune (R = 0.82); - a moderate association between the price of Rune and the price of XRune (R = 0.7); and - a weak association between the price of XRune and the price of Thor (R = 0.37).

All results are satistically significant.

For every 1$ increase in the price of Rune: - the price of XRune is expected to increase by $0.015; and - the price of Thor is expected to increase by $0.347.

Discussion

What can we do with this information?

If an investor has Rune tokens that are just sitting their wallet, they might as well invest them in the Rune-Thor liquidity pool. We have established that these tokens have a strong correlation. This means that impermanent loss is unlikely in the Rune-Thor pool because the two assets move in sync.

The Thor-Rune pool offers 45% APY on two assets that have a correlation of 0.82.

Limitations

The drastic fall in the value of Thor during the first few days of it’s existence strongly affect our data. It would be worthwhile to redo this exercise in a month and exclude the first few weeks of Thor trading data.

Zook#2707

@streamust

December 12, 2021

link to queries on Flipside Crypto