0% found this document useful (0 votes)
13 views56 pages

Factor Model Risk Decomposition in R

The document outlines a course on Factor Model Risk Analysis in R, focusing on macroeconomic factor models, portfolio risk budgeting, and Monte Carlo simulations. It includes practical examples using hedge fund data, descriptive statistics, and regression analysis to assess risk factors and returns. Various R packages are utilized for data manipulation, visualization, and statistical testing throughout the analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views56 pages

Factor Model Risk Decomposition in R

The document outlines a course on Factor Model Risk Analysis in R, focusing on macroeconomic factor models, portfolio risk budgeting, and Monte Carlo simulations. It includes practical examples using hedge fund data, descriptive statistics, and regression analysis to assess risk factors and returns. Various R packages are utilized for data manipulation, visualization, and statistical testing throughout the analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

AMATH 546/ECON 589

Factor Model Risk Analysis in R


29 May
May, 2013
Eric Zivot
Outline
• Data for examples
• Fit Macroeconomic factor model
• Factor risk
i k budgeting
b d i
• Portfolio risk budgeting
• Factor model Monte Carlo

© Eric Zivot 2011


Set Options and Load Packages
# set output options
> options(width = 70, digits=4)

# load required
q p
packages
g
> library(ellipse) # plot ellipses
> library(fEcofin) # various economic and
# financial data sets
> library(PerformanceAnalytics) # performance and risk
# analysis functions
> library(tseries) # MISC time series funs
> library(xts)
lib ( t ) # ti
time series
i objects
bj t
> library(zoo) # and utility functions

© Eric Zivot 2011


Hedge Fund Data
# load hypothetical long-short equity asset managers data
# from PerformanceAnalytics package
> data(managers)
> class(managers)
[1] "xts" "zoo"
> start(managers)
[1] "1996-01-30"
> end(managers)
[1]
1 "2006-12-30"
2006 12 30
> colnames(managers)
[1] "HAM1" "HAM2" "HAM3" "HAM4"
[5] "HAM5" "HAM6" "EDHEC LS EQ" "SP500 TR"
[9] "US 10Y TR" "US 3m TR"
# remove data prior to 1997-01-30 due to missing vals
> managers = managers["1997::2006"]

© Eric Zivot 2011


Plot Hedge Fund and Factor Returns
> [Link] <- function(...) {
+ lines(
lines(...)
)
+ abline(h=0)
+ }

# use [Link]() from zoo package for multi-panel plots


> [Link](managers[, 1:6], main="Hedge Fund Returns",
+ [Link]="multiple", type=“h”, lwd=2, col="blue",
+ panel=[Link])

> [Link](managers[, 7:10], main="Risk Factor Returns",


+ [Link]="multiple", type=“h”, lwd=2, col="blue",
+ panel=[Link])

© Eric Zivot 2011


HAM3 HAM2 HAM1

-0.05 0.00 0.05 0.10 0.15 0.00 0.05 0.10


0 0.1
-0
5.10 -0.0
05 0.00 0.05

1998
2000
2002

Index
2004
2006
HAM6 HAM5 HAM4

© Eric Zivot 2011


-0.04 0.00 0.02 0.04 0.06 -0.10 0.00 0.10 -0.15 --0.05 0.05 0.15
Hedge Fund Returns

1998
2000
2002

Index
2004
2006
US 3mTR US.10
[Link] [Link] [Link]

0.001 0.003 0.0


005 -0.06 -0.02
2 0.02 -0.15 -0.05 0.05 -0.0
06 -0.02 0.02 0.06
0

1998
2000
2002

Index

© Eric Zivot 2011


Risk Factor Returns

2004
2006
Plot Cumulative Returns
# plot cumulative returns using PerformanceAnalytics
# function [Link]()

# hedge funds
> [Link](managers[,1:6],
+ main="Cumulative
i "C l ti Returns",
t "
+ [Link]=TRUE,
+ [Link]="topleft")

# risk factors
> [Link](managers[,7:9],
+ main="Cumulative
main Cumulative Returns",
Returns ,
+ [Link]=TRUE,
+ [Link]="topleft")

