DeFi Analysis COVID-19 amid turmoil and after plunge

Yuya Sugano
15 min readApr 23, 2020

This is one of two consecutive articles and the previous article covered the trace of analysis of Cointelegraph article the financial assets correlation with bitcoin amid COVID-19 crisis and looked through the anticipation for crypto currency trend. Please note that reading this article throughly needs a little technical knowledge about Anaconda3, python, Jupyter to visualize data with hands-on. You can skip the technical part and see the experiment result in the latter part. Jupyter Notebook is here.

Fig.1 lineplot of Dawjones vs Gold vs Crypto

Introduction

All asset classes in the financial market have been affected by the chaos of COVID-19 pandemic and confronting plunge and high level of volatilities. In stock exchanges and a various industries they would need to concern bail-outs or expect monetary stimulus by governments to avoid the worse situations however there is more optimistic view for crypto assets such as bitcoin and other crypto currencies that employ decentralization concept in protocol nature. Anthony “Pomp” Pompliano, co-founder and partner at Morgan Creek Digital posted his anticipation what will occur next 18 to 24 months in his article and he said bitcoin will outperform other asset classes even better than gold as inflation headge asset. What he emphasized in the article were 1) With quantitative easing people seek inflation hedge asset to battle with devaluation of cash and other assets, gold and bitcoin would benefit in that case, 2) Bitcoin reward halving is coming on May 13th, which will reduce the block reward from 12.5 BTC to 6.25 BTC. This could be technically quantitative tightening. [1]

I briefed the experiment result with the two major points in the previous article.

  1. Crypto currencies might outperform other financial assets because it reacts to the market faster than others and no worrisome points because neither bankruptcy nor default happens in decentralized nature
  2. Crypto currencies are less correlated with the traditional financial assets such as stock, real estate, gold so it would be adequate for hedge asset to adjust risk especially except bitcoin that was correlated to some extent

Even gold hasn’t been spared from the turmoil of current situation as this article explained. Additionally it says the correlations between gold and other financial assets have became correlated this time while usually gold shows negative correlations with other asset classes. It looks a little rough conclusion to me from the taken figure “Gold’s Rolling 7 days correlations with other financial assets” in the article. Bitcoin is showing quite high correlations with the traditional asset classes for example stock, real estate, Nikkei225 but Ether hasn’t shown that much. The result implies that other crypto currencies might be less correlated with the traditional financial assets or even negatively correlated, which is more beneficial for pursuing high risk-adjusted returns in portfolio or bet on it as inflation hedge asset when the governments start flooding fiats into the world. It’s out of the cage. [2]

According to fellow Venezuelan expatriate Mauricio Di Bartolomeo, co-founder of the crypto loan startup Ledn, Mexican and Argentinian users are driving growth on his platform with bitcoin savings accounts. Even including bitcoin-collateralized loans for dollars or stablecoins, Latin Americans now make up 60 percent of new Ledn user accounts in 2020

A question came to my mind when I saw those correlation figures and the turmoil via news, facebook and twitter. Lending, loans and other unbundled services in DeFi protocols those demand and supply could have soared instead of plunge because of shortage of running business costs and of individual livings to avoid unprecedented economic disruption more than the 2008 financial crisis. The governments and financial companies have been trying to give emergency supports like paying the wages of employees to cover wipe-out of throusands of jobs and waiving account fee or deferring payments on credit card. So DeFi market might have grown and more tokens and assets might have used in contrast to the current situation. Might not? It’s intriguing to look into. [3]

After the turmoil of COVID-19 there will be some bail-outs and government quantitative easing in a lot of countries. Both for daily use and investment use crypto currencies would take market dominance more than ever. We can confirm some ongoing occassions under the current circumstance that people started using bitcoin for daily use in a few south american countries. If you don’t dislike volatilities of current crypto currencies (if it’s tolerable for you) it’s quite usefull for payments, pay-check, and loans, any other case. Back to the topic in this article, I’d like to analyze correlations and some stats in figures between crypto currencies price and DeFi price (the locked value in smart contracts). Bitcoin which is called “digital gold” did not act like real gold in fact but other crypto currencies are maybe neutral, especially DeFi protocols might have had actual demands possibly in desperate situation for some people who could not get necessary helps before the support was due or not sufficient quantities under flow crunch.

