31.sim_stockPortfolio_trace

31.sim_stockPortfolio_trace - Rf: for(i in 1:length(Rfr)){...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
########################## #===> ((((( 2 ))))) <===# #===> main functions <===# ########################## #===> obtain a lot of tickers via included data set <===# library(stockPortfolio) #DATA: ticker <- c("C", "KEY", "WFC", "JPM", "SO", "DUK", "D", "HE", "EIX", "LUV", "AMR", "AMGN", "GILD", "CELG", "GENZ", "BIIB", "CAT", "DE", "HIT", "IMO", "MRO", "HES", "YPF", "^GSPC") #===> get data <===# gr1 <- getReturns(ticker, start='1999-12-31', end='2004-12-31') #Single index model: #Short sales allowed, default Rf=0. sm1SIM <- stockModel(gr1, model='SIM', index=24) # defaults: # Rf = 0 # shortSelling = TRUE ops1 <- optimalPort(sm1SIM) plot(ops1) portPossCurve(sm1SIM, add=TRUE, riskRange=5) #Generate many values of RF: Rfr <- seq(-5,.01,0.0005) #Initialize the two vectors: rbar_opt <- rep(0,length(Rfr)) risk_opt <- rep(0,length(Rfr)) #Use the single index model to find many points of tangency (one for each #value of
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Rf: for(i in 1:length(Rfr)){ simn <- stockModel(gr1, model='SIM', index=24, Rf=Rfr[i], shortSelling=FALSE) opsimn <- optimalPort(simn) rbar_opt[i] <- opsimn$R risk_opt[i] <- opsimn$risk } #Identify the efficient frontier when short sales not allowed: points(risk_opt,rbar_opt,type="l" ) #Add the minimum risk portfolio when short sales are not allowed (this is #an approximation - but a good one!): smnSIM_mvp <- stockModel(gr1, model='SIM', index=24, Rf=-100, shortSelling=FALSE) opnSIM_mvp <- optimalPort(smnSIM_mvp) points(opnSIM_mvp, optPortOnly=TRUE, colOP='#888888', cex=2) #View only the efficient frontier when short sales are not allowed: plot(risk_opt,rbar_opt,type="l" ) points(opnSIM_mvp, optPortOnly=TRUE, colOP='#888888', cex=2)...
View Full Document

This note was uploaded on 06/02/2011 for the course STATS 183 taught by Professor Nicolas during the Spring '11 term at UCLA.

Page1 / 2

31.sim_stockPortfolio_trace - Rf: for(i in 1:length(Rfr)){...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online