© Eric Zivot 2011


Cumulative Returns

4..5
HAM1
HAM2
HAM3
4.0 HAM4
HAM5
HAM6
3.5
3.0
3
Value

2.5
2.0
1.5
1.0

Jan 97 Jan 98 Jan 99 Jan 00 Jan 01 Jan 02 Jan 03 Jan 04 Jan 05 Jan 06

Date
© Eric Zivot 2011
Cumulative Returns

3.0
EDHEC LS EQ
SP500 TR
2.5 US 10Y TR
Value

2.0
1.5
1.0

Jan 97 Jan 98 Jan 99 Jan 00 Jan 01 Jan 02 Jan 03 Jan 04 Jan 05 Jan 06

Date
© Eric Zivot 2011
Descriptive
p Statistics: Funds
# Use [Link]() function from PerformanceAnalytics package
> [Link](managers[,
g 1:6])
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
Observations 120.0000 120.0000 120.0000 120.0000 77.0000 64.0000
NAs 0.0000 0.0000 0.0000 0.0000 43.0000 56.0000
Minimum -0.0944 -0.0371 -0.0718 -0.1759 -0.1320 -0.0404
Quartile 1 0.0000 -0.0108 -0.0059 -0.0236 -0.0164 -0.0016
Median 0.0107 0.0075 0.0082 0.0128 0.0038 0.0128
Arithmetic Mean 0.0112 0.0128 0.0108 0.0105 0.0041 0.0111
Geometric Mean 0.0108 0.0121 0.0101 0.0090 0.0031 0.0108
Quartile 3 0.0252 0.0224 0.0263 0.0468 0.0309 0.0255
Maximum 0.0692 0.1556 0.1796 0.1508 0.1747 0.0583
SE Mean 0.0024 0.0033 0.0033 0.0050 0.0052 0.0030
LCL Mean (0.95) 0.0064 0.0062 0.0041 0.0006 -0.0063 0.0051
UCL Mean (0.95) 0.0159 0.0193 0.0174 0.0204 0.0145 0.0170
Variance 0.0007 0.0013 0.0013 0.0030 0.0021 0.0006
Stdev 0.0264 0.0361 0.0367 0.0549 0.0457 0.0238
Skewness -0.6488 1.5406 0.9423 -0.4064 0.0724 -0.2735
Excess Kurtosis 2.1223 2.7923 3.0910 0.6453 2.1772 -0.4311

© Eric Zivot 2011


Descriptive Statistics: Factors
> [Link](managers[, 7:9])
EDHEC LS EQ SP500 TR US 10Y TR
Observations 120
120.0000
0000 120
120.0000
0000 120
120.0000
0000
NAs 0.0000 0.0000 0.0000
Minimum -0.0552 -0.1446 -0.0709
Quartile 1 -0.0032 -0.0180 -0.0075
Median 0.0110 0.0105 0.0051
Arithmetic Mean 0.0095 0.0078 0.0048
Geometric Mean 0.0093 0.0068 0.0046
Quartile 3 0.0214 0.0390 0.0167
Maximum 0.0745 0.0978 0.0506
SE Mean 0.0019 0.0040 0.0019
LCL Mean (0.95) 0.0058 -0.0003 0.0011
UCL
C Mean (0
(0.95)
95) 0
0.0132
0132 0
0.0158
0158 0
0.0085
0085
Variance 0.0004 0.0020 0.0004
Stdev 0.0205 0.0443 0.0204
Skewness 0.0175 -0.5254 -0.4389
Kurtosis 0.8456 0.3965 0.9054

© Eric Zivot 2011


Testing for Normality
# use [Link]() function from tseries package
> [Link]([Link]$HAM1)
j q ( g $ )

Jarque Bera Test

data: [Link]$HAM1
X-squared = 33.7, df = 2, p-value = 4.787e-08

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6


statistic 33.7 85.4 67.2 5.88 15.2 1.02
P-value 0.000 0.000 0.000 0.053 0.000 0.602

