分析中国石化日均收益率,日均收益率与β系数
1、下载数据
global path "c:\cnstock\beta"
cd $path
cap mkdir out
global out "$path\out"
ssc install cntrade,replace
cntrade 600028
2、处理数据
```
use "600028.dta",clear
drop in 1/3195
keep in 1/732
save "600028.dta",replace
cntrade 000001, index
drop in 1/5881
keep in 1/732
save "000001.dta",replace
use "000001.dta", clear
merge 1:1 date using "600028.dta", nogen force
gen year = year(date)
rename rmt ret_mkt
rename rit ret_stk
order date year index* stk* ret*
save "merge_600028.dta", replace
```
以上操作是为了保留股票与指数2015-2017年数据并合并以便接下来的操作。
3、进行分析
```
use "merge_600028.dta",clear
foreach i in "2015" "2016" "2017"{
ameans ret_stk if year==`i'
}
```
求日均收益率,得到结果
```stata
bys year:egen sd=sd(ret_stk)
```
求日均波动率
```
foreach i in "2015" "2016" "2017"{
reg ret_stk ret_mkt if year==`i'
aaplot ret_stk ret_mkt if e(sample), xline(0,lp(dash) lc(red)) ///
yline(0,lp(dash) lc(red)) msize(*0.6) ///
title("中国石化 (600028) 的 Beta 系数, `i'") ///
xtitle("市场指数收益率(上综指)")
graph export "$out\aaplot_600028_`i'.png", replace
}
```
进行回归求β系数并画图,得到
网友评论