Stock Portfolio Optimisation
(Final year project)
Under supervision of
Prof. Maheshwari Tripathi
Dr. Promila Bahadur
Presented By : Group - 21
Yashraj Singh Bhadauria (1805210066)
Umang Dubey (1805210060)
Vivek Bhardwaj (1805210063)
Stock Portfolio
Optimization
Optimizing Portfolio returns using Statistics &
Computers Science.
The Problem
Creating Portfolio is a very critically aspect of
investment management. Even after active
Problem research and multiple mathematical
frameworks
Small investors aren’t able to decide
How to allocate M how much to allocate to each asset in
amount of money into N order to improve on the returns per
assets ? unit risk.
What investors Principle : Diversification of assets
do today ● Identify Potential Stocks
● Allocate stocks by Human Understanding
● Volatility estimation mostly ignored
● Leads to Risky Portfolio
● Results in Average returns/ Losses
Solution
Solution
Diagram
Prerequisite
Expected Returns of assets :
● Percent returns given by each of the assets
● Arr => [ return(i) | i < N ]
● Come up with estimates, for example by extrapolating historical data.
● Expected Portfolio returns : where Ri is the return on asset i and and wi is the
weighting of component asset i.
Prerequisite
Risk Model (Covariance Matrix) :
● Formula
where μ corresponds to the average return
and ri corresponds to return on i-th day.
● Portfolio return variance
● Portfolio Return Volatility (Risk)
Modern Portfolio Theory[5]
● Basic Idea : Classical Mean-Variance
Optimizer (Efficient Frontier)[4]
○ Input ← (Expected Returns , Risk model)
○ Output → Optimal Weights distribution.
● Maximize Sharpe Ratio among portfolios on
efficient frontier
○ Slope of capital allocation line
● Dr. Harry Markowitz (1952)
○ 1990 Nobel Memorial Prize in Economic
Sciences
[EXTENSION] Black-Litterman - Allocation Inputs from investor → Improves Expected
Returns
Use Semantic Analysis on twitter/investment forums in order to estimate drops/increase in
stocks → input to Black-Litterman Allocation
Risk Parity[4]
● Basic Idea : Design a Portfolio such that the
risk is equally distributed among asset.
● Volatility is the measure of risk, the volatility
of each asset is expected to be 1/len(assets)
● Multiple ways to formulate the problem, one
below
○ Iterative Algorithm (No. of Iterations ∝
closer to optimal)
○ Start with equal weighted portfolio
(Each asset ←Budget/len(assets) )
○ Each iteration reduce weights of assets
with high risk ratings and increase
weights of low risk ratings using a
predefined convergence speed.
Hierarchical Risk Parity (HRP)[2],[3]
● Basic Idea : Exploit the intrinsic hierarchy of the correlation matrix.
● This algorithm was proposed by Lopez de Prado in 2016.
● Stage 1: Tree Clustering
○ Build a distance matrix ← Correlation Matrix where, 𝑑(𝑖,𝑗) = √ 1 / 2 (1 − 𝜌 (𝑖,𝑗) )
○ Build euclidian distance matrix D*(i,j) = sqrt( summation ( d(k,i) ^ 2 - d(k,j) ^ 2 ) for all k)
○ Followed by clustering using some heuristic over Euclidean distance
● Stage 2: Quasi Diagonalisation (using clusters created above)
○ Reorganizes rows & cols of covariance matrix → largest values lie along the diagonal.
○ Renders property: Similar investments ←→ together ; dissimilar ←→ far apart.
● Stage 3: Recursive Bisection (Bottom Up and Top Down)
○ Distribute the allocation through recursive bisection based on cluster covariance.
Hierarchical Risk Parity (HRP)[2],[3]
Clustering in HRP produces a tree like
structure where similar assets come
closer to each other in the
Hierarchical structure.
Dendrogram on right presents how
assets would be allocated in a top
down fashion splitting into two parts
at each section
Monte Carlo Simulation[1]
Why & What ?
● A fit-all solution doesn’t exist.
○ Although mathematically correct, CLA is known to be a poor estimator of the optimal
solution out-of-sample.
● System with 𝑁 random variables, where the expected value of draws → 𝜇, and the variance of
these draws → 𝑉 ,the covariance matrix. Calculate → ⍵
● The input variables 𝑉 and 𝜇 are typically unknown.
● Lead to unstable solutions
○ solutions where a small change in the inputs →extreme changes in 𝜔̂.
Monte Carlo Simulation[1]
How ?
● Derives the simulated pair {𝜇̂, 𝑉̂ } from original {𝜇, 𝑉}.
● De-noise the covariance matrix .
● Estimate 𝜔̂ ∗ from {𝜇̂,𝑉̂ } according to various alternative methods. (Here - Markowitz , Risk
Parity , Hierarchical Risk Parity)
● Combine all previous steps into a Monte Carlo experiment, whereby optimal allocations 𝜔̂ ∗
are computed on a large number of simulated pairs {𝜇̂,𝑉̂ }
● Computes the true optimal allocation 𝜔 ∗ from the pair {𝜇, 𝑉}, and compares that result with
the estimated 𝜔̂ ∗ .
○ computes the standard deviation of the differences between 𝜔̂ ∗ and 𝜔 ∗
● Pick the method which suits best.
Analysis performed Portfolio : [ VZ,CMCSA,AMT,ES,EIX,TSN,GLPI,WMT,GBX]
Analysis Month : 05/2020
Amount to invest : $10,000
Expected Outcome Variance Error
Error estimate Estimate
Analysis performed Allocate w.r.t HRP.
1. Annualized mean
return by HRP :
14.84%
2. Annualized mean
return by Markowitz :
14.05%
3. Annualized mean
return by Risk Parity :
14.18%
Analysis performed
Watching how different
strategies work over a
period of 2 years after
analysis is performed.
Methodology & Technology to be used
● Optimization based on
○ Modern Portfolio Theory
○ Risk Parity
○ Hierarchical Risk Parity
● Analysis
○ Risk Analysis : Covariance between stocks , etc
○ Portfolio Forecast : Mean, Weighted mean, etc
○ Monte Carlo Simulation.
● Python for analysis
● Modules : pandas, numpy, matplotlib, seabourn, scikit-learn, PyPortfolioOpt , mcos
● Flask for development of server.
● HTML/CSS & Javascript for UI development.
Questions?
References
1. López de Prado, Marcos and López de Prado, Marcos, A Robust Estimator of the Efficient Frontier (October 15, 2016).
Available at SSRN: https://ssrn.com/abstract=3469961 or http://dx.doi.org/10.2139/ssrn.3469961
2. Johann Pfitzinger & Nico Katzke, 2019. "A constrained hierarchical risk parity algorithm with cluster-based capital
allocation," Working Papers 14/2019, Stellenbosch University, Department of Economics.
3. López de Prado, Marcos and López de Prado, Marcos, Building Diversified Portfolios that Outperform Out-of-Sample
(May 23, 2016). Journal of Portfolio Management, 2016; https://doi.org/10.3905/jpm.2016.42.4.059. , Available at
SSRN: https://ssrn.com/abstract=2708678 or http://dx.doi.org/10.2139/ssrn.2708678
4. Dalio, R., 2005. Engineering targeted returns and risks. Alpha Manager.
5. Markowitz, Harry. “Portfolio Selection.” The Journal of Finance, vol. 7, no. 1, [American Finance Association, Wiley], 1952,
pp. 77–91, https://doi.org/10.2307/2975974.
6. Costa, Giorgio, and Roy H. Kwon. "Risk parity portfolio optimization under a markov regime-switching framework." Quantitative
Finance 19.3 (2019): 453-471.
7. Gambeta, Vaughn, and Roy Kwon. "Risk return trade-off in relaxed risk parity portfolio optimization." Journal of Risk and
Financial Management 13.10 (2020): 237.
8. Ivanova, Miroslava, and Lilko Dospatliev. "Application of Markowitz portfolio optimization on Bulgarian stock market from 2013
to 2016." International Journal of Pure and Applied Mathematics 117.2 (2017): 291-307.
9. Tola, Vincenzo, et al. "Cluster analysis for portfolio optimization." Journal of Economic Dynamics and Control 32.1 (2008):
235-258.
10. Michaud, Richard O., and Robert Michaud. "Estimation error and portfolio optimization: a resampling solution." Available at
SSRN 2658657 (2007).