0% found this document useful (0 votes)
3 views32 pages

Portfolio Optimization

The document discusses portfolio optimization, explaining the concept of a portfolio as a combination of securities defined by weights that sum to 1. It covers the calculation of portfolio weights, expected returns, and risk metrics, including variance and standard deviation, while also introducing tools and methods in R for analyzing portfolio performance. Additionally, it touches on concepts like Value at Risk (VaR) and Conditional Value at Risk (cVaR) for assessing potential losses in investment portfolios.

Uploaded by

aryaman.negi.11
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)
3 views32 pages

Portfolio Optimization

The document discusses portfolio optimization, explaining the concept of a portfolio as a combination of securities defined by weights that sum to 1. It covers the calculation of portfolio weights, expected returns, and risk metrics, including variance and standard deviation, while also introducing tools and methods in R for analyzing portfolio performance. Additionally, it touches on concepts like Value at Risk (VaR) and Conditional Value at Risk (cVaR) for assessing potential losses in investment portfolios.

Uploaded by

aryaman.negi.11
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
You are on page 1/ 32

Portfolio Optimization

Motivation
What is a Portfolio and why is it useful?
• A portfolio is a specific combination of securities, usually defined by portfolio weights
that sum to 1.
• 𝜔 = 𝜔1 , 𝜔2 , 𝜔3 … … 𝜔𝑛
• If 𝑁𝑖 is the number of shares of an asset and 𝑃𝑖 is the price of the share of the same
asset
𝑁 𝑖 𝑃𝑖
• 𝜔𝑖 = , where 𝑁𝑖 is the real number which can be negative
𝑁1 𝑃1 +⋯………+𝑁𝑛 𝑃𝑛

• 1 = 𝜔1 + 𝜔2 + 𝜔3 … … + 𝜔𝑛
• Portfolio weights can sum to 0 (dollar-neutral portfolios) and weights can be positive
or negative.
• Portfolio weights summarize all relevant information
Positions
• 𝑁𝑖 is the real number which can be negative
• This implies that some weights are negative and others are more than
1
• What do you mean by weights more than 1.
• You are buying more than what you can own? Someone is loaning you
a stock.
• Weights can sum to zero is more complex.
Motivation
• Example:
• Your investment account of 1,00,000 consists of three stocks: 200
shares of stock A, 1000 shares of stock B, 750 shares of stock C. Your
portfolio is summarized by the following weights:

Asset Shares Price/share Investment Portfolio weight

A 200 50 10,000 10%

B 1000 60 60,000 60%

C 750 40 30,000 30%

Total 1,00,000 100%


Example
Stock Prices • Suppose we have monthly closing price
Month Stock A Stock B data for 12 months on two shares
0 25 45
1 24.12 44.85 • We calculate the monthly return for each
2 23.37 46.88 stock
3 24.75 45.25
𝑃𝐴𝑡
4 26.62 50.87 • 𝑟𝐴𝑡 = ln
5 26.5 53.25
𝑃𝐴,𝑡−1
6 28 53.25 • Had the stock paid a dividend in month t
7 28.88 62.75 𝑃𝐴𝑡 +𝐷𝑖𝑣𝑡
8 29.75 65.5 • 𝑟𝐴𝑡 = ln
𝑃𝐴,𝑡−1
9 31.38 66.87
10 36.25 78.5
11 37.13 78
12 36.88 68.23
Portfolio
Stock A Return A Stock B Return B portfolio • 𝐸𝑥𝑝𝑒𝑐𝑡𝑒𝑑 𝑃𝑜𝑟𝑡𝑓𝑜𝑙𝑖𝑜 𝑟𝑒𝑡𝑢𝑟𝑛𝑠 = 𝐸 𝑟𝑝 = 0.5𝐸 𝑟𝐴 + 0.5𝐸 𝑟𝐵
25 45 W=0.5
24.12 -3.58% 44.85 -0.33% -1.959%
23.37 -3.16% 46.88 4.43% 0.634% 𝐸 𝑟𝑝 = 0.5 ∗ 3.24% + 0.5 ∗ 3.47% = 3.35%
24.75 5.74% 45.25 -3.54% 1.099%
26.62 7.28% 50.87 11.71% 9.495% • 𝐸 𝑟𝑝 = 𝜔𝐸 𝑟𝐴 + 1 − 𝜔 𝐸 𝑟𝐵
26.5 -0.45% 53.25 4.57% 2.060%
28 5.51% 53.25 0.00% 2.753% • 𝑉𝑎𝑟 𝑟𝑝 = 𝜔2 𝑉𝑎𝑟 𝑟𝐴 + 1 − 𝜔 2 𝑉𝑎𝑟 𝑟𝐵 + 2𝜔 1 − 𝜔 𝐶𝑜𝑣 𝑟𝐴 , 𝑟𝐵
28.88 3.09% 62.75 16.42% 9.755%
29.75 2.97% 65.5 4.29% 3.629% • 𝜎𝑝2 = 𝜔2 𝜎𝐴2 + 1 − 𝜔 2 𝜎𝐵2 + 2𝜔 1 − 𝜔 𝜌𝐴𝐵 𝜎𝐴 𝜎𝐵
31.38 5.33% 66.87 2.07% 3.702%
36.25 14.43% 78.5 16.03% 15.231%
37.13 2.40% 78 -0.64% 0.880%
36.88 -0.68% 68.23 -13.38% -7.029%
Monthly mean 3.24% Monthly Mean 3.47% Mean 3.354%

