Stockportfolio

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

stockPortfolio

YIK LUN, KEI


allen29@ucla.edu
library(stockPortfolio)
ticker <-

c("C", "KEY", "WFC", "JPM", "SO", "DUK", "D", "HE", "EIX", "LUV", "AMGN",
"GILD", "CELG", "BIIB", "CAT", "DE", "IMO", "MRO", "HES", "YPF", "^GSPC")

gr1 <- getReturns(ticker, start='1999-12-31', end='2004-12-31')

No model - classical Markowitz model:


m1 <- stockModel(gr1, drop=21) # drop index
#Find the point of tangency:
op1 <- optimalPort(m1)
#Plot the 20 stocks, the index, and point G (point of tangency):
plot(op1)
#Add the portfolio possibilities curve:
portPossCurve(m1, add=TRUE)
#Add the tangent (the following will draw the line only up to G:
segments(0,0,op1$risk,op1$R)
#If you want to extend the tangent beyond G:
slope <- (op1$R-0)/op1$risk
segments(0,0,2*op1$risk, m1$Rf+slope*2*op1$risk)
#Add a cloud of points for visualization:
portCloud(m1)

0.02
0.00

0.01

Return

0.03

0.04

Risk and Return of Stocks

0.00

0.05

0.10

0.15

0.20

0.25

Risk

Single index model:


#Short sales allowed, defaults: Rf = 0, shortSelling = TRUE
sm1SIM <- stockModel(gr1, model='SIM', index=21)
#Short sales not allowed & a choice of Rf.
sm2SIM <- stockModel(gr1, model='SIM', index=21, Rf=0.03/12, shortSelling=FALSE)
op1SIM <- optimalPort(sm1SIM)
op2SIM <- optimalPort(sm2SIM)
plot(op1SIM)
points(op2SIM, optPortOnly=TRUE, colOP='#888888', cex=2)
portPossCurve(sm1SIM, add=TRUE,riskRange=5)

0.02
0.00

0.01

Return

0.03

0.04

Risk and Return of Stocks

0.00

0.05

0.10

0.15

0.20

0.25

Risk

Constant correlation model:


sm1CCM
sm2CCM

<- stockModel(gr1, model='CCM', drop=21)


<- stockModel(gr1, model='CCM', drop=21, shortSelling=FALSE)

#===> identify the optimal portfolio for constant correlation model<===#


op1CCM <- optimalPort(sm1CCM)
op2CCM <- optimalPort(sm2CCM)
plot(op1CCM)
points(op2CCM, optPortOnly=TRUE, colOP='#888888', cex=2)
portPossCurve(sm1CCM, add=TRUE, riskRange=5)

0.02
0.00

0.01

Return

0.03

0.04

Risk and Return of Stocks

0.05

0.10

0.15

0.20

0.25

Risk

Adjusting the betas using Blumes and Vasiceks techniques in single index model
#Need another historical period:
gr2 <- getReturns(ticker, start='2004-12-31', end='2009-12-31')
#Single index model for period 2004-2009:
sm3SIM <- stockModel(gr2, model='SIM', index=21)
#Update the model using Blume's technique:
simBlu <- adjustBeta(sm1SIM, sm3SIM) # default method is "Blume"
#Update the model using Vasicek's technique:
simVas <- adjustBeta(sm3SIM, method="V")
#Optimize:
op3SIM <- optimalPort(sm3SIM)
opBlu <- optimalPort(simBlu)
opVas <- optimalPort(simVas)
plot(op3SIM, xlim=c(0, 0.25), ylim=c(-0.03, 0.12), main="Betas unadjusted")
portPossCurve(sm3SIM, add=TRUE, riskRange=10)
4

0.05
0.00

Return

0.10

Betas unadjusted

0.00

0.05

0.10

0.15

0.20

Risk

plot(opBlu, xlim=c(0, 0.25), ylim=c(-0.03, 0.12), main="Betas - Blume")


portPossCurve(simBlu, add=TRUE, riskRange=10)

0.25

0.05
0.00

Return

0.10

Betas Blume

0.00

0.05

0.10

0.15

0.20

Risk

plot(opVas, xlim=c(0, 0.25), ylim=c(-0.03, 0.12), main="Betas - Vasicek")


portPossCurve(simVas, add=TRUE, riskRange=10)

0.25

0.00

Return

0.05

0.10

Betas Vasicek

0.00

0.05

0.10

0.15

0.20

Risk

op1
##
##
##
##
##
##
##
##
##
##
##

