Using R for Hedge Fund of
Funds Risk Management
Funds Risk Management
R/Finance 2009: Applied Finance with R R/Finance 2009: Applied Finance with R University of Illinois Chicago, April 25, 2009
Eric Zivot
Professor and Gary Waterman Distinguished Scholar, Department of Economics
Adjunct Professor, Departments of Finance and Statistics University of Washington
Outline
Outline
• Hedge fund of funds environmentHedge fund of funds environment • Factor model risk measurement
i l i i i
• R implementation in corporate environment • Dealing with unequal data histories
• Some thoughts on S-PLUS and S+FinMetrics vs. R in Finance
Hedge Fund of Funds Environment
• HFoFs are hedge funds that invest in other hedge funds
– 20 to 30 portfolios of hedge funds – Typical portfolio size is 30 funds
• Hedge fund universe is large: 5000 live funds – Segmented into 10-15 distinct strategy types
• Hedge funds voluntarily report monthly performance to commercial databases
– Altvest, CISDM, HedgeFund.net, Lipper TASS, CS/Tremont, HFR
Hedge Fund Universe
Hedge Fund Universe
Live funds
Convertible Arbitrage Dedicated Short Bias Emerging Markets Equity Market Neutral Event Driven
Fixed Income Arbitrage Global Macro
Long/Short Equity Hedge Managed Futures
Multi-Strategy Fund of Funds
Characteristics of Monthly Returns
Characteristics of Monthly Returns
• Reporting biasesReporting biases
– Survivorship, backfill
N l b h i
• Non-normal behavior
– Asymmetry (skewness) and fat tails (excess k t i )
kurtosis)
• Serial correlation
– Performance smoothing, illiquid positions
Characteristics of Hedge Fund Data
Characteristics of Hedge Fund Data
fund1 fund2 fund3 fund4 fund5 Observations 122.0000 107.0000 135.0000 135.0000 135.0000 NAs 13.0000 28.0000 0.0000 0.0000 0.0000 Minimum -0.0842 -0.3649 -0.0519 -0.1556 -0.2900 Quartile 1 -0.0016 -0.0051 0.0020 -0.0017 -0.0021 Median 0.0058 0.0046 0.0060 0.0073 0.0049 Arithmetic Mean 0.0038 -0.0017 0.0063 0.0059 0.0021 Geometric Mean 0.0037 -0.0029 0.0062 0.0055 0.0014 Quartile 3 0.0158 0.0129 0.0127 0.0157 0.0127 Maximum 0.0311 0.0861 0.0502 0.0762 0.0877 Variance 0.0003 0.0020 0.0002 0.0008 0.0013 Stdev 0.0176 0.0443 0.0152 0.0275 0.0357 Skewness -1.7753 -5.6202 -0.8810 -2.4839 -4.9948 Kurtosis 5.2887 40.9681 3.7960 13.8201 35.8623 Rho1 0.6060 0.3820 0.3590 0.4400 0.383
Factor Model Risk Measurement in
HFoFs Portfolio
• Quantify factor risk exposuresQuantify factor risk exposures
– Equity, rates, credit, volatility, currency, commodity etc
commodity, etc.
• Quantify tail risk
V R ETL – VaR, ETL
• Risk budgeting
– Component, incremental, marginal
Commercial Products
Commercial Products
www riskdata com www finanalytica com www.riskdata.com www.finanalytica.com
Very expensive! R is not! Very expensive! R is not!
Factor Model: Methodology
Factor Model: Methodology
1 1
,
it i i t ik kt itR
=
α β
+
F
+ +
β
F
+
ε
1
i i iti
t
t
T
α
′
ε
=
+
β
F
t+
F1, , ; , ,
~ ( ,
)
i t Fi
=
n t
=
t
T
F
μ Σ
…
…
F 2 ,(
)
~ (0,
)
t F it ε iε
σ
μ
cov(
, ) 0 for all , and
cov(
) 0 for
jt itf
j i
t
i
j
ε
ε ε
=
=
≠
cov( ,
ε ε
it jt) 0 for
=
i
≠
j
Practical Considerations
Practical Considerations
• Many potential risk factors ( > 50)Many potential risk factors ( > 50)
• High collinearity among some factors
i k f di i li /
• Risk factors vary across discipline/strategy • Nonlinear effects
• Dynamic effects
• Time varying coefficientsTime varying coefficients
• Common histories for factors; unequal histories for fund performance
Expected Return Decomposition
Expected Return Decomposition
]
[
]
[
]
[
R
E
F
E
F
E
[
R
it]
iβ
i1E
[
F
1t]
β
ikE
[
F
kt]
E
=
α
+
β
+
+
β
E t d t d t “b t ” ] [ ] [ 1 1 t ik kt i E Fβ
E Fβ
+ +Expected return due to “beta” exposure
1
1 t ik kt
i
β
β
Expected return due to manager specific “alpha”
]) [ ] [ ( ] [ it i1 1t ik kt i E R β E F β E F α = − + +
Variance Decomposition
p
2
var( )R = β′ var( )F β + var( )
ε
= β Σ β′ +σ
,var( )Rit = βi var( )Ft βi + var( )
ε
it = β Σ βi F i +σ
ε isystematic specific
Variance contribution due to factor exposures
) var( ) var( ) var( 1 22 2 2 2 1 F t β F t βk Fkt β + + + ) cov( 2 ) cov( 2
β
β
F F + +β
β
F FVariance contribution due to covariances between factors
) , cov( 2 ) , cov( 2
β
1β
2 F1t F2t + +β
k−1β
k Fk−1t FktCovariance
Covariance
t t=
+
+
tR
α
B F
ε
( )R Σ BΣ B′ + D 1 1 n n k t1 t1 n× × × k× n×+
+
tR
α
B F
ε
2 2 ,1 , var( ) ( , , ) t FM n R diag ε εσ
εσ
ε ′ = Σ = + = F BΣ B D Dε ε,1 … ε,n cov( ,R Rit jt ) = β′i var( )Ft β j = β Σ β′i F j Note:Portfolio Analysis
Portfolio Analysis
1 ( , , ) portfolio weightsw wn ′ = = w … R = w′R = w′α + w′BF + w′ε 1 ( , , )n p g n it i t n i i n i i n it i t t t pt w w w R w R ε α + ′ + = = + + = =∑
∑
∑
∑
β F ε w BF w α w R w pt t p p i it i t i i i i i i i it i R w w w w ε α ε α + ′ + = + +∑
∑
∑
∑
= = = = F β F β 1 1 1 1 pt t p pPortfolio Variance Decomposition
Portfolio Variance Decomposition
′ + ′ ′ ′ R 2 ( ) (R ) BΣ B D ′ ′ = ′ + ′ ′ = ′ = = F systematic p F t pt p R 2 , 2 var( ) var( ) σ σ w B BΣ w Dw w w B BΣ w w R w
∑
= ′ = n i i i specific p y p w 1 2 , 2 , , ε σ σ w Dw 2 2 , 2 p systematic p R σ σ = = i 1 σ p 2 2 2 , , covariance terms k p systematic p F p p j jj σ = β ′Σ β =∑
β σ + 1 2 2 2 covariance terms j k p systematic p j jj σ β σ = = , −∑
, 1 p systematic p j jj j β =∑
Risk Budgeting: Volatility
Risk Budgeting: Volatility
p σ BΣ B w Dw MCR = ∂ = F ′ + Marginal contributions systematic p σ w B BΣ MCR w MCR F ′ = = ∂ = g to risk specific p systematic σ σ Dw MCR = p σ ( ) p σ ∂ ′ + = = w BΣFB w Dw CR w Components to risk p σ = = ∂ CR w w
∑
= = ′CR n CR σ 1 p∑
= = = i p i CR 1 σ CR 1Tail Risk Measures
Tail Risk Measures
Value-at-Risk (VaR)
1
( )
VaR
α= − = −
q
αF
−α
of returns
F
=
CDF
R
Expected Shortfall (ES)
[ | ]
ES E R R VaR[ | ≤ ]
Tail Risk Measures: Normal Distribution
Tail Risk Measures: Normal Distribution
2 2
~
(
,
),
p p p p FMR
N
μ σ
σ
= Σ
w
′
w
1, ( )
1
N p pVaR
α= −
μ
−
σ
×
z
αz
α= Φ
−α
1
( )
N p pES
αμ
σ
φ
z
αα
=
−
Tail Risk Measures: Non-Normal Distributions
Tail Risk Measures: Non Normal Distributions
Use Cornish-Fisher expansion to account for asymmetry p y y and fat tails
CF i i VaRα = −μ σ− × zα
(
2)
(
3)
(
3)
2 1 1 1 1 3 2 5 6 24 36 i ii z skewi z z ekurti z z skewi
α α α α α α α μ σ ⎡ ⎤ + ⎢− − − − + − ⎥ ⎣ ⎦ : CF
ESα Formula given in Boudt, Peterson and Croux (2008)
"Estimation and Decomposition of Downside Risk for Portfolios with Non-Normal Returns," Journal of Risk and implementation in PerformanceAnalytics
Risk Budgeting: Tail Risk
Value-at-Risk (VaR) cV a Rα ,i , 1 1 , n n i i i i i i VaR VaR w w m VaR w α α α = = ∂ = = × ∂∑
∑
,i [ i | p ] i VaR m VaR E R R VaR w α α α ∂ = = − = ∂Expected Shortfall (ES)
n n ES ES
∑
∂ α∑
ES ,i cE Sα , 1 1 , [ | ] i i i i i i ES w w m ES w ES ES E R R V R α α α α = = = = × ∂ ∂ ≤∑
∑
,i [ i | p ] m ES E R R VaR w α α = ∂ = − ≤ αRisk Budgeting: Explicit Formulas
Risk Budgeting: Explicit Formulas
• Normal distributionNormal distribution
– See Jorian (2007) or Dowd (2002)
N l di t ib ti i C i h Fi h
• Non-normal distribution using Cornish-Fisher expansion
S B d P d C (2008) "E i i
– See Boudt, Peterson and Croux (2008) "Estimation and Decomposition of Downside Risk for
Portfolios with Non Normal Returns " Journal of
Portfolios with Non-Normal Returns, Journal of Risk and implementation in PerformanceAnalytics
Risk Budgeting: Simulation
Risk Budgeting: Simulation
1
{ }M simulated returns
it t
R = = M
Method 1: Brute Force
,i , ,i i i VaR ES mVaR mES w w α α α α Δ Δ ≈ = Δ i Δ i
Method 2: Average Rit around values for which Rpt = VaR VaRα , , : : , i it i it t R VaR t R VaR mVaRα R mESα R ε = ± ≤ ≈ −
∑
≈ −∑
: pt : pt t R =VaRα±ε t R ≤VaRαR Functions for Factor Model Risk
Analysis
Function Function factorModelCovariance normalES factorModelRiskDecomposition normalPortfolioES normalVaR normalMarginalES normalVaR normalMarginalES normalPortfolioVaR normalComponentES normalMarginalVaR modifiedES normalComponentVaR modifiedPortfolioES normalVaRreport modifiedESreport modifiedVaR simulatedMarginalVaR modifiedPortfolioVaR simulatedComponentVaR modifiedMarginalVaR simulatedMarginalES modifiedComponentVaR simulatedComponentES modifiedComponentVaR simulatedComponentESUnequal Histories
Unequal Histories
Risk factors Fund performance
1,T , , k T,
F … F R1,T
Risk factors Fund performance
, n T R 1,T Ti , , k T, Ti F − … F − 1 1,T T R − R 1,1, , k ,1 F … F , n n T T R −
Example Portfolio: Unequal Histories of Individual Funds X 165939 0 .0 4 0 .0 0 X 104314 -0.0 5 0 .0 0 0 .0 5 -0 .0 8 -0 0 .0 0 .1 -0.1 5 -0. 10 00 X 29554 0 .3 -0 .2 -0 .1 0 X 153684 08 -0 .0 4 0 .00 -0 0 0. 02 0. 04 6 9 -0 .0 0. 02 4 5 -0 .0 4 0 .0 0 X 1131 6 -0 .0 6 -0. 02 X 1561 4 1998 2000 2002 2004 2006 2008 1998 2000 2002 2004 2006 2008
Implication of Unequal Histories
Implication of Unequal Histories
• Can’t fit factor models to some fundsCan t fit factor models to some funds
– Need to create proxy factor model
St ti ti hi t i (t t d d t )
• Statistics on common histories (truncated data) may be unreliable
• Difficult to compute non-normal tail risk measures
Extract Data from Database
Analysis and Reporting Flow Process Database E l Flow Process Excel Spreadsheets xlsReadWrite
R: Fit factor models R data files
Excel R: Simulation, portfolio
RODBC
RODBC
Spreadsheets calculations, risk analysis
S ffi i
Factor Model Construction
Sufficient
history? No
Yes
Fit factor model :
Variable selection: leaps, MASS
Collinearity diagnostics: car
d i i d l
Create proxy factor model from models with sufficient history dynamic regression: dynlm
Evaluation of Fitted Factor Models
Evaluation of Fitted Factor Models
• Graphical diagnosticsGraphical diagnostics
– Created plot method appropriate for time series regression
regression.
• Stability analysis
CUSUM t t h
– CUSUM etc: strucchange
– Rolling analysis: rollapply (zoo)
Ti i dl
– Time varying parameters: dlm
• Dynamic effects
Diagnostic Plots: Example Fund
0. 02 p , 0. 00 c e 4 -0 .0 2 n th ly p e rfo rm an c -0. 06 -0 .0 4 M o n -0 .0 8 -2005 2006 2007 2008 2009 Actual Fitted 2005 2006 2007 2008 20090 .6 0. 8 1 .0 60
Time Series Regression Residual diagnostics
AC F -0 .2 0 .0 0 .2 0 .4 0 1. 0 De n s it y 30 40 50 PA CF -0 .2 0 .0 0 .2 0 .4 0 .6 0 .8 01 0 2 0 Lag 5 10 15 Returns -0.04 -0.02 0.00 0.02
OLS-based CUSUM test
1. 5 .02 u at io n pro c es s 0 0. 5 1 .0 a l Q uant il es 0. 0 0 0 . Em pi ri c a l f luc tu -1 .0 -0.5 0. 0 Em p ir ic a -0 .0 4 -0. 02
24-month rolling estimates (I n te rc ept ) 0. 000 0. 004 X 144887 0 .0 5 0. 15 ( -0 .004 0. 25 -0 .0 5 0 0 .3 X 144874 0. 05 0. 15 0. 1 0 .2 0 X 144911 -0 .0 5 -0 .1 0 .0 7 5 0. 0 2007 2008 2009 Index -0 .4 -0 .3 -0 .2 X 1448 7 2007 2008 2009
Dealing with Unequal Histories
Dealing with Unequal Histories
• Estimate conditional distribution ofEstimate conditional distribution of RRi givengiven FF
– Fitted factor model or proxy factor model
E ti t i l di t ib ti f F
• Estimate marginal distribution of F
– Empirical distribution, multivariate normal, copula
• Derive marginal distribution of Ri from p(Ri|F)
and p(F)
• Simulate Ri and Calculate functional of interest
Simulation Algorithm
Simulation Algorithm
• DrawDraw by resampling from the
{
F1 F M}
by resampling from theempirical distribution of F.
• For each (u = 1 M) draw a value
{
F1, ,… F M}
F R
• For each (u = 1, …, M), draw a value
from the estimated conditional distribution of
R given F= (e g from fitted factor model
u
F Ri u,
F
Ri given F= (e.g., from fitted factor model
assuming normal errors)
i h d i d l f R
u
F
{ }
MR
• is the desired sample for Ri
• M ≈ 5000
{ }
, 1 i u u R =What to do with
{ }
,?
M i u
R
What to do with ?
• Backfill missing fund performance
{ }
,1
i u
u=
Backfill missing fund performance
• Compute fund and portfolio performance measures
measures
• Estimate non-parametric fund and portfolio tail i k
risk measures
• Compute non-parametric risk budgeting measures
• Standard errors can be computed using a p g
Example: Backfilled Fund Performance 0. 05 0 .0 0 0 -0 .0 5 1998 2000 2002 2004 2006 1998 2000 2002 2004 2006
Example: Simulated portfolio distribution
60 % Mo d V a R 99% VaR 40 50 99 % D ens it y 30 40 1 02 0 0 1 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04S-PLUS and S+FinMetrics vs R
S PLUS and S+FinMetrics vs R
• Dealing with time series objects in R can beDealing with time series objects in R can be difficult and confusing
timeSeries zoo xts – timeSeries, zoo, xts
• Time series regression in R is incompletely
i l t d
implemented
– Diagnostic plots, prediction
• R packages give about 80% functional coverage to S+FinMetrics
Some Thoughts About Using R in a
C
i
Corporate Environment
• IT doesn’t want to support itIT doesn t want to support it • Firewalls block R downloads
h ld f l d h
• The world runs from an Excel spreadsheet
• Analysts with some programming experience learn R quickly
References
References
• Boudt, K., B. Peterson and C. Croux (2008) "Estimation and , , ( ) Decomposition of Downside Risk for Portfolios with Non-Normal Returns," Journal of Risk
D d K (2002) M i M k Ri k J h Wil d • Dowd, K. (2002), Measuring Market Risk, John Wiley and
Sons
• Goodworth, T. and C. Jones (2007). “Factor-based, Non-Goodwo t , . a d C. Jo es ( 007). acto based, No parametric Risk Measurement Framework for Hedge Funds and Fund-of-Funds,” The European Journal of Finance.
H ll b k J (2003) “D i P f li V l Ri k • Hallerback, J. (2003). “Decomposing Portfolio Value-at-Risk:
A General Analysis”, The Journal of Risk 5/2.
References
References
• Jiang, Y. (2009). g, ( ) Overcoming Data Challenges in Fund-of-g g f Funds Portfolio Management, PhD Thesis, Department of Statistics, University of Washington.
L A (2007) H d F d A A l i P i • Lo, A. (2007). Hedge Funds: An Analytic Perspective,
Princeton.
• Yamai, Y. and T. Yoshiba (2002). “Comparative Analyses of a a , . a d . os ba ( 00 ). Co pa at ve a yses o Expected Shortfall and Value-at-Risk: Their Estimation Error, Decomposition, and Optimization, Institute for Monetary and Economic Studies Bank of Japan