import tushare as ts
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.api as sm
pro = ts.pro_api()
#华通医药
df_HTYY = pro.daily(ts_code="002758.SZ",start_date="20190816",end_date="20190916")
df_HTYY_pct_change = df_HTYY['pct_chg'].values
#第一医药
df_DYYY = pro.daily(ts_code="600833.SH",start_date="20190816",end_date="20190916")
df_DYYY_pct_change = df_DYYY['pct_chg'].values
X_df_HTYY_pct_change = sm.add_constant(df_HTYY_pct_change)
results = sm.OLS(df_DYYY_pct_change,X_df_HTYY_pct_change).fit()
print(results.summary())
fitted_ys = results.fittedvalues
print(fitted_ys)
结果:
将结果可视化: