Python 为什么不';桌子上的数字不是变了吗?
Python 为什么不';桌子上的数字不是变了吗?,python,matplotlib,Python,Matplotlib,导入matplotlib.pyplot作为plt 将statsmodels.api作为sm导入 将statsmodels.formula.api作为sm1导入 开始=0 结束=60 timeseries={“期间”:[], “A”:[…], “B”:[…], “C”:[…], “R2”:[]} 当结束时 import matplotlib.pyplot as plt import statsmodels.api as sm import statsmodels.formula.api as sm
导入matplotlib.pyplot作为plt
将statsmodels.api作为sm导入
将statsmodels.formula.api作为sm1导入
开始=0
结束=60
timeseries={“期间”:[],
“A”:[…],
“B”:[…],
“C”:[…],
“R2”:[]}
当结束时
import matplotlib.pyplot as plt
import statsmodels.api as sm
import statsmodels.formula.api as sm1
start = 0
end = 60
timeseries = {"period":[],
"A": [],
"B":[],
"C":[],
"R2":[]}
while end <= len(d):
df = d.iloc[start:end]
period = str(df.index[0].to_timestamp().to_period('M')) + " to " + str(df.index[-1].to_timestamp().to_period('M'))
model= sm1.ols(formula = 'Q("KS11") ~ Q("000001.SS") +Q("GSPC") ',data= d).fit()
model_result = model.summary()
x = df['000001.SS','GSPC']
y = df['KS11']
x = sm.add_constant(x)
model = sm.OLS(y,x).fit()
model_result = model.summary()
timeseries["period"].append(period)
timeseries["R2"].append(model.rsquared)
results_as_html = model_result.tables[1].as_html()
timeseries["A"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][0])
timeseries["B"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][1])
timeseries["C"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][2])
start+=1
end+=1
timeseries_result = pd.DataFrame.from_dict(timeseries)
start = 0
end = 120
timeseries = {"period":[],
"alpha": [],
"beta":[],
"r_sqrd":[]}
while end <= len(monthly_asset_rre_df):
df = monthly_asset_rre_df.iloc[start:end]
period = str(df.index[0].to_timestamp().to_period('M')) + " to " + str(df.index[-1].to_timestamp().to_period('M'))
x = df['F']
y = df['M']
x = sm.add_constant(x) #adds a constant term to the linear equation it is fitting
model = sm.OLS(y,x).fit()
model_result = model.summary()
timeseries["period"].append(period)
timeseries["r_sqrd"].append(model.rsquared)
results_as_html = model_result.tables[1].as_html()
timeseries["alpha"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][0]) #intercept
timeseries["beta"].append(pd.read_html(results_as_html, header=0, index_col=0)[0]["coef"][1]) #coef
start+=1 #start = start + 1
end+=1 #end = end + 1
timeseries_result = pd.DataFrame.from_dict(timeseries)