Conclusion: All assets non-normal


non normal except HAM6

© Eric Zivot 2011


Sample
p Correlations
(pairwise complete obs)

EDHEC LS EQ
US 10Y TR

TR

TR
US 3m T

SP500 T
HAM2

HAM3

HAM5

HAM6

HAM4

HAM1
US 10Y TR

US 3m TR

HAM2

HAM3

HAM5

HAM6

HAM4

EDHEC LS EQ

SP500 TR

HAM1

© Eric Zivot 2011


Macroeconomic Factor Model (FM)
Rit  i  1i [Link]  2i [Link]  3iUS.10Y .TRt   it

• Rit = return in excess of T-Bill rate on hedge fund i in


monthh t.
• [Link] = excess total return on EDHEC long-
short
h t equity
it iindex
d (“ (“exotic
ti risk
i k ffactor”)
t ”)
• [Link] = excess total return on S&P 500 index
(traditional equity
eq it risk factor)
• [Link] = excess total return on US 10 year T-Note
(traditional rates risk factor)
© Eric Zivot 2011
Prepare Data for Regression
# subtract "US 3m TR" (risk free rate) from all
# returns. note: apply() changes [Link] to class
# "
"matrix”
t i ”
> [Link] = apply([Link], 2,
+ function(x) {x - [Link][,"US 3m TR"]})
> managers df = [Link]([Link])
[Link] as data frame(managers df)
# remove US 3m TR from [Link]
> [Link] = [Link][, -10]
# extract variable names for later use
> [Link] = colnames([Link])[1:6]
# eliminate spaces in factor names
> [Link] = c(
c("[Link]",
[Link] , "[Link]",
[Link] ,
+ "[Link]")
> colnames([Link])[7:9] = colnames(managers)[7:9]
+ = [Link]
> [Link] = [Link]([Link](managers[,
+ [Link]]))
© Eric Zivot 2011
Fit FM by Least Squares
# initialize list object to hold regression objects
> [Link] = list()

# initialize matrices and vectors to hold regression


# alphas
alphas, betas
betas, residual variances and r-squared values
> Betas = matrix(0, length([Link]),
+ length([Link]))
> colnames(Betas) = [Link]
> rownames(Betas) = [Link]
> Alphas = ResidVars = R2values =
+ rep(0,length([Link]))
> names(Alphas) = names(ResidVars) = names(R2values) =
+ [Link]

© Eric Zivot 2011


Fit FM by Least Squares
# loop over all assets and estimate time series
# regression
> for (i in [Link]) {
+ [Link] = [Link]([Link][, c(i, [Link])])
+ [Link] = [Link](paste(i,"~", ".", sep=" "))
+ [Link] = lm([Link],
( data=[Link]))
+ [Link] = summary([Link])
+ [Link][[i]] = [Link]
+ Alphas[i] = coef([Link])[1]
coef(fm fit)[1]
+ Betas[i, ] = coef([Link])[-1]
+ ResidVars[i] = [Link]$sigma^2
+ R2values[i] = [Link]$[Link]
fm summary$r squared
+ }

> names([Link])
( g )
[1] "HAM1" "HAM2" "HAM3" "HAM4" "HAM5" "HAM6"
© Eric Zivot 2011
FM fit for HAM1

0.05
0.00
Value

-0.05

Coefficients:
Estimate Std. Error
(Intercept) 0.00537 0.00185
EDHEC LS EQ 0
[Link] 0.26777
26777 0.12399
0 12399
[Link] 0.28719 0.05740
Fitted [Link] -0.23024 0.08709
-0.10

Actual Multiple R-squared: 0.501

J
Jan 97 J
Jan 98 J
Jan 99 J
Jan 00 J
Jan 01 J
Jan 02 J
Jan 03 J
Jan 04 J
Jan 05 J
Jan 06

Date
© Eric Zivot 2011
Regression Results
Fund Intercept [Link] SP500 US.10YR  R2
HAM1 0.005*** 0.268** 0.287*** -0.230*** 0.019 0.501
HAM2 0.001 1.547*** -0.195** 0.050 0.025 0.514
HAM3 -0.001
0 001 1 251*** 0.131**
1.251*** 0 131** 0 144
0.144 0 022
0.022 0 657
0.657
HAM4 -0.002 1.222*** 0.273** -0.139 0.043 0.413
HAM5 -0.005 1.621*** -0.184 0.271 0.040 0.232
HAM6 0.004*** 1.250*** -0.175* -0.174* 0.016 0.564

***, **, * denote significance at the 1%,


1% 5% and 10% level,
level respectively

© Eric Zivot 2011


FM Covariance Matrix
# risk factor sample
p covariance matrix
> [Link] = var([Link][, [Link]])

# FM covariance matrix
> [Link] = Betas%*%[Link]%*%t(Betas) +
+ diag(ResidVars)

# FM correlation matrix
> [Link] = cov2cor([Link])

© Eric Zivot 2011


FM Correlations

HAM5

HAM2

HAM6

HAM4

HAM3

HAM1
H

H
HAM5

HAM2

HAM6

HAM4

HAM3

HAM1

© Eric Zivot 2011


Fund of Hedge Funds (FoHF)
Equally
q y weighted
g portfolio
p (fund
( of hedge
g funds):
)

1
wi  , i  HAM1, ,HAM6
6
> [Link] = rep(1,6)/6
> names([Link]) = [Link]
> w
[Link]
vec
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
0.167 0.167 0.167 0.167 0.167 0.167
# portfolio returns. Note: need to eliminate NA values
# from HAM5 and HAM6
> r.p = [Link]([Link]([Link][,
manager names]))%*%w vec
[Link]]))%*%[Link]
> [Link] = zoo(r.p, [Link](rownames(r.p)))
© Eric Zivot 2011
FoHF (Portfolio) FM
# portfolio factor model
> alpha.p
l h = [Link](crossprod(Alphas,[Link]))
i ( d(Al h ))
> beta.p = t(Betas)%*%[Link]
> [Link] = t(beta.p)%*%[Link]%*%beta.p
> [Link] = t([Link])%*%diag(ResidVars)%*%[Link]
> [Link].p = [Link] + [Link]
> [Link].p = [Link]([Link].p)
> [Link].p = [Link]([Link]/[Link].p)