https://twitter.com/Bitcoinbeach/status/1248394124664827904
  1. What is DeFi and TVL?
  2. Data Collection in AWS
  3. Experiment & Analysis

What is DeFi and TVL?

DeFi is the movement to create financial services on the decetralized technology for example on the blockchain to provide services without any interventions by central parties such as governments, companies but by smart contracts that are programmable codes on the blockchain that can execute automatically operations when certain conditions are met. With the emerge of Fintech companies a lot of financial services were decoupled and constructed again as unbundled service, now DeFi has been emerging with its distinct characteristics, transparent and auditability, high availability in network, neutrality for users in constrast to the conventional systems. Smart contracts do not need to couple with human validators, enforcers but execute operations by eliminating human interference and interventions under transparency and neutrality for those services. “A Beginner’s Guide to Decentralized Finance (DeFi)” is easy-to-read article for beginners. [4]

There are a various unique areas in DeFi, stablecoin and decentralized reserve bank (Maker), Lending and borrowing (Compound, dYdX), decentralized token exchange (Uniswap) and Synthetic assets (Synthetix), etc. As described in this guide the benefits of DeFi could be realized by not only less-developed countries and people who are in unstable economic environment but people those are in developed countries, especially when it comes to this current turmoil situation for obtaining loans, hedging fiat inflation, and new models of income generation with interests. DeFi services could be alternative liquidities and options, delivartives away from the traditional financial instruments to everyone in the globe without any instrumental entry points. I’d like to focus on decentralized reserve bank (Maker), lending & borrowing protocol (Compound, dYdX) plus synthetic assets (Synthetix) and decentralized exchange (Uniswap, Kyber) in this experiment. Because actual demands might have soared during the current severe situation for these services. [5]

As most of DeFi products are developed on Ethereum platform by leveraging ether as utility currency we can observe measure traction with how much values are locked in smart contracts of DeFi services — Total Value Locked (TVL) that is calculated by taking these balances and multiplying them by their price in USD or ether. DeFi Pulse seems the only site monitoring each protocol’s underlying smart contracts on the ethereum blockchain to calculate that traction and it supports API to retrieve data from the site. Let’s see that TVL peaked at $1.239B around Feb 15th and plunged below $500M in mid March like following sharp drops on other financial assets amid the market crisis. The plunge of DeFi TVL consists of all locked value in DeFi in underlying smart contracts which convert the accumulated value in USD unit. DeFi Pulse API needs an API key to get history data and rate data. You can create an account to get a key for the bigger rate limit or collect each protocol’s Total Value Locked by transferring data to AWS DynamoDB. [6]

The bottom line of tvl in DeFi around $500M

When people collaterize their ether in smart contracts of DeFi the TVLs becomes increasing and when the price of ether in USD drops down, the TVL also falls down. Viewing from this lens ether and DeFi protocol’s TVL values must show high correlations due to ether price plunge in this crisis because most of tokens and assets in DeFi protocols are ether-denominated (ether can be locked). We have to observe correlations between DeFi protocol’s TVLs and bitcoin, i.e. crypto currency and other financial assets. TVL the concept might be misleading. Here’s a good reference about how to interpret Total Value Locked (TVL) in more accurate way. [7]

Data Collection in AWS

If you use your API key to obtain historical data and rate data you can skip this part how to collect data from an API and store data in AWS Dynamo DB. This is just a test implementation for reference. You can sign up DeFi Pulse DATA to get an API key for use.

AWS Python SDK boto3 library can invoke DynamoDB operations for both local environment and Lambda. Here’s local pip environment information for my test.

$ pip install boto3
Successfully installed boto3-1.12.29 botocore-1.15.29 s3transfer-0.3.3
$ pip list
boto3 1.12.29
botocore 1.15.29
s3transfer 0.3.3

I ran some codes locally to create a DynamoDB table and extract collected data from the table to create a csv file. Please follow the instruction aws configure to set up your local environment. [8]

You can run this code to create a DynamoDB table with the DeFi protocol’s name as Partition Key and datetime as Sort Key.

Table attribute configuration

Once you created the table a setup of IAM, Lambda function and CloudWatch event is required. This package calls the Lambda function periodically (1 hour interval in this setting) and save hourly records in the DynamoDB table. This is just one table I used.

