FactorsRisk [UP]
FactorsRisk [UP]
FactorsRisk [UP]
Michael Ashby
28 February 2019
Last time
I Principal components:
I Implementation: https://programming-r-pro-bro.blogspot.
com/2011/10/principal-component-analysis-use.html
I Gory mathematical detail: http://www.cs.princeton.edu/
picasso/mats/PCA-Tutorial-Intuition_jp.pdf
I Risk/performance measures:
I Implementation: PerformanceAnalytics reference manual
I Information on expectiles: Information - https:
//getd.libs.uga.edu/pdfs/anderson_andrew_l_201212_ms.pdf
Principal components analysis (PCA)
Factor models
ri,t − rf ,t = αi + Ft βi + ei,t
I Fama-French: case where factors are known. We have a time
series for each one
I PCA: components not known, but extracted from the data
Idea of a factor model
Σr = βΣF β | + Σe
where (assuming there are K factors and N assets), ΣF is the
K × K covariance matrix of the factors F and
Σe = diag{σ12 , σ22 , . . . , σn2 }
I Even if we treat this as a statistical factor model (loadings
unknown, factors unknown), the RHS above will typically have
far fewer parameters to estimate (nK + K + K (K2+1) ) than the
LHS N(N+1)
2
I e.g. even for smallish N (N = 50) and K = 10 (large factor
model) we have 1275 parameters in LHS and only 565 in RHS
I This type of shrinkage may be helpful in terms of a
mean-variance problem
Extracting factors in theory
Σr = βΣF β > + Σe
has more parameters than RHS, we can’t uniquely identify β
and F
I We can, however, identify F and β up to a rotation
I So we choose a convenient rotation: we will make our factors
orthogonal to each other
I Question: if the factors are uncorrelated and the errors are
uncorrelated, how can the assets be correlated? Answer: . . .
Extracting factors by PCA
I Given that we have decided to make our factors orthogonal to
each other, we will use principal components on our returns
matrix R
I To do this, we will need to do an eigenvalue decomposition
(princomp() in R)
I This will give us N factors - not ideal!
I Luckily, the factors will be ordered by which one explains the
most variance
I We will first consider one factor, then two factors etc. Once
“enough” of the variance is explained, we can stop adding
factors
I We will come back to what is “enough” later
I Once we have the factors, we can estimate β and Σe (residual
vairances) by OLS time-series regressions (one for each asset)
as we did in the Fama-French case when the factors were
known (we treat the factors as known once we extract them)
Digression: in MLE, how to estimate Σe and β?
library(tidyverse)
library(reshape2)
library(lubridate)
library(tidyquant)
library(XLConnect)
library(XLConnectJars)
Extracting factors in R - data (DJIA)
prices=tq_index("dow") %>%
# complete_cases=TRUE gets rid of symbols returning
# NA due to error in get call (e.g. wrong symbol)
tq_get(get = "stock.prices", complete_cases = TRUE) %>%
# keep only variables listed inside select()
select(symbol, date, adjusted) %>%
# set cases as year, month and symbol
group_by(year(date), month(date), symbol) %>%
# for time-series variables, keep just the last
# observation of each month
summarize(adjusted = tail(adjusted, 1)) %>%
# make a date column with only years and months in
# for this new object
mutate(date = make_date(`year(date)`, `month(date)`)) %>%
#acast(data,id1~id2,value.var="x") returns a matrix
#of x where id1 describes the rows and id2 the cols
acast(date~symbol,value.var = "adjusted")
Extracting factors in R - eigendecomposition
I We need to remove NA values. We know how to do this from
last time. We also know that this particular dataset has no
missing values, so we keep going!
I It’s trivially easy to compute the PCA:
ret = diff(log(prices))
pca = princomp(ret)
summary(pca)
## Importance of components:
## Comp.1 Comp.2 Comp.3
## Standard deviation 0.2295718 0.09409044 0.08698306 0
## Proportion of Variance 0.4372084 0.07344167 0.06276549 0
## Cumulative Proportion 0.4372084 0.51065012 0.57341561 0
## Comp.5 Comp.6 Comp.7
plot(pca$sdev)
0.20
0.15
pca$sdev
0.10
0.05
0 5 10 15 20 25 30
Index
Extracting factors in R - how many factors?
f1 = rowSums(pca$loadings[1,]*ret)
library(PerformanceAnalytics)
pret = 0.4*ret[,1]+0.3*ret[,2]+0.2*ret[,3]+0.1*ret[,4]
Implementation in R II
I We’ll compute the Cornish-Fisher 95% VaR
VaR(R=pret,p=0.95,method=c("modified"))
## [,1]
## VaR -0.06957187
ES(R=pret,p=0.95,method=c("modified"))
## [,1]
## ES -0.09684417
## $MVaR
## [1] 0.0701611
##
## $contribution
## AAPL AXP BA CAT
## 0.030492149 0.012802774 0.019668320 0.007197861
##
## $pct_contrib_MVaR
## AAPL AXP BA CAT
## 0.4346019 0.1824768 0.2803308 0.1025905
Expectiles
n h io
eτ (L) = arg min E τ 1(L > `)(L − `)2 + (1 − τ )1(L < `)(L − `)2
`∈R
library(expectreg)
expectile(-pret,0.95)
## 0.95
## 0.0495
Implementation in R - theoretical expectile
mean(-pret)+ sd(-pret)*enorm(0.95)
## [1] 0.04947906
Performance measures
Performance measures
ra − rb /sd(ra − rb )
bench = 0.25*(ret[,1]+ret[,2]+ret[,3]+ret[,4])
InformationRatio(pret,bench)
## [1] 0.3761627
Sortino ratio
I Suppose an investor has a minimum acceptable return in mind
I Then we can compute the Sortino ratio which only penalises
variance in returns less than the MAR
I This is unlike the Sharpe ratio, which penalises both upside and
downside risk equally
r̄p − rMAR
SortR =
σd
v
u T
u 1 X
σd = t (rp,t − rMAR )2 1(rp,t < rMAR )
T − 1 t=1
I Very straightforward in R (we’ll set rMAR = 0)
SortinoRatio(pret)
## [,1]
## Sortino Ratio (MAR = 0%) 0.6195425
(Max) drawdown
I Drawdown at time t tells us how far below previous peak rp,t is
(and is 0 if above peak)
I We can get a whole time series of drawdowns for our return
series using
Drawdowns(pret)
maxDrawdown(pret)
## [1] 0.2691596
Calmar ratio
I The Calmar ratio gives the cumulative return over the whole
period ÷ max DD
I Surprise, surprise, we calculate it as
CalmarRatio(pret)
## [,1]
## Calmar Ratio 0.9360109
That’s all folks!