2.6.5 散点图与回归直线
读入IBM和S&P的月度收益率数据,从1926-01到2011-09,
并转换为xts格式,时间下标改为yearmon格式:
d
"m-ibmsp-2611.txt",
col_types=cols(.default=col_double(),
date=col_date(format="%Y%m%d")))
ibmsp
indexClass(ibmsp)
## Warning: indexClass
## 请用'tclass
## 见help("Deprecated")和help("xts-deprecated")。
head(ibmsp)
## ibm sp
## 1月 1926 -0.010381 0.022472
## 2月 1926 -0.024476 -0.043956
## 3月 1926 -0.115591 -0.059113
## 4月 1926 0.089783 0.022688
## 5月 1926 0.036932 0.007679
## 6月 1926 0.068493 0.043184
序列图:
chartSeries(
ibmsp[,"ibm"], type="lines",
theme="white", name="IBM returns",
major.ticks="years", minor.ticsk=FALSE)
## Warning: indexClass
## 请用'tclass
## 见help("Deprecated")和help("xts-deprecated")。
chartSeries(
ibmsp[,"sp"], type="lines",
theme="white", name="S&P returns",
major.ticks="years", minor.ticsk=FALSE)
## Warning: indexClass
## 请用'tclass
## 见help("Deprecated")和help("xts-deprecated")。
IBM收益率对标准普尔指数收益率的散点图:
d
plot(d[,"sp"], d[,"ibm"], pch=16, cex=0.2,
xlab="S&P", ylab="IBM")
计算相关系数:
d
cor.test(d[,"sp"], d[,"ibm"])
##
## Pearson's product-moment correlation
##
## data: d[, "sp"] and d[, "ibm"]
## t = 26.664, df = 1027, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.6020164 0.6743519
## sample estimates:
## cor
## 0.6395979
相关系数为0.64,显著不等于零。
作线性回归并在散点图上叠加回归直线:
d
plot(d[["sp"]], d[["ibm"]], pch=16, cex=0.2,
xlab="S&P", ylab="IBM")
lm1
print(summary(lm1))
##
## Call:
## lm(formula = ibm ~ sp, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.279155 -0.032137 -0.002261 0.030647 0.280313
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.008974 0.001706 5.259 1.76e-07 ***
## sp 0.818776 0.030707 26.664 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.05443 on 1027 degrees of freedom
## Multiple R-squared: 0.4091, Adjusted R-squared: 0.4085
## F-statistic: 711 on 1 and 1027 DF, p-value: < 2.2e-16
abline(lm1, col="red", lwd=2)
回归方程为
\[
\text{IBM} = 0.008474 + 0.818776 \text{S$\&$P}
\]
一般地,
\[
r_t = \alpha + \beta m_t + \varepsilon_t
\]
其中\(r_t\)是某资产的收益率,
\(m_t\)是市场的收益率,
\(\alpha\)表示相对于市场收益的超额收益率。
这样的模型称为市场模型(market model)。