Monthly variance 0.23% Monthly Variance 0.65% Variance 0.314%


Monthly stand Monthly stand
dev 4.78% dev 8.03% Stdev 5.60%

Annual mean 38.879% Annual mean 41.622%


Annual variance 2.745% Annual variance 7.746%
Annual std dev 16.569% Annual std dev 27.832%
Efficient Frontier
5.60% 3.354% 3.50% return
sigma return
0 8.034% 3.47% 3.45% return
0.075 7.616% 3.45%
0.15 7.212% 3.43% 3.40%
0.225 6.825% 3.42%
0.3 6.457% 3.40% 3.35%
0.375 6.113% 3.38%
0.45 5.796% 3.37% 3.30%
0.525 5.511% 3.35%
0.6 5.264% 3.33% 3.25%
0.675 5.060% 3.31%
0.75 4.904% 3.30% 3.20%
0.825 4.801% 3.28%
0.9 4.755% 3.26% 3.15%
0.975 4.766% 3.25%
1.05 4.836% 3.23% 3.10%
1.125 4.960% 3.21%
1.2 5.136% 3.19% 3.05%
1.275 5.358% 3.18% 0.000% 1.000% 2.000% 3.000% 4.000% 5.000% 6.000% 7.000% 8.000% 9.000%
1.35 5.621% 3.16%
1.425 5.919% 3.14%
1.5 6.247% 3.13%
1.575 6.601% 3.11%
General Case
𝜔1
𝜔2
𝜔3
• Ω= . ➔ ΩT = [𝜔1 , 𝜔2 , 𝜔3 … … , 𝜔𝑁 ]
.
𝜔𝑁

• 𝐸 𝑟𝑝 = σ𝑁
𝑖=1 𝜔𝑖 𝐸(𝑟𝑖 )
𝐸 𝑟1
𝐸 𝑟2
• 𝐸 𝑟 = 𝐸 𝑟
.3 ➔𝐸 𝑟 𝑇
= [𝐸 𝑟1 , 𝐸 𝑟2 , 𝐸 𝑟3 … . . 𝐸 𝑟𝑁 ]
.
𝐸 𝑟𝑁

• 𝐸 𝑟𝑝 = σ𝑁 T 𝑇
𝑖=1 𝜔𝑖 𝐸 𝑟𝑖 = Ω 𝐸 𝑟 = 𝐸 𝑟 Ω