> fm.p = c(alpha.p, beta.p, sqrt([Link].p), [Link].p)


> names(fm.p) = c("intercept", [Link], "sd", “r2")
> fm.p
fm p
intercept [Link] [Link] [Link] sd
0.000455 1.193067 0.022973 -0.012990 0.027817
r-squared
0.812435

© Eric Zivot 2011


Factor Risk Budgeting
# use factorModelFactorSdDecomposition() function
# from factorAnalytics
y package
p g
> args(factorModelFactorSdDecomposition)
function ([Link], [Link], sig2.e)
# Compute factor SD decomposition for HAM1
> [Link].HAM1 =
factorModelFactorSdDecomposition(Betas["HAM1",],
+ [Link], ResidVars[
ResidVars["HAM1"])
HAM1 ])

> names([Link].HAM1)
[1] "[Link]" "[Link]" "[Link]" "[Link]"

© Eric Zivot 2011


Factor Contributions to SD
> [Link].HAM1
$[Link]
[1] 0.0265

$[Link]
$ f
[Link] [Link] [Link] residual
MCR 0.0119 0.0295 -0.00638 0.711

$[Link]
[Link] [Link] [Link] residual
CR 0.00318 0.00847 0.00147 0.0134

$[Link]
[Link] [Link] [Link] residual
PCR 0.12 0.319 0.0553 0.506
© Eric Zivot 2011
Factor Contributions to SD
# loop over all assets and store results in list
> [Link] = list()
> for (i in [Link]) {
+ [Link][[i]] =
factorModelFactorSdDecomposition(Betas[i,],
+ [Link],
f t ResidVars[i])
id [i])
+ }

# add portfolio factor SD decomposition to list


