[PYTHON] Which crypto assets can be earned efficiently

Introduction

Bitcoin of ** crypto assets (virtual currency) ** continues to update the highest price.

On December 16, 2020, Bitcoin topped $ 28,000. Now $ 30,000 is just around the corner.

One of the reasons for the soaring prices of crypto assets such as Bitcoin is that the US Federal Reserve Board (FRB) has lowered the policy interest rate to near zero, greatly weakening the US dollar.

Since there is an upper limit to the number of crypto assets such as Bitcoin issued, investors believe that the value will increase when the number of supplies reaches the upper limit.

In this article, we will calculate the expected value and variance of the return on investment (ROI) of each cryptocurrency asset and verify which cryptocurrency asset you should invest in to earn efficiently.

What is a crypto asset (virtual currency)?

It is defined in the "Act on Settlement of Funds" as having the following properties.

(1) It can be used for payments to unspecified persons and can be exchanged with legal tender (Japanese yen, US dollars, etc.). (2) Electronically recorded and transferable (3) Not legal tender or assets denominated in legal tender (prepaid cards, etc.)

It is said that there are more than 2,000 types of cryptocurrency assets in circulation around the world. Typical crypto assets include Bitcoin, Ethereum, and Bitcoin Cash.

The reasons why crypto assets are attracting attention are that "cryptographic assets have a common value in the world and can be used anywhere as they are" and "there is no need for exchange costs such as exchanging yen for dollars".

As the demand and use of crypto assets increases, the value of crypto assets will increase. When investing in cryptocurrencies, you can expect a rise and aim for a gain on price increase, or if price fluctuations are large, you can aim for a margin on short-term trading.

[Reference] What is a crypto asset (virtual currency)? | Bank of Japan Homepage About crypto assets | SBI VC Trade Homepage

Expected value and diversification of return on investment

--Return on investment

How efficiently did you make money? There is a return on investment (ROI) as an index to see. This return on investment is

\frac{Profit amount}{Investment amount}

You can find it with. The higher the number, the more efficiently you are earning for the investment amount.

For example, consider the examples of "using 100,000 yen to make 50,000 yen" and "using 500,000 yen to make 50,000 yen". First of all, the former earns the same profit with less money than the latter, so you can immediately see that the former earns more efficiently. The return on investment represents this efficiency, and when actually calculated, the former is 0.5 and the latter is 0.1. In this way, you can see how efficiently you made money by comparing the return on investment.

--Expected value and variance

For $ N $ return on investment data $ X = (X_1, X_2, ..., X_N) $, the average value (expected value) $ E [X] $ is

E[X]=\frac{1}{N}(X_1+X_2+\cdots+X_N)

It can be calculated with. This is just an average formula.

The variance $ V [X] $ is

V[X]=\frac{1}{N}\sum_{i=1}^N(X_i-E[X])^2

It can be calculated with. This is just a variance formula.

result of analysis

In a certain month, the return on investment of each crypto asset is calculated every day, and the expected value $ E $ and the variance $ V $ are calculated.

The following 22 types of crypto assets are verified this time.

"BTC-USD","XRP-USD","ETH-USD","LTC-USD","BCH-USD","BNB-USD",
"EOS-USD","USDT-USD","LINK-USD","TRX-USD","ADA-USD","XLM-USD",
"XMR-USD","DASH-USD","NEO-USD","ETC-USD","XEM-USD","ZEC-USD",
"QTUM-USD","BTG-USD","BAT-USD","DOGE-USD"

For example, "BTC-USD" means Bitcoin/US Dollar (BTC/USD) and "ETH-USD" means Ethereum/US Dollar (ETH/USD).

By comparing the expected value of the return on investment $ E $ of each crypto asset with the calculation result of the variance $ V $, we will consider which crypto asset can be earned efficiently.

The figure below shows the results for October 2020.

In October 2020, Bitcoin/US $ (BTC/USD) will have a higher return on investment than any other crypto asset and will have the lowest risk (diversification) of any other crypto asset that is profitable. It is. Therefore, the next month (November) investment in Bitcoin can be expected to generate the highest profit with a small risk.