• 𝑉𝑎𝑟 𝑟𝑝 = σ𝑁
𝑖=1(𝜔𝑖 )
Three Universes
Three universes or paradigms for portfolio analysis with
R. xts
1. The tidyverse is a collection of R packages for doing
data science in a certain way. The package is called • EXTENSIBLE
so because TIME SERIES
(1) each variable has its own column (2) each
observation is a row (3) each value is a cell
2. An xts object is a matrix, that also, always, has a time
index for the order of the data. It holds a time series,
meaning it holds the observations and the times at
which they occurred.
3. tidyquant: This universe takes a lot of the best
features of xts, PerformanceAnalytics and the tidyquant tidyverse
tidyverse and lets them play well together.
PerformanceAnalytics
• In the xts world, there are two crucial packages that we will use:
quantmod and PerformanceAnalytics. quantmod is how we will
access the internet and pull in pricing data. That data will arrive to us
formatted as an xts object.
• It has several useful functions for analyzing portfolio performance in
an xts object, such as StdDev(), SharpeRatio(), SortinoRatio(),
CAPM.Beta().
#install.packages("gapminder")
############TO SHOW THE PIPING############
Pipe function library(gapminder)
head(gapminder)

####The first method###########


• Piping when compared with filter(select(gapminder, country, lifeExp,
Filtering gdpPercap), country=="Kenya")
• Here is what our chaining/ ####The PIPE#############
gapminder %>%
piping command says: select(country, lifeExp, gdpPercap) %>%
• Take the gapminder data filter(country=="Kenya")
• Select the variables country, lifeExp,
gdpPercap
• Keep info from Kenya
The spread function
Downloading data
• Lets select a few stocks library(tidyquant) # To download the data
to build our portfolios. library(tidyr)
library(plotly) # To create interactive charts
• We will choose the library(timetk) # To manipulate the data series
following 5 stocks
tickIndia<-c('INFY.NS','RELIANCE.NS','ICICIBANK.NS','SBIN.NS','ITC.NS’)
• INFY.NS
• RELIANCE.NS price_dataIndia <- tq_get(tickIndia,
• ICICIBANK.NS from = '2014-01-01',
to = '2021-12-31',
• SBIN.NS get = 'stock.prices’)
• ITC.NS
Estimating returns log_ret_tidy <- price_data %>%
group_by(symbol) %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
• Next we will calculate the period = 'daily',
daily returns for these col_rename = 'ret',
stocks. We will use the type = 'log')
head(log_ret_tidy)
logarithmic returns. log_ret_xts <-log_ret_tidy%>%
• data is in tidy format, we spread(symbol, value = ret) %>%
need to convert it into an tk_xts()
head(log_ret_xts)
xts format plot(log_ret_xts[,"ITC.NS"], main = "ITC", col =
• spread() function to "steelblue")
convert it to a wide format
mean_ret <- colMeans(log_ret_xts)
• will also convert it into a print(round(mean_ret, 5))
time series object using
xts() cov_mat <- cov(log_ret_xts) * 252
print(round(cov_mat,4))
Covariance matrix
• We apply our methods to thousands of cov_mat_India <-
random portfolio, let us demonstrate cov(log_retIndia_xts) * 252
the steps on a single portfolio. print(round(cov_mat_India,4))
• To calculate the portfolio returns and
risk (standard deviation) we will us wts <- runif(n = length(tick))
need print(wts)
• Mean assets returns
• Portfolio weights print(sum(wts))
• Covariance matrix of all assets
• Random weights wts <- wts/sum(wts)
print(wts)
• we will calculate the covariance matrix
for all these stocks. We will annualize it sum(wts)
by multiplying by 252
VaR and cVaR ####VaR is defined as the predicted worst-case loss with a
specific confidence
####level (for example, 95%) over a period of time (for
• I am X % certain there will not be a example, one day)
loss of more than V dollars in the
next N days. varRisk(logret3, weights = c(1, 1, 1)/3, alpha = 0.05)
• V= VaR= f(time N days, confidence cvarRisk(logret3, weights = c(1, 1, 1)/3, alpha = 0.05)
level X%)
• It is loss level over N days that has
a probability of only (100-X)% of
being exceeded.
• VaR is the loss corresponding to
(100-X)th percentiles of the
distribution of the change in value
of the portfolio over the next N
days.
• When N=5 and X=97, VaR is the 3rd
percentile of the distribution of
changes in the value of the portfolio
over the next 5 days