> [Link][["PORT"]] =
factorModelFactorSdDecomposition(beta.p,
+ [Link], [Link])

> names([Link])
[1] "HAM1"
HAM1 "HAM2"
HAM2 "HAM3"
HAM3 "HAM4"
HAM4 "HAM5"
HAM5 "HAM6"
HAM6 "PORT"
PORT

© Eric Zivot 2011


Factor Contributions to SD
# function to extract contribution to sd from list
> ggetCSD = function(x)
( ) {
+ x$[Link]
+}

# extract contributions to SD from list


> [Link] = sapply([Link], getCSD)
> rownames([Link]) = c([Link], "residual")

# create stacked barchart


> barplot([Link], main="Factor Contributions to SD",
+ [Link]=T, [Link]=list(x="topleft"),
+ col=c("blue","red","green","white"))

© Eric Zivot 2011


Factor Contributions to SD
Factor Contributions to SD

0.05 residual
[Link]
[Link]
[Link]
04
0.0
0.03
0.02
0.01
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 PORT

© Eric Zivot 2011


Factor Contributions to ETL
# first combine HAM1 returns, factors and std residuals
> tmpData = cbind([Link][,1],
cbind(managers df[ 1]
+ [Link][,[Link]],
+ residuals([Link][[1]])/sqrt(ResidVars[1]))
> co
colnames(tmpData)[c(1,5)]
a es(t p ata)[c( ,5)] = c(
c([Link][1],
a age . a es[ ],
"residual")
> [Link].HAM1 =
factorModelFactorEsDecomposition(tmpData Betas[1,],
factorModelFactorEsDecomposition(tmpData, Betas[1 ]
+ ResidVars[1], [Link]=0.05)
> names([Link].HAM1)
[1] "[Link]"
[Link] "[Link]"
[Link] "[Link]"
[Link] "[Link]"
[Link]
[5] "[Link]" "[Link]" "[Link]"

© Eric Zivot 2011


Factor Contributions to ETL: HAM1
> [Link].HAM1
$[Link]
5%
0.0309

$[Link]
$ d
[1] 6

$[Link]
$idx exceed
1998-08-30 2001-09-29 2002-07-30 2002-09-29 2002-12-30
20 57 67 69 72
2003 01 30
2003-01-30
73

© Eric Zivot 2011


Factor Contributions to ETL: HAM1
$[Link]
$ES fm
[1] 0.0577

$[Link]
$ c S.
[Link] [Link] [Link] residual
MCES 0.0289 0.0852 -0.0255 1.32

$[Link]
[Link] [Link] [Link] residual
CES 0.00774 0.0245 0.00587 0.025

$[Link]
[Link] [Link] [Link] residual
PCES 0
0.134
134 0
0.424
424 0
0.102
102 0
0.433
433

© Eric Zivot 2011


HAM1 returns and 5% VaR Violations

0.00
Returns

-0.10

1998 2000 2002 2004 2006

Index

Mean of [Link] when HAM1 <= 5% VaR


0.06
Retturns

00
0.0
-0.06

1998 2000 2002 2004 2006

MCETL = -0.029 Index


© Eric Zivot 2011
HAM1 returns and 5% VaR Violations
0.00
Returns

-0.10

1998 2000 2002 2004 2006

Index

Mean of [Link] when HAM1 <= 5% VaR


0.05
Retturns

-0.05
5
-0.15

1998 2000 2002 2004 2006

Index
MCETL = -0.085
© Eric Zivot 2011
HAM1 returns and 5% VaR Violations

0.00
Returns

-0.10

1998 2000 2002 2004 2006

Index

MCETL = 0.026 Mean of [Link] when HAM1 <= 5% VaR


0.00 0.04
urns

0
Retu

-0.06

1998 2000 2002 2004 2006

Index
© Eric Zivot 2011
HAM1 returns and 5% VaR Violations

0.00
Returns

-0.10

1998 2000 2002 2004 2006

Index

Mean of Standardized Residual when HAM1 <= 5% VaR


2
Retturns

-2 -1 0 1

1998 2000 2002 2004 2006

MCETL = -1.32 Index


© Eric Zivot 2011
Factor Contributions to ETL
Factor Contributions to ET L

residual
[Link]
[Link]
0.10

[Link]
0.08
0.06
0.04
0.02
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 PORT

© Eric Zivot 2011


Portfolio Risk Budgeting
# use portfolioSdDecomposition() function from
# factorAnalytics package
> args(portfolioSdDecomposition)
function ([Link], [Link])
# compute with sample covariance matrix (pairwise
# complete observations)
> [Link] = cov([Link][,[Link]],
+ use="[Link]")
> [Link] =
+ portfolioSdDecomposition([Link], [Link])

> names([Link])
( t d d l )
[1] "sd.p" "mcsd.p" "csd.p" "pcsd.p"

© Eric Zivot 2011


Portfolio SD Decomposition
> [Link]
$sd.p
[1] 0.0261

$mcsd.p
HAM1
1 HAM2
2 HAM3
3 HAM4
4 HAM5
5 HAM6
6
MCSD 0.0196 0.0218 0.0270 0.0431 0.0298 0.0155

$csd p
$csd.p
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
CSD 0.00327 0.00363 0.00451 0.00718 0.00497 0.00259

$pcsd.p
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
PCSD 0.125 0.139 0.172 0.275 0.19 0.099

© Eric Zivot 2011


Fund Contributions to Portfolio SD
Fund Percent Contributions to Portfolio SD
0.25
0.20
PercentContribution

0.15
0.10
0.05
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6

© Eric Zivot 2011


Portfolio ETL Decomposition
# use ES() function in PerformanceAnalytics package
> [Link]
p =
ES([Link]([Link][,[Link]]),
+ p=0.95, method="historical",
+ portfolio_method = "component",
+ weights = [Link])
> [Link]
$`-r_exceed/c_exceed`
[1]
1 00.0479
0 9

$c_exceed
[1] 3

$realizedcontrib
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
0.1874 0.0608 0.1479 0.3518 0.1886 0.0635
© Eric Zivot 2011
Portfolio ETL Decomposition
# use portfolioEsDecomposition from factorAnalytics
# package.
> args(portfolioEsDecomposition)
function (bootData, w, delta.w = 0.001, [Link] =
0.01, method = c("derivative",
"
"average"),
") [Link]
th d = c("HS",
(" S" "C
"CornishFisher"))
i h i h "))
> [Link] =
portfolioEsDecomposition([Link]([Link][,manager.
names]),[Link], [Link]=0.05)

> names([Link])
[1] "[Link]" "[Link]" "[Link]" "[Link]"
[5] "MCES" "CES" "PCES"

© Eric Zivot 2011


Portfolio ETL Decomposition
> [Link]
$[Link] $[Link] $[Link] $[Link]
5% [1] 00.0428
0428 [1] 4 [1] 10 11 13 32
0.0269

$MCES
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
MCES 0.0417 0.0113 0.0371 0.0976 0.0505 0.0186

$CES
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
CES 0.00695 0.00188 0.00618 0.0163 0.00842 0.00310

$PCES
HAM1 HAM2 HAM3 HAM4 HAM5 HAM6
PCES 0.162 0.0439 0.145 0.38 0.197 0.0724

© Eric Zivot 2011


Fund Contributions to Portfolio ETL
Fund Percent Contributions to Portfolio ET L
0.35
0.30
0.25
Percent Contribution

0.20
0.15
0.10
0.05
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6

© Eric Zivot 2011


Portfolio Returns and 5% VaR Violations

0.00 0.04
Returns

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM1 when PORT <= 5% VaR


-0.05 0..00 0.05
urns
Retu

2002 2003 2004 2005 2006 2007

Index
MCETL = -0.042
© Eric Zivot 2011
Portfolio Returns and 5% VaR Violations
0.00 0.04
Returns

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM2 when PORT <= 5% VaR


-0.04 0.00 0.04 0.08
urns
Retu

2002 2003 2004 2005 2006 2007

Index
© Eric Zivot 2011
Portfolio Returns and 5% VaR Violations

0.00 0.04
Returns
R

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM3 when PORT <= 5% VaR


0.00 0.04
Retturns

0
-0.06

2002 2003 2004 2005 2006 2007

Index
© Eric Zivot 2011
Portfolio Returns and 5% VaR Violations
0.00 0.04
Returns

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM4 when PORT <= 5% VaR


-0.15 -0.05 0.05
urns
Retu

2002 2003 2004 2005 2006 2007

Index
© Eric Zivot 2011
Portfolio Returns and 5% VaR Violations
0.00 0.04
Returns

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM5 when PORT <= 5% VaR


0.00
urns
Retu

-0.10

2002 2003 2004 2005 2006 2007

Index
© Eric Zivot 2011
Portfolio Returns and 5% VaR Violations

0.00 0.04
Returns

-0.06

2002 2003 2004 2005 2006 2007

Index

Mean of HAM6 when PORT <= 5% VaR


0.04
Retturns

0.00
0
-0.04

2002 2003 2004 2005 2006 2007

Index
© Eric Zivot 2011
Factor Model Monte Carlo (FMMC)
# resample from historical factors
> [Link]
n boot = 5000

# set random number seed


> [Link](123)
[Link]( 3)

# [Link] reshuffled indices


> bootIdx = sample(nrow([Link]), [Link],
+ replace=TRUE)

# resampled factor data


> [Link] = [Link]([Link][bootIdx,
+ [Link]])

© Eric Zivot 2011


FMMC with Normal Residuals
# FMMC using normal distribution for residuals and
# alpha = 0
> [Link] = matrix(0, [Link], length([Link]))
> [Link] = matrix(0, [Link], length([Link]))
> co
colnames([Link])
a es( etu [Link]) = co
colnames([Link])
a es( es d.s ) =
+ [Link]
# FMMC loop
for (i in [Link]) {
[Link] = [Link]%*%Betas[i, ]
[Link][, i] = rnorm([Link],sd=sqrt(ResidVars[i]))
[Link][, i] = [Link] + [Link][, i]
}

# compute portfolio return and fm residual


> [Link]
return p boot = [Link]%*%wvec
returns boot%*%wvec
> [Link].p = [Link]%*%[Link]
© Eric Zivot 2011
FMMC Factor Contribution
# compute decomposition in loop
to ETL
> [Link] = list()
> for (i in [Link]) {
+ tmpData = cbind([Link][, i], [Link],
+ [Link][, i]/sqrt(ResidVars[i]))
> colnames(tmpData)[c(1,5)] = c([Link][i], "residual")
> [Link][[i]] =
factorModelFactorEsDecomposition(tmpData, Betas[i,],
+ ResidVars[i], [Link]=0.05)
}
# add
dd portfolo
f l retsults
l - need
d factor
f model
d l residuals
id l
> tmpData = cbind([Link], [Link],
+ [Link].p/sqrt([Link]([Link])))
> colnames(tmpData)[c(1,5)]
( p )[ ( , )] = c("PORT",
( , "residual")
)
> [Link][["PORT"]] =
factorModelFactorEsDecomposition(tmpData, beta.p,
+ [Link], [Link]=0.05)

© Eric Zivot 2011


FMMC Factor Contributions to ETL
Factor Contributions to ET L

residual
0.10

[Link]
[Link]
[Link]
0.08
0.06
0.04
0.02
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6 PORT

© Eric Zivot 2011


FMMC Fund Contribution to
Portfolio ETL
> [Link] =
portfolioEsDecomposition([Link],
+ [Link],
. ec, ta
[Link]=0.05)
.p ob 0.05)

© Eric Zivot 2011


FMMC Fund Contributions to
Portfolio ETL
Fund Percent Contributions to Portfolio ET L
0.25
20
0.2
Percent Contribution

0.15
0.10
0.05
0.00

HAM1 HAM2 HAM3 HAM4 HAM5 HAM6

© Eric Zivot 2011

You might also like