• bookloveru2

Corona and the stock market and the correlation coefficient between Corona and the stock market .

更新日:2021年1月2日

Hello, everyone.



This time we're going to see if there's a correlation between the dreaded new pneumonia corona and the stock market.


Verification.



Maybe it's a little inappropriate.


I also thought that, day after day, the corona cases and global stock prices


It continues to soar.



There must be something to it!


So we decided to check it out.




Note that the verification period is "January 11, 2020 - August 1, 2020".



The graph is drawn in python.


The code is shown at the end of the article.



Vertical axis: number of corona cases in each country (from WHO)


Horizontal axis: major stock indices for each country + Bitcoin (from yahooFinance)



Results: (1) Stock indices and the number of new corona cases seem to have no or slightly inverse correlation.


    The diagonal component (the diagonal axis from top left to bottom right is almost zero or slightly negative.


   (2) The highest relationship is between the number of people infected in Brazil and BTC (correlation 0.47).


    Why?




From the above, it can be said that there wasn't much of a relationship between the new pneumonia corona and the stock market.


It might be. (´Ohm...´Ohm...´Ohm...´Oh...labor.



In addition, this data's


The number of new corona infections is the number of new infections on a daily basis.


Stock prices for each country are plotted as a percentage of the cumulative product after standardization.




In your own environment, if you want to try it out.


 Download the raw data (csv) below to get a copy of your


 Save your GoogleDrive.




COVID19
.csv
Download CSV • 22KB

Then run the following python code



from google.colab import drive
drive.mount('/content/drive/')
 
! pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
 
# check auth
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.spatial.distance import cdist
plt.style.use('seaborn') 
font = {'family' : 'meiryo'}
plt.rc('font', **font)
 
data= pd.read_csv('drive/My Drive/COVID19.csv',index_col="Date")

# of new corona infections in WHO. The missing value for corona is set to zero zero. .fillna(0) 0 infected people.
covid19 = data.iloc[::,0:8].fillna(0)

#stock price. The stock price does not care about the missing value. Because it is actually a non-business day, the value does not change.
stock = data.iloc[::,9:17]

# Replaces missing values in stock by row-by-row mode.
stockmode = stock.fillna(stock.mode().iloc[0])

#covid19 and stockmode correlation coefficients in a heatmap.
#pd.DataFrame to numpy.ndarray.
ndf1=covid19.T.values
ndf2=stockmode.T.values
res=(1 - cdist(ndf1, ndf2, metric='correlation'))
DataFrame(res, index=covid19.columns, columns=stockmode.columns)
print(res.head())
sns.set_context("talk")
fig = plt.subplots(figsize=(10, 12))
sns.heatmap(res, annot=True,fmt='.2f',cmap='binary',square=True)



I used the following book as a reference for this code.






Please follow us on Twitter at https://twitter.com/bookloveru2


#math.


#Stats.


#Python




閲覧数:8回0件のコメント