Portfoliopython: 1 Week 1 Section 1 - Fundamentals of Risk and Returns
Portfoliopython: 1 Week 1 Section 1 - Fundamentals of Risk and Returns
Pt+1 − Pt Pt+1
Rt,t+1 = = −1
Pt Pt
If dividends D have been paid out at t + 1, the formula above is for the price return. the total
return is given by:
Pt+1 + Dt,t+1 − Pt Pt+1 + Dt,t+1
Rt,t+1 = = −1
Pt Pt
((1 + 0.01)12 − 1)
1 X
N
2
σR = (Ri − R̄)2
N
i=1
1
1.2.2 Standard deviation
Standard deviation is the square root of the variance:
v
u
u1 X N
σR = t (Ri − R̄)2
N
i=1
Rp − Rf
SharpeRatio(P) =
σp
2
2 Week 1 Section 2 - Beyond the Gaussian case: extreme risk
estimates
2.1 Video: Deviations from normality
2.1.1 Skewness
Skewness is a measure of asymmetry of the distribution. If distribution has a negative skewness,
then the probability of getting an outcome below the mean is higher than the probability of an
outcome above the mean. The opposite is true for a positively skewed distribution.
2.1.2 Kurtosis
Kurtosis is a quantitative measure of the thickness of the fatness of the tail of in relation to that
of the Gaussian distribution. The Gaussian distribution has a kurtosis of 3, if the value is higher
it has a fat tail distribution.
n 2 (K − 3)2
JB = (S + )
6 4
3
2.2.3 CVaR - Conditional VaR
CVaR is the expected loss (as a positive number) beyond the VaR. See also Investopedia.
R V aR
x· fR (x)d(x)
CV aR = −E(R|R ≤ −V aR) = −∞
FR (−V aR)
fR is the return density function and FR is the cumulative probability distribution. CVar is nothing
more than the average of all those returns that are worse than the VaR.
Question: Consider the following sequence of monthly returns on a portfolio: -4%, +5%, +2%,
-7%, +1%, +0.5%, -2%, -1%, -2%, +5%. What is the 80% monthly CVaR for the portfolio?
Answer: Out of 10 monthly returns, the worst outcome is -7% and the second worst outcome is
-4%, so 8 out of 10 outcomes are better than -4%. The worst return after excluding the 20% worst
return, that is after excluding the two worst return, is therefore -2%. VaR is typically expressed as
a positive number so 2% is the 80% VaR. The CVaR is given by the average loss beyond the VaR,
that is $ -(-7%-4%)/2=5.5% $.
Pr(R ≤ µp + zα σp ) = α
Zα is the one-sided α-quantile of the standard normal distribution of the return, for example for
Zα =-1.65, the probability is ~5% to get below that α-value.
VaRα = −(µ + zα σ)
Question: Consider a portfolio with a +.5% monthly expected return and 4% monthly volatility.
What is the 95% monthly Gaussian VaR for the portfolio?
Answer: VaR = −(.5% − 1.65x4%) = 6.1%. (−6.1 or less is the absolute value range that will
occur in 5% of the cases for a normal distribution with µ = 0.5 and σ = 4.)
%load_ext autoreload
%autoreload 2
4
%matplotlib inline
import numpy as np
import seaborn as sns
import matplotlib as plt
from scipy import stats
import matplotlib.pyplot as plt
mu= 0.5
sigma=4
x5= -6.1
extend= 3
xx = np.arange(mu-extend*sigma, mu+extend*sigma, 0.1)
yy = stats.norm.pdf(xx,loc=mu,scale=sigma)
delta=0.000000001
xxx= xx[xx<= x5]
yyy= yy[xx<= x5]
5
The Gaussian distribution has thin tails and may underestimate risk. It is not a good model for
VaR.
Method 3: Parametric non-Gaussian VaR There are many parametric non-Gaussian distri-
butions:
• Define
• Pareto
• Student
• Loggamma
• Frechet
1 1 1
z̃α = zα + (zα2 − 1)S + (zα3 − 3zα )(K − 3) − (2zα3 − 5zα )S 2
6 24 36
6
[7]: <matplotlib.axes._subplots.AxesSubplot at 0x211f31beac8>
X
k
Rp = wi Ri
i=1
The expression for the portfolio variance σ 2 is a generalization of the formula we’ve already seen
in the 2-asset case:
X k X k
2
σp = wi wj σi σj ρij
i=1 j=1
7
X
k X
k
σp2 = wi wj σij
i=1 j=1
σp2 = wT Σw
8
The maximum Sharpe ratio portfolio (MSR) is at the point where the orange line that starts at the
risk-free rate (here generously set at 12%) touches the efficient frontier. The slope of the orange
line is the Sharpe ratio of the portfolio.
The MSR portfolio contains no exposure to specific risk. This type of risk is unrewarded because
it can be diversified away.
The tangency portfolio is the portfolio that maximizes the Sharpe ratio.
PN
µp − rf i=1 wi µi − rf
SRp = = qP
σp N
ww σ
i,j=1 i j ij
9
4.2.2 Global minimum variance (GMV) portfolio
The GMV is the portfolio that is least sensitive to errors in parameter estimates. Since it requires
no expected return estimates, it is only sensitive to errors in risk parameter estimates. The asset
weights of the maximum Sharpe ratio portfolio vary a lot if the expected returns of the assets
change.
[9]: import pandas as pd
import edhec_risk_kit as erk
5 Week 3 Section 1 -
5.1 Video: Limits of diversification
Diversification allows you to most efficiently harvest the highest possible reward per unit of risk,
by eliminating unrewarded risks. diversification cannot help you deal with systematic risk: the risk
factor that impacts all the assets simultaneously.
10
5.1.1 Hedging
Hedging (i.e. avoiding risk taking) is the only effective way to obtain downside protection. Hedging
is symmetric, you get protection for downside risk, but give up on possible returns.
I explain the diagram in a different way than the Coursera/EDHEC video does:
• T is the total amount of assets that you have
• Protection Floor F is the level of assets that you want to protect against downside risk
• The difference between total assets T and the desired protection floor F is called cushion
C =T −F
11
• The amount of risky asset E you take on is E = M ∗ C, where M is a (yet undetermined)
multiplier
• The rest is put in a riskless asset B = T − E
If the risky asset E loses value, the cushion C becomes smaller and the risky asset must be replaced
with riskless asset. E = M ∗ C must hold. If the cushion becomes zero, only riskless asset remains.
Example:
• M =3
• F = 80%
• T = 100$
What is the value of E? C = T − F = 100 − 80 = 20. The initial investment in risky asset E is
E = M ∗ C = 3 ∗ 20 = 60.
12
• F : floor (a minimum amount of wealth to protect)
• C: cap (a maximum (!) amount of wealth to protect)
• A: asset value
• E: the amount of risky asset that you take on
• m: CPPI multiplier
• T : threshold level where downside protection switches to upside protection, determined by F
and C.
Question: What is the initial allocation to the risky asset for a portfolio starting at $100, with a
multiplier equal to 4, a wealth preservation floor set at 90% and a cap set at 105%?
Answer: A = 100 M = 4 F = 90% C = 105% The portfolio initial value is closer to the cap
than it is to the floor. In this case, the investment in risky asset is 4 ∗ (105% − 100%) = 20%.
Threshold level of the asset value A = T where downside proection switches to upside protection
is determined by:
Ft + Ct
m(Tt − Ft ) = m(Ct − Tt ) → Tt =
2
Question: Consider a portfolio starting at $100, with a multiplier equal to 4, a wealth preservation
floor set at 90% and a cap set at 105%. What is the threshold value beyond which the allocation
to risky asset is computed with respect to the cap, and not to the floor?
Answer: A = 100 M =4 F = 90% C = 105%
100+95
T = 2 = 97.5%
13
• σdWt the stocastic component: volatility σ times dWt , the Brownian motion process.
• dB
Bt = rdt: is the return fraction of the riskfree asset. It is the riskfree rate r times the period
t
dt.
• B0 : the value of B at time zero(?).
Question: Assume that a stock index has a Sharpe ratio of 0.5 and a volatility of 20%? If the
risk-free rate is 2%, what is the drift of the stock index return process?
Answer: λ = 0.5, σ = 0.2 and r = 0.02. dSt
St = 0.02 + 0.2 ∗ 0.5 = 0.12
St+dt − St √
= (r + σλ)dt + σ dtξt
St
S −S
• t+dtSt
t
= dS
St : the fractional change of return.
t
dSt Et [ dS
St ]
t
Et [ ] = µdt ⇒ =µ
St dt
dSt Vart [ dS
St ]
t
Vart [ ] = σ 2 dt ⇒ = σ2
St dt
• µ: annualized expected return
• σ 2 : annualized variance
14
6 Week 3 Section 2 -
6.1 Video: Monte Carlo simulation
6.1.1 A model with a stochastic opportunity set
All elements of the equation below depend on time. For example, the riskfree rate is not a constant
but is a stochastic process that can change over time: rt .
dSt p p
= (rt + Vt λSt )dt + Vt dWtS
St
dSt
• St : the return as a fraction of
the asset value
• r√t : the time dependent riskfree rate
• Vt = σt : the estimate of the time dependent volatility (sqrt of variance Vt ).
• λS : the estimate of the time dependent Sharpe ratio
√t √
• Vt dWtS the stocastic component: volatility σt = Vt times dWtS . The time dependent
Brownian motion process is represented by dWtS .
The change in riskfree rate drt and volatility dVt are modeled as stochastic processes.
p
dVt = α(V̄ − Vt )dt + σV Vt dWtV
• dVt : the change in variance
• α: the mean reverting speed of Vt
• V̄ : the mean of the variance
• Vt : √the current value of the variance
• σV Vt dWtr : the Brownian motion (≥ 0) for changes in variance
Question: Assuming a mean-reverting model for interest rates with long-term mean level equal
to 2%. If the current level of interest rate is 3% and if the speed of mean reversion is 0.5, what is
the average annual expected change in interest rate?
Answer: drt = a(b − rt )dt with b = 0.02, rt = 0.03, a = 0.5, dt = 1 ⇒ 0.5 ∗ (0.02 − 0.03) = −0.5%
15
Take a look at the Wikipedia page about Geometric Brownian Motion.
7 Week 4 Section 1 -
7.1 Video: From Asset Management to Asset-Liability Management
7.1.1 Funding ratio
In asset-liability management we measure the ratio between asset values and liability values.
Funding ratio measures the assets relative to the liabilities. If it is equal to 100%, it means that
assets are sufficient to cover liabilities.
At
Ft =
Lt
• Ft : funding ratio
• At : asset values
• Lt : liability values
7.1.2 Surplus
The surplus St is the difference between assets At and liability values Lt .
St = At − Lt
Question: Consider a pension fund that has a 50%-50% stock/bond allocation. Assume that
equity markets go down by 5%, bond markets go down by 10%, and further assume that the
liability value goes down by 8%. Is the funding ratio of the pension plan increasing or decreasing?
Answer: Change in return: (0.5 ∗ −5% + 0.5 ∗ −10%) = −7.5%. Change in liability value: −8%.
The funding ratio increases.
7.2 Video: Lab Session - Present Values, liabilities and funding ratio
This lab session video introduces some equations.
16
is flat, and so the interest rate is the same for all horizons. The present value of a set of liabilities
L is given by:
X
k
P V (L) = B(ti )Li
i=1
1
B(t) =
(1 + r)t
This means that after t years the bond (that now costs Bt ) will pay 1 dollar:
B(t)(1 + r)t = 1
17
7.3.2 Factor exposure matching
We would like bonds with payouts that match our liability payments. That would give perfect
cash-flow matching. This is not practical and we can use factor exposure matching instead.
Question: What is the safe liability-hedging asset for a 45Y old investor preparing for retirement
at age 65.
• 3 month T-Bills?
• 20-year inflation-linked pure discount bond?
• Deferred inflation-linked annuity with a 20 years deferral period?
Answer:
• 3 month T-Bills: This should not be selected If interest rates go down, the value of short-
term bonds will increase moderately, while the value of the long-dated liabilities, given by
replacement income, will increase significantly.
• 20-year inflation-linked pure discount bond: This should not be selected The 20-year pure
discount bond will pay a cash-flow when the investor reaches retirement at age 65, but the
investor needs to receive replacement income cash-flows throughout retirement, not at retire-
ment date.
• Deferred inflation-linked annuity with a 20 years deferral period?: A deferred inflation-linked
annuity with a 20 year deferral period will start paying cash flows when the investor reaches
age 65, and will pay replacement income cash-flow as long as the investor is alive. This make
it the perfect safe retirement asset.
These questions cannot be answered using the information learned in the lectures!
√
drt = a(b − rt ) dt + σ rt dWt
• drt : small change in interest rate
• a: the speed of reversion to the mean
• b: long term mean of the interest rate
• rt : current interest rate
• dt : a small amount of time
√
• σ rt dWt : random component
– σ: the volatility, which acts as a scaling factor
√
– rt : prevents negative interest rates
– dWt : a random normally distributed number (‘the shock’)
18
If we compound every 1/N part of a year we get:
r N
(1 + )
N
1 + rannual = erinst
rannual = erinst − 1
rinst = ln(1 + rannual )
• rannual : annualized interest rate
• rinst : instantaneous (or short) rate
• erinst : e to the power of the short rate
where
!2ab/σ2
2he(a+h)τ /2
A(t, T ) =
2h + (a + h)(eτ h − 1)
and
2(eτ h − 1)
B(t, T ) =
2h + (a + h)(eτ h − 1)
and
p
h= a2 + 2σ 2
and
τ =T −t
• P (t, T ): price at time t of a bond that matures at time T
So this is the evolution in price of a zero-coupon bond, as interest rates go up, the price of the bond
comes down. As interest rates falls, the price of the bond goes up.
19
7.5 Video: Liability-driven investing (LDI)
7.5.1 Greed and Fear
• Performance generation through optimal exposure to rewarded risk factors
• Hedging against unexpected shocks
Performance-seeking portfolio (PSP): focus on diversified efficient access to risk premia.
Liability-hedging portfolio (LHP): focus on hedging impact of risk factors in liabilities.
Pn t×C n×M
t=1 ( (1+y)t + (1+y)n
Macaulay duration =
Current bond price
• t: respective time period
• C: periodic coupon payment
20
• y: periodic yield
• n: total number of periods
• M : maturity value
• Current bond price: present value of cash flows
8 Week 4 Section 2 -
8.1 Video: Choosing the policy portfolio
8.1.1 Optimal asset mix
What is the optimal asset mix for liability driven investment (Section 7.6) when investing in the
two building blocks PSP and LHP (Section 7.5.1)?
The risk aversion parameter γ is the fraction of allocation to LHP/PSP.
In practice, the allocation to PSP is increased until the risk budget is exhausted. The risk budget
is set by the stakeholders.
8.1.2 Conflicts
There is a conflict between short-term and long-term perspectives. For the long term perspective
you want to reach your funding ratio. For the short perspective you want to look at the volatility
and the max drawdown (Section 1.3.1).
If the risk budget is small, there will not be much upside potential. This requires a large investment
to meet the liability.
21
Question: At a meeting of the board of trustees of a pension fund, it is decided that the acceptable
volatility of the funding ratio is increased from 8% to 10? What consequence should follow?
• An increase in the allocation to the PSP?
• A 10% increase in funding ratio?
• A 10% decrease in funding ratio?
• An increase in the allocation to the LHP?
Answer: An increase in the allocation to the PSP. Increasing the risk budget allows investors to
take on more risk.
22
8.3 Video: Liability-friendly equity portfolios
8.3.1 Liability friendliness
• cash-flow matching focus: choose stocks with high and stable dividends
• factor matching focus: choose stocks that may have a low tracking error with respect to the
liabilities: low volatility stocks
• isovariance portfolios: fill the risk budget upto the the allowed level with low volatility stocks.
23