-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0417_1.py
More file actions
27 lines (21 loc) · 751 Bytes
/
0417_1.py
File metadata and controls
27 lines (21 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
from pandas_datareader import data as pdr
import yfinance as yf
yf.pdr_override()
from scipy import stats
import matplotlib.pyplot as plt
dow = pdr.get_data_yahoo('^DJI', '2000-01-04')
kospi = pdr.get_data_yahoo('^KS11', '2000-01-04')
df = pd.DataFrame({'X':dow['Close'],'Y':kospi['Close']})
df = df.fillna(method = 'bfill')
df = df.fillna(method = 'ffill')
regr = stats.linregress(df.X,df.Y)
regr_line = f'Y = {regr.slope:.2f}*X + {regr.intercept:.2f}'
plt.figure(figsize=(7,7))
plt.plot(df.X, df.Y, '.')
plt.plot(df.X, regr.slope*df.X + regr.intercept, 'r')
plt.legend(['DOW x KOSPI', regr_line])
plt.title(f'DOW x KOSPI (R = {regr.rvalue:.2f})')
plt.xlabel('Dow Jones Industrial Average')
plt.ylabel('KOSPI')
plt.show()