Also, with the exception of Bitcoin/US dollar (BTC/USD), Bitcoin Cash/US dollar (BCH/USD) and Ethereum/US dollar (ETH/USD) are also more risky (diversified) than other crypto assets. , It can be said that it is a good investment target because it has a high investment return.

The following is the result of November 2020.

In November 2020, the expected return on investment of Ripple/US $ (XRP/USD) was the highest. This is because the price of Ripple has skyrocketed. We earn more than 5% per day.

On the other hand, in October 2020, Bitcoin/US $ (BTC/USD) seemed to be the most profitable, but Ripple/US $ (XRP/USD) was the best. However, although the risk of Bitcoin/US dollar (BTC/USD) has increased compared to the previous month, it is making almost the same profit as the previous month.

Bitcoin/US $ (BTC/USD) is less risky and profitable, but looking at the results in November, look at crypto assets that can be expected to be more profitable according to the risk you can take. I can.

There are four candidates: Ethereum/US dollar (ETH/USD), Quantum/US dollar (QTUM/USD), Ada/US dollar (ADA/USD), and Ripple/US dollar (XRP/USD). Which of these four you should invest in depends on the investor's own personality.

Ripple/USD (XRP/USD) is the best option if you are fairly risk tolerant and want to be highly profitable. Other than that, Ethereum/US $ (ETH/USD), Quantum/US $ (QTUM/USD), and Ada/US $ (ADA/USD) will be selected in order according to the risk that can be tolerated.

When considering the investment target based only on this result, cryptocurrency assets other than the above four will not be selected. This is because when comparing these four options with the other options, the four options this time are more profitable for risk. The point on the upper left is more profitable for risk than the point on the lower right.

Therefore, when considering investing in crypto assets other than Bitcoin, it can be said that one of these four options should be invested.

The following is the result of December 2020.

Expected return on investment in Bitcoin/US $ (BTC/USD) is higher than last month. In addition, the risk was about 20, which was almost the same as the previous month. It is a good investment destination because it has the lowest risk among the crypto assets this time and has earned some profit. Litecoin/US $ (LTC/USD) can also be an option if you want to take more risk and aim for higher profits.

In November, the expected rate of return on Ripple/US dollar (XRP/USD) was the highest, but in December, it became the investment target with the lowest rate of return. This is because the US Securities and Exchange Commission (SEC) has filed a lawsuit against Ripple Labs. XRP fell 37% on the 29th and fell 60% by a week later.

in conclusion

Bitcoin/USD (BTC/USD) was found to be the least risky (among crypto assets) and the highest expected return on investment in any of the October, November and December results.

Therefore, it can be said that if you invest in Bitcoin for the time being, you can earn a stable investment in cryptocurrency assets **.

In addition, Ethereum/US dollar (ETH/USD) and Litecoin/US dollar (LTC/USD) are also one of the investment options because they have low risk to some extent and high profits to some extent in any of the three periods. maybe.

Previously, I tried the same verification as this time with 225 Nikkei stocks. If you are interested, please also see "(Qiita) Verifying Investment Efficiency of All Nikkei 225 Stocks".

Appendix (analysis program)

--Collect time series data

By executing the following program, you can get the time series data of the price of crypto assets from January 1, 2015 to December 31, 2020.

Python's pandas_datareader library is used to get the data. You can use it to get data from Yahoo! Finance. Python's Pandas library is used to read and write CSV files.

After acquiring the data, the data will be saved in the CSV file format `` `ccurrency_close_all.csv```.

getStockPrice.py


import pandas as pd 
import pandas_datareader.data as web

#Cryptocurrency
def get_cc():
    CCURRENCY=["BTC-USD","XRP-USD","ETH-USD","LTC-USD","BCH-USD","BNB-USD",
               "EOS-USD","USDT-USD","LINK-USD","TRX-USD","ADA-USD",
               "XLM-USD","XMR-USD","DASH-USD","NEO-USD",
               "ETC-USD","XEM-USD","ZEC-USD","QTUM-USD",
               "BTG-USD","BAT-USD","DOGE-USD"]
    return CCURRENCY

