R 언어와 마크비츠 자산 조합 이론 학습 노트(fportfolio 패키지로 실현)

1510 단어
여전히 fportfolio 패키지의 데이터 세트 LPP2005.RET의 경우
library(fPortfolio)
# 
mvspec<-portfolioSpec()
setRiskFreeRate(mvspec)<-0
setSolver(mvspec)<-"solveRshortExact"
print(mvspec)
data<-100*LPP2005
Data<-portfolioData(100*LPP2005.RET,mvspec)#100*LPP2005.RET 
print(Data)
constrains<-"Short"
portfolioConstraints(data,mvspec,constrains)
# 
globminportfolio<-minvariancePortfolio(Data,mvspec,constrains)
print(globminportfolio)

# 
m1vspec<-portfolioSpec()
data1<-100*LPP2005.RET
Data1<-portfolioData(100*LPP2005.RET,m1vspec)
n<-ncol(data1)
setWeights(m1vspec)<-rep(1/n,n)
m1vPortfolio<-feasiblePortfolio(Data1,m1vspec,constraints="LongOnly")
print(m1vPortfolio)

# , 
mvspec1<-portfolioSpec()
setRiskFreeRate(mvspec1)<-0.05
targetReturn<-getTargetReturn(m1vPortfolio@portfolio)["mean"]
setTargetReturn(mvspec1)<-targetReturn
efficientportfolio<-efficientPortfolio(Data,spec=mvspec1)
weightsPie(efficientportfolio)
efficientportfolio

# 
data2<-100*LPP2005.RET
lppspec<-portfolioSpec()
setRiskFreeRate(lppspec)<-0.005
frontier<-portfolioFrontier(data2,lppspec)
#plot(frontier)
tailoredFrontierPlot(frontier)
frontierPlot(frontier)
cmlPoints(frontier,col=2)
frontier
weightsPlot(frontier)

좋은 웹페이지 즐겨찾기