投资组合管理之一:经典Markowitz理论

1 均值方差优化问题

设投资者所能投资的资产有个品种,投资每个品种的权重为,每个品种的收益为代表第个资产的在投资组合中的权重,代表第个资产的收益,于是有:

在Markowitz理论中,资产的风险由标准差表示,用表示,于是有协方差矩阵:

个品种的期望收益为,则对于一个投资组合而言,其当前组合收益为,其期望收益和方差分别为:

在经典Markowitz理论中,Markowitz使用方差替代风险,于是整个问题就变成了如何选择到一组使其满足投资组合的方差最小:

其约束条件为:

2 有效边界问题

上面的均值方差模型没有考虑到无风险资产,现在假设投资组合中无风险资产的比例为,剩下的为风险资产的比例为,于是投资组合的期望收益为:

因为,所以:

即:

又因为,所以:

3 例子

任意选取上证50指数中的5支成分股票600000.SH,600048.SH,601169.SH,601669.SH,601989.SH,收益如下图所示:


这5支股票组成的最小均值方差组合及有效边界如下图:

R代码如下:

library(WindR)
library(data.table)
library(dplyr)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
library(DEoptim)
library(ROI)
require(ROI.plugin.glpk)
require(ROI.plugin.quadprog)
library(devtools)
w.start(showmenu = FALSE)

#准备数据
Index = w.wset('IndexConstituent','date=20130601;windcode=000016.SH')
Index = as.data.table(as.data.frame(Index))

Stock = w.wsd(Index$Data.wind_code[1],"close2","2013-06-01","2015-06-02","adjDate=0;Fill=Previous;PriceAdj=F")
Stock = as.data.table(as.data.frame(Stock))
colnames(Stock)[3] = as.character(unique(Stock$Code))
Stock = Stock[,2:3,with = FALSE]

for (i in 2:dim(Index)[1]) {
  SingleStock = w.wsd(Index$Data.wind_code[i],"close2","2013-06-01","2015-06-02","adjDate=0;Fill=Previous;PriceAdj=F")
  SingleStock = as.data.table(as.data.frame(SingleStock))
  colnames(SingleStock)[3] = as.character(unique(SingleStock $Code))
  SingleStock = SingleStock[,2:3,with = FALSE]
  
  setkey(SingleStock,Data.DATETIME)
  setkey(Stock,Data.DATETIME)
  Stock = merge(Stock,SingleStock,all=T)
}

rownames(Stock)=Stock$Data.DATETIME
Stock$Data.DATETIME = NULL
Stock=as.xts(Stock)


R <- Stock[, c(1,10,20,30,40,50)]
funds <- colnames(R)

#创建投资组合
init <- portfolio.spec(assets=funds)
init <- add.constraint(portfolio=init, type="full_investment")
init <- add.constraint(portfolio=init, type="long_only")

#创建有效前沿组合
init <- create.EfficientFrontier(R=R, portfolio=init, type="mean-StdDev")
chart.EfficientFrontier(init, match.col="StdDev", type="l", RAR.text="Sharpe Ratio", pch=4)

Comments

comments powered by Disqus