(100-x)% Gain or loss over N days


Example
Solution
In excel

NORM.S.INV(1%) = -2.32635 =-2.33

(100-99)% Gain or loss over N days


Practice
• Now consider a portfolio consisting of both Rs.1 crore of Maruti and
50 lakhs of TVS. We suppose that the returns on the two shares have
a bivariate normal distribution with a correlation of 0.3. Find the 10-
day 99% VaR for the portfolio consisting of both Maruti and TVS given
that the 𝜎𝑋 =2,00,000 and 𝜎𝑌 = 50,000.
• Estimate 𝜎𝑋+𝑌 = 𝜎𝑋2 + 𝜎𝑌2 + 2𝜌𝜎𝑋 𝜎𝑌 .
• 1-day 99% VaR is 𝜎𝑋+𝑌 × 2.33
• 10-day 99% VaR is 10 × 1𝑑𝑎𝑦 𝑉𝑎𝑅
cVaR
• While VaR represents a worst-case loss associated with a probability
and a time horizon, CVaR is the expected loss if that worst-case
threshold is ever crossed.
• Quantifies the expected losses that occur beyond the VaR breakpoint.
• It is the average of the values that fall beyond the VaR:
Common portfolios
• Global Minimum Variance (see Markowitz, 1952, 1956, 1991): Based on
Variance-Covariance
• Equal Risk Contributed (see Qian, 2005, 2006; Maillard et al., 2010; Qian,
2011): Based on variance-covariance, marginal risk contributions are
equated
• CVaR Contributed (see Boudt et al., 2010, 2011): Based on downside risk
measure, budgeting contributions to CVaR
• Most Diversified (see Choueifaty and Coignard, 2008; Choueifaty et al.,
2011): Based on (i) correlation matrix and (ii) re-scaling of weights
according to assets’ riskiness
• Optimal Tail Dependent: (i) Minimum tail dependent allocation, (ii)
Selection of portfolio constituents from a set of assets
library(PortfolioAnalytics)
Library(FRAPO)
Most common portfolios ######GLobal minimum variance portfolio###

p1<-PGMV(log_ret_xts,
1. Global Minimum Variance Portfolio percentage=FALSE,optctrl=ctrl())
p1
(PGMV from FRAPO) a<-Weights(p1)%*% cov(log_ret_xts)
2. Most Diversified Portfolio (PMD from a
t(Weights(p1))
FRAPO) varPGMV<-sum(Weights(p1)*a)
• Instead of using the variance-covariance
stdevPGMV<-sqrt(varPGMV)
matrix of the asset returns, the correlation stdevPGMV
matrix is utilized as dispersion measure #######Most diversified portfolio
• Weights are then recovered by rescaling
the optimal solution with the assets’ p2<-PMD(log_ret_xts,percentage=FALSE,optctrl=ctrl())
p2
standard deviations and normalizing such a<-Weights(p2)%*% cov(log_ret_xts)
that the weights sum to one. a
varPMD<-sum(Weights(p1)*a)
stdevPMD<-sqrt(varPMD)
stdevPMD
Maximize Diversification Ratio

> stdevPMD
[1] 0.01169978
> stdevPGMV
[1] 0.01167769

Lower Variance