Model: no model specified.


Expected return: 0.02379712
Risk estimate:
0.02992525
Portfolio allocation:
C
KEY
-0.05077884 -0.01803800
D
HE
0.06000250 0.14401262
CELG
BIIB
0.04602932 0.07948149

WFC
JPM
SO
DUK
0.23388976 0.10071405 0.30307486 -0.24457688
EIX
LUV
AMGN
GILD
0.04989857 -0.03429291 -0.08000181 0.06403138
CAT
DE
IMO
MRO
0.01360471 0.11595350 0.31766423 -0.11059292
7

0.25

##
HES
## -0.04398222

YPF
0.05390659

op1CCM
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: constant correlation model


Expected return: 0.02233795
Risk estimate:
0.03820264
Portfolio allocation:
C
KEY
-0.029975636 0.047191271
DUK
D
-0.036451917 0.119763275
AMGN
GILD
-0.078260404 0.051914208
DE
IMO
0.032634460 0.305939862

WFC
JPM
SO
0.051725845 -0.065997705 0.208502051
HE
EIX
LUV
0.323580180 -0.019731709 -0.012615475
CELG
BIIB
CAT
0.004786165 0.005214365 0.056663054
MRO
HES
YPF
0.026561873 -0.006198388 0.014754625

op1SIM
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: single index model


Expected return: 0.02017085
Risk estimate:
0.02598451
Portfolio allocation:
C
KEY
-0.057727971 0.061337599
DUK
D
0.009832096 0.103426458
AMGN
GILD
-0.003838124 0.042383781
DE
IMO
0.045868659 0.194444435

WFC
JPM
0.069728577 -0.073997090
HE
EIX
0.209283933 0.028118640
CELG
BIIB
0.017485828 0.021933434
MRO
HES
0.043138688 0.024329979

SO
0.177268392
LUV
0.014045862
CAT
0.047382433
YPF
0.025554392

op2CCM
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: constant correlation model


Expected return: 0.01941413
Risk estimate:
0.03472464
Portfolio allocation:
C
KEY
WFC
JPM
SO
DUK
0.000000000 0.029059502 0.030164186 0.000000000 0.179801138 0.000000000
D
HE
EIX
LUV
AMGN
GILD
0.094870217 0.284219513 0.000000000 0.000000000 0.000000000 0.041755769
CELG
BIIB
CAT
DE
IMO
MRO
0.000000000 0.000000000 0.040734265 0.016442946 0.269848245 0.010125804
HES
YPF
0.000000000 0.002978415

op2SIM
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: single index model


Expected return: 0.01926181
Risk estimate:
0.03031291
Portfolio allocation:
C
KEY
WFC
JPM
SO
DUK
0.000000000 0.060909492 0.058142240 0.000000000 0.000000000 0.000000000
D
HE
EIX
LUV
AMGN
GILD
0.117471633 0.273975244 0.034840850 0.000000000 0.000000000 0.055805711
CELG
BIIB
CAT
DE
IMO
MRO
0.025449941 0.028537244 0.016273719 0.032003331 0.260919984 0.023581898
HES
YPF
0.005995484 0.006093228

op3SIM
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: single index model


Expected return: 0.03069542
Risk estimate:
0.050631
Portfolio allocation:
C
KEY
WFC
JPM
SO
-0.163425025 -0.217516214 -0.008610113 0.011793372 0.166009989
DUK
D
HE
EIX
LUV
0.281226197 0.129340183 -0.038780960 0.029198862 -0.112066172
AMGN
GILD
CELG
BIIB
CAT
-0.019990167 0.315392663 0.215680603 -0.006920874 -0.011229793
DE
IMO
MRO
HES
YPF
0.049475294 0.120843676 0.090165012 0.107035611 0.062377856

opBlu
##
##
##
##
##
##
##
##
##
##
##
##
##

Model: single index model


Expected return: 0.06210231
Risk estimate:
0.1098455
Portfolio allocation:
C
KEY
WFC
JPM
SO
-0.351892917 -0.542649312 -0.023565045 0.007496025 0.008559911
DUK
D
HE
EIX
LUV
0.355813905 0.145124768 -0.163334908 -0.063269920 -0.285552880
AMGN
GILD
CELG
BIIB
CAT
-0.096470361 0.630714684 0.465289502 -0.046381965 0.009049669
DE
IMO
MRO
HES
YPF
0.141715079 0.254033131 0.202132364 0.231576991 0.121611278

You might also like