#Stock price acquisition (daily) csv save Close only
def get_close_csv(stock_name: list,start=None,end=None,filename='noname'):
    for i in range(len(stock_name)):
        if(i==0):
            data = web.DataReader(stock_name[i],"yahoo",start,end).Close.rename(stock_name[i])
        else:
            data2 = web.DataReader(stock_name[i],"yahoo",start,end).Close.rename(stock_name[i])
            #data = pd.concat([data,data2], axis=1)
            data = pd.merge(data, data2, how='outer', on='Date')
        print(str(i+1)+"/"+str(len(stock_name)))
    data.to_csv(f"{filename}")

get_close_csv(get_cc(),start='2015-1-1', end='2020-12-31',filename='ccurrency_close_all.csv')

--Calculate the expected value and variance of the return on investment and create a scatter plot

The Pandas library used to read and write CSV files is used to calculate the expected value of return on investment and variance.

First, read the time series data `` `ccurrency_close_all.csv``` acquired by the above program. Next, calculate the return on investment, expected value, and variance of each crypto asset. Finally, the result is displayed on a scatter plot.

analysis.py


import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import itertools
import datetime

#Cryptocurrency
def get_cc():
    CCURRENCY=["BTC-USD","XRP-USD","ETH-USD","LTC-USD","BCH-USD","BNB-USD",
               "EOS-USD","USDT-USD","LINK-USD","TRX-USD","ADA-USD",
               "XLM-USD","XMR-USD","DASH-USD","NEO-USD",
               "ETC-USD","XEM-USD","ZEC-USD","QTUM-USD",
               "BTG-USD","BAT-USD","DOGE-USD"]
    return CCURRENCY

#Read stock price data of all stocks
df = pd.read_csv('ccurrency_close_all.csv', index_col=0)

# year
# s_time_list = [f'{y}-1-1' for y in range(2015,2021)]; e_time_list = [f'{y}-12-31' for y in range(2015,2021)]

# month
s_time_list = ['{0:02d}-{1:02d}-1'.format(y,m) for y, m in itertools.product(range(2015,2021), range(1,13))]
e_time_list = [(datetime.date(y,m,1)-datetime.timedelta(days=1)).strftime("%Y-%m-%d") for y, m in itertools.product(range(2015,2021), range(1,13))][1:]+['2020-12-31']

#Price earnings ratio
df_returns_all = (df-df.shift(1))/df.shift(1)*100

for ii in range(len(s_time_list)):
    s_time = s_time_list[ii]
    e_time = e_time_list[ii]
    df_returns = df_returns_all[s_time:e_time]
    #Standard deviation, variance
    df_std = pd.DataFrame(df_returns.var(), columns=['Variance'])
    df_mean = pd.DataFrame(df_returns.mean(), columns=['Anerage'])
    
    #Combine results
    df_result = pd.concat([df_std, df_mean], axis=1)
    
    #Create a list of stock names (for point labels)
    data_name = get_cc()
    
    #Point data
    average = np.array(list(df_result['Variance']))
    variance = np.array(list(df_result['Anerage']))
    
    # E-Create V diagram
    plt.figure(figsize=(9,9))
    plt.xlabel('Variance', fontsize=18)
    plt.ylabel('Average', fontsize=18)
    plot_list=get_cc()
    for (i,j,k) in zip(average, variance, data_name):
        if k in plot_list:
            plt.plot(i,j,'o')
            plt.annotate(k, xy=(i, j),fontname="MS Gothic", fontsize=18)
            
    plt.title('{} ~ {}'.format(s_time, e_time), fontsize=25)
    plt.tick_params(labelsize=18)
    plt.savefig(f'./month/cc{ii}m.png')
    # plt.close()

Recommended Posts

Which crypto assets can be earned efficiently