R语言sharpiro_2 金融数据及其特征 | 金融时间序列分析讲义

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)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值