1. IAM: create an iam policy that has access on dynamodb and set it on a role

This example gives full access to DynamoDB as dynamodb:* so you may need to change it to more restrictive privilege as needed.

AWSLambdaBasicExecutionRoleWithDynamoDB

2. Lambda: Upload zipped lambda_function.py and set the prepared role

If the required libraries are not built-in in Lambda service we can include the library in the directory and zip them. On Lambda we can upload .zip file or download a file from S3 bucket where you saved the zipped folder with the libraries. Here’s an example how to include requests library.

$ cd lambda_function/
$ pip install requests -t ./
$ chmod -R 755 ./*
$ zip -r lambda_function.zip ./*

Create a lambda function from CLI or AWS console and set the prepared role on the created lambda function. Code sampe is here, a lambda function to call DeFi Pulse API and save data in DynamoDB.

lambda_function.py

3. CloudWatch: Configure CloudWatch Events and run it periodically

You can add a trigger event from CLI or AWS console how to invoke this lambda function. I configured CloudWatch Events with cron scheduler cron(0 * * * ? *) achieve periodic CloudWatch events per minute.

CloudWatch Events with the scheduler

The test code does return only the statusCode and the message “Calling API succeeded” but you can confirm the json was saved in DynamoDB table appropriately. If CloudWatch Events was configured properly, json data will be inserted every hour in the table.

A test call of the lambda function

Again you don’t need to build this system if you sign up DeFi Pulse DATA and obtain an API key to retrieve historical DeFi data (It was embarrassing that I realised this taking historical data was supported after I coded the lambda function). Here’s my repository for your reference.

Experiment & Analysis

It’s time to play with data. I used the libraries pandas and pandas-datareader to crawl & manipute data we used in the previous article. I have added DeFi data crawling part as below in the notebook. You may change the calling URL depending on what data you would like to retrieve from DeFi Pulse site. getDeFiData function can return both multiplied price in USD and ether-calculated price for Total Value Locked (TVL). Pull needed columns and manipulate data as needed on-demand.

Stats can be calculated with a single describe() function. Let’s look through stats a little and go to graphycal analysis. Please be careful bitcoin, ether and other financial assets are USD-base price while DeFi assets are TVL values in USD. Total Value Locked (TVL) does not mean any price of crypto currencies but how much currencies are locked in smart contracts by the designated currency for example in USD or in ether. One misleading concept in here is the difference between the locked value in ether and the TVL in ether. TVL in ether is ether base calculation for the total locked values in the protocol not purely locked ether amount in smart contracts in the protocol.

Stats of daily data the latest 3 months

The lineplot of given time-series data for bitcoin, ether, DawJones, gold, Maker TVL (USD) and Maker TVL (ether) was drawn in fig.1. All rows were divided by the first index value for each column so the starting points became zero now. mau is Maker TVL (USD) and mae is Maker TVL (ether) in the figure. 1.0 can be considered the anchoring point for different unit data between the currencies and TVLs. When ether marked 1.6 in Feb that meant ether price soared by 160% from the price of the reference point 1.0.

  1. Maker TVL (USD) followed the surge and plunge of ether until the bottom
  2. Maker TVL (ether) has been moving significantly different, it’s opposite

It looks like the collaterized ether in Maker has been decreasing in opposite directions when ether is on recovery trend after the plunge. This is an essential concern for people when ether price falls down in the market they must watch their over-collaterization status and stabilize its LTV (Loan-To-Value) appropriately for Maker CDP. Let’s delve into this further.

Fig.1 Lineplot of Dawjones vs Gold vs Crypto

Imagine you have collaterized ether that is equivalent to 150 USD in Maker CDP and loan 100 DAI that is soft-pegged to 100 USD. When ether price dip below the price of 150 USD, you need to pump more ether in your CDP or you have to withdraw DAI to keep your LTV (Loan-To-Value) not exceeding below 67% in this protocol. If you pulled 1 DAI from the destination in this case then 99 DAI is the amount you have to secure ether-denominated collateral that is equivalent to 148.5 USD (99 USD times 150%) now. So it’s now tolerable if the price of ether in USD falls a little (by 99%). In contract when the price of ether soars people can loan more DAI that is relevant to actual price of ether in USD calculation in Maker CDP or they might release ether out of their collaterizations to bear devaluation of USD values for DAI. Because people might prefer to ether more than holding DAI that is soft-pegged to USD when they anticipate that quantative easing floods USD into the economy and USD inflation can be predicted.

Let’s look through coefficient of variation between TVL calculated in USD and TVL calculated in ether for DeFi protocols only. The coefficient of variation is defined as the ratio of the standard deviation to the mean. It shows the extent of variability in relation to the mean. One significant difference here is dYdX that indicates high standard deviation in ether TVL, which might mean using ether in dYdX was brisk to some extent. In dYdX we can deposit ether, DAI or USDC and lend or borrow those currencies.

Fig.2 Comparison coefficient of variation between USD and ETH denominated assets

I took only ether-denominated price of TVLs in the following two figures. With the said reasons above ether-denominated TVLs can be negatively correlated with the ether price. The fig.3 shows the rolling 7 days change of DeFi and financial assets in percents. Ether and DeFi TVLs are seen opposite in phase at a glance.

Fig.3 Rolling 7-days change of DeFi and financial assets (%)

Lending & borrowing protocols (Compound, dYdX) have shown camel humps in fig.4 the rolling 7 days standard deviation but I’m not sure why this happened yet. It’s surprising that Maker sank below DawJones standard deviation during the crisis.

Fig4. Rolling 7-days standard deviation of DeFi and financial assets (%)

From the previous article, ether was neutrally correlated with bitcoin and other financial assets however the trend of ether looks the same to other assets. There were just some spikes and high volatilities that might have caused the correlation low-key compared to other financial assets. In this experiment the correlation pairplots for both in USD and ETH look interesting as following. In the USD figure two columns gld (Gold) and dyd (dydx) seem not so correlated with any other assets. Ether usually could drag ether-denominated TVLs back and forth in the trend so the correlation of dYdX with others looks unique and distinctive against the trend. Anyway I think these figures might be misleading and obfuscating for some degree.

Fig.5 Correlation of DeFi and the financial assets (Pearson correlation)

Next I collected locked tokens balance in DeFi protocols for ether and DAI. Fig.6 is the lineplot of DeFi protocols locked ether chart. The trend seen in green eMak is similar to mae in fig.1 because ether-dominance is high in Maker DAO. These values have been converged to the right end. The trend is neither upward nor downward. Ether liquidity moves around in some places.

Fig.6 Lineplot of DeFi protocols Maker, Compound, Dydx, Uniswap, Kyber for locked ETH

In fig.7 dYdX is astonishing and unique again. Why is stake so high? DAI stablecoin started flowing in exactly when we had seen “Black Thursday” on March 12th. But it does not provide any clues if there has been actual demands for borrowing and lending in the market for DAI. We’re seeing a dip and retreat at the right end. More interesting phenomenon can be seen in the next figure that draws high attention.

Fig.7 Lineplot of DeFi protocols Maker, Compound, Dydx, Uniswap, Kyber for locked DAI

Here’s the lineplot of Lending and Borrowing rates of Maker, Compound, and dYdX each. The percentages varied especially during the center yellow spikes of dYdX. The lending and borrowing rate might have been mechanically driven up by flash-loan type of thing to release collaterals in Maker by borrowing ether that can skirt over-collaterization for DAI then withdraw loans from CDP.

Fig.8 Lineplot of DeFi protocols Maker, Compound, Dydx lend and borrow rates (%)

As conclusion the most of moves, surge and plunge seem to have been caused by speculative acts in DeFi market and it’s not practical to trace how those borrowed crypto currencies were used now. The glimpse from this analysis was that ether price formation is different from bitcoin due to its unique ecosystem plus demand & supply of the DeFi protocols as lending and borrowing. That’s why ether price trend was neutrally correlated with other financial assets. At last ether price has recovered back faster than other financial assets more quicker than bitcoin since “Black Thursday”. [9]

--

--

Yuya Sugano

Cloud Architect and Blockchain Enthusiast, techflare.blog, Vinyl DJ, Backpacker. ブロックチェーン・クラウド(AWS/Azure)関連の記事をパブリッシュ。バックパッカーとしてユーラシア大陸を陸路横断するなど旅が趣味。