σ𝑁
𝑖>𝑗 𝜔𝑖 𝜎𝑖
𝐷𝑅 𝑤 =
𝜔 ′ Σ𝜔
Minimum tail dependence portfolio
• Correlations are calculated in the tails only. Only in
the extreme cases or tails the correlations are
calculated
• Var-Covar matrix is not considered
EmpTC
• Pairwise tail dependent coefficients are considered Methods
• What is the tail? How many values of the tail are
taken?
EVT
• Tail = 𝑁
• Correlation between the worst 11 is considered. tdc(log_ret_xts, method="EmpTC",lower=TRUE)
• Estimated non-parametrically by either the cor(log_ret_xts)
empirical tail copula (method= EmpTC) or based
on the stable tail-dependence
function(method=“EVT”)
Most common portfolios
• Minimum tail dependent portfolio
(PMTD from FRAPO)
• Variance-Covariance matrix is replaced
with the matrix of the lower tail p3<-PMTD(log_ret_xts,method="EmpTC",
dependence coefficients percentage=FALSE,optctrl=ctrl())
• First step: Derive optimal solution if TDC- p3
matrix is used with main-diagonal
elements are set to one.
• Second step: Re-scale optimal weight
vectors by assets volatility (riskiness).
• Tail Dependent Coefficient (tdc)->
pairwise tail dependence coefficients
between N series
PMTD
• For a long-only investor, the minimum tail-dependent portfolio
solution is returned by calling PMTD(). The function body is akin to
that of the function PGMV() by which the solution of a global
minimum-variance portfolio is returned. But instead of employing the
variance-covariance matrix as a measure of dispersion, the TDC matrix
returned from the call to tdc() is utilized.
Diversification measures
Equal risk contributed portfolios (PERC)
• Equal risk contributed portfolio weights p5<-PERC(cov(log_ret_xts),percentage=TRUE,
• Objective function is the standard deviation of optctrl = ctrl())
the marginal risk contributions, which is a5<-Weights(p5)%*% cov(log_ret_xts)
minimal if all the contributions are equal. a5
• The solution of an equal risk contribution varPERC<-sum(Weights(p5)*a5)
portfolio can be determined with the function stdevPERC<-sqrt(varPERC)
PERC(). The function’s closure takes four stdevPERC
arguments: Sigma for the variance-covariance
matrix, par for the initial weight vector to be
used, percentage as a logical switch governing
whether the weights should be returned as
percentages (the default) or decimal figures,
and the argument optctrl which is passed
down to the rp() function of the package cccp
(see Pfaff 2015) in order to carry out the
optimization.
Comparing the GMVw <- Weights(PGMV(log_ret_xts))
MDPw <- Weights(PMD(log_ret_xts))
allocations MTDw <- Weights(PMTD(log_ret_xts))
ERCw<-Weights(p5)
• The allocations according to the
four portfolio optimizations are ## Graphical displays of allocations
then extracted by means of the oldpar <- par(no.readonly = TRUE)
Weights() method and assigned par(mfrow = c(2, 2))
to the objects GMVw, MDPw, dotchart(GMVw, xlim = c(0, 40), main = "GMV Allocation", pch
MTDw, and ERCw for the global- = 19)
minimum variance, most- dotchart(MDPw - GMVw, xlim = c(-20, 20), main = "MDP vs.
diversified, minimum tail-
dependent, and equal-risk GMV", pch = 19)
contributed solutions, abline(v = 0, col = "gray")
respectively. The weights are dotchart(MTDw - GMVw, xlim = c(-20, 20), main = "MTD vs.
then collected in the matrix GMV", pch = 19)
object W. This object is then abline(v = 0, col = "gray")
used in the call to the apply() dotchart(ERCw - GMVw, xlim = c(-20, 20), main = "ERC vs.
function to determine the
marginal risk contributions for GMV", pch = 19)
each of the four optimal weight abline(v = 0, col = "gray")
vectors. par(oldpar)
GMV allocation
• The GMV solution is characterized by a dominant allocation in Infy
followed by ITC, Reliance, ICICI and SBI
This portfolio concentration is quite typical for GMV
approaches and governed by the low volatility of the
dominating firms.
Most Diversified Portfolio vs GMV

The relative allocation of the most-diversified portfolio is depicted here.


The biggest difference is a distinct underweight of ITC and Infy as compared to GMV.
ERC, MTD and
GMV
• Quite a different picture
emerges for the MTD and
ERC allocations.
• MTD gives more weight to
SBI and ICICI when
compared to GMV
• ERC also gives more
weight to SBI and ICICI
when compared to GMV
• All in all, the latter two
portfolio approaches
result in a more balanced
wealth allocation.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy