-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0417_2.py
More file actions
25 lines (22 loc) · 717 Bytes
/
0417_2.py
File metadata and controls
25 lines (22 loc) · 717 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
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
tlt = pdr.get_data_yahoo('TLT','2002-07-30')
kospi = pdr.get_data_yahoo('^KS11','2002-07-30')
df = pd.DataFrame({'X':tlt.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}'
print(regr)
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('TLT')
plt.ylabel('KOSPI')
plt.show()