---
title: portfolio management
tags: teach:MF
---
# Portfolio Management
## Agenda
1. Modern portfolio theory
2. Lab in pythons
5. Hw 5.
## Modern portfolio theory
#### A quick but brutal way :cat:
Portfolio management using hierarchical clustering

:heart: It is not sure if this is a good investment stratgy.
:heart: One way to conclude if through extensive backtest.
### [Harry Max Markowitz](https://en.wikipedia.org/wiki/Harry_Markowitz) :+1:

[Harry Max Markowitz](https://en.wikipedia.org/wiki/Harry_Markowitz) (born August 24, 1927) is an American economist and a recipient of the 1989 John von Neumann Theory Prize and the 1990 Nobel Memorial Prize in Economic Sciences (Wiki).
The Markowitz model is also called the *mean-variance model* because it is based on expected returns and the standard deviation of the various portfolios.
### Ultimate goal
We want to be *happy* in the *future*.
Suppose we are in a daily basis.
Suppose we have $n$ assets to invest.
We need to decide a *portfolio weight vector* for each asset at day $t_0$:
$$w = (w_1,\ldots,w_n)',$$
where the plum denotes vector or matrix transpose.
#### Future?
For future, we need to build a model for future returns,
$$R=(R_{1},\ldots,R_{n})'.$$
We possibly need to build future returns for a sequence of days.
#### Happy?
Let $\textbf{1}$ denote the one vector of size $n\times 1$.
For simplicity, suppose we invest 1 dollar at the initial time.
The future accumulative return is
$$F = w'(\textbf{1}+R) = (w_1+\cdots+w_n) + w_1 R_1+w_2R_2+\cdots w_nR_n. $$
For <font color="#f00">happiness</font>, we use a utility function (效用函數) to measure both happiness and fear. Happiness is related to the fortune, and is described by the utility function
$$U(F) = U( w'(1+R)) := U(R, w).$$
Utility function needs to be
1. Non-decreasing
2. Concave
#### What do we have?
Domain knowledge: finance, expert's views, insider information, etc.
With domain knowledge, we try to find out data:
1. Macro: GDP, unemployment rates, housing index, etc.
2. Micro: dividend theory, CAPM, APT, financial statements, anomalies, etc.
3. Historical returns and trading volumns
4. Technical analysis: RSI, etc.
Denote the data at day $t$,
$$x_t=(x_{t,1},x_{t,2},\ldots,x_{t,m})'$$for $t=1,\ldots, t_0$. Let $x = [x_{1}';x_2';\ldots,x_{t_0}']$ denote the available information till day $t_0$.
#### Reformulation
The portfolio management could be rewritten as a constrained optimization problem:
$$\max_{w \in A} E[U(w, R)|\mathcal{F}_{t_0}].$$
Here,
- $U$ is the utility function,
- $E[\cdot]$ is the expectation,
- $A$ is a possible set for $w$.
In other words, if we let $f(w) = E[U(w, R)|\mathcal{F}_{t_0}]$. We rewrite it as,
$$\max_{w \in A} f(w).$$
:::info
Optimization: maximizing or minimizing a function, mathematically.
|No |Topic | Example |
| --- |---|---|
|1 | Closed form solution | Ex. Global-minimum variance portfolio |
| 2| Numerical procedures | Ex. K-means algorithm |
| | | Ex. Stochastic gradient descent for deep neural networks |
:::
#### Return prediction
We build a *model* to predict the future return:
$$R = m(x; \theta)$$
where $\theta=(\theta_1,\ldots,\theta_k)$ is the parameter vector.
Two issues:
1. What to put as information $x$?
2. Which model $m(\dots;\cdot)$ to use?
- Statistical models (time series, panel data)
- machine learning
#### Constrains about $w$
The natural constrain on the weight: $$A=\{w\in\Re^n: \textbf{1}'{w}=1\}.$$
No short sales$$A=\{w\in \Re^n: w_i \geq 0, \textbf{1}'{w}=1\}.$$
No short sales, avoid small changes of portfolio weights to reduce transaction costs
$$A=\{w\in \Re^n: w_i \geq 0, w_i\geq \varepsilon, \textbf{1}'{w_i}=1\}.$$
## A simple illustration
We assume an $n$-dimensional normal distribution:
$$R\sim N_n(\mu,\Sigma),$$
where $\mu$ is the mean vector, and $\Sigma$ is the covariance matrix.
Note the normality is not a necessary assumption.
#### Notations
The portfolio return, is the random variable,
$$R_{p,w} = w'R.$$
The subscript ``$w$" indicates that the portfolio is constructed using the $w$-weights.
The expected return on the portfolio is
$$E[R_{p,w}] = w'\mu = w_1 \mu_1+ w_2 \mu_2+\cdots+w_n \mu_n,$$
and the variance of the portfolio return is
$$Var[R_{p,w}] = \sigma^2_{p,w} = w'\Sigma w = \sum_i \sum_j w_i w_j \Sigma_{i,j} .$$
The condition that the portfolio weights sum to one can be expressed as
$$\sum_{i=1}^n w_i = w'\textbf{1}=1, $$
where $\textbf{1}$ is a $n\times 1$ vector with each element equal to 1.
#### The global minimum variance portfolio
The global minimum variance portfolio $m=(m_1,\ldots,m_n)'$ for the $n$ asset case solves the constrained minimization problem:
$$\min_w w'\Sigma w,$$
such that $m'\textbf{1} = 1$.
The Lagrangian for this problem is
$$L(m,\lambda) = m'\Sigma m - \lambda(m'\textbf{1}-1)=0.$$
The first-order-condition is
\begin{eqnarray*}
\frac{\partial L(m,\lambda)}{\partial m} &= & 2\Sigma m + \lambda \textbf{1} = \textbf{0},\\
\frac{\partial L(m, \lambda)}{\partial \lambda} &=& m'\textbf{1} - 1 = 0.
\end{eqnarray*}
Solving these equations, we have the solution for $m$,
$$m = \frac{\Sigma^{-1}\textbf{1}}{\textbf{1}'\Sigma^{-1} \textbf{1}}.$$
### Issues?
#### Estimation risk
The optimal portfolio weight depends highly on the estimated return and risk of assets. How to deal with the estimation error?
#### Model risk
- A more sophisticated model
- Black-Litterman portfolio
- Stochastic dominance portfolio
### Backtest?
We need to implement a rolling-window approach.
### HW 5
1. JWHT, page 414, 4. (Hint: Only handwritting is needed. For easier grading to our TA, Ian, you can scan this solution and paste it with your other solutions in a single file.)
2. In this homework assignment, you will download the dataset on NewE3 “seeds_dataset” to solve the following problems.
The explanation of variables can find in the resource:http://archive.ics.uci.edu/ml/datasets/seeds
Analyze the data by the hierarchical clustering. Under which distance and linkage method does it produce clusters closest to the original classes?
3. Consider three stocks (Google, AAL, and Tesla) with prices from 2018/1/1 to 2021/10/1. Let $S_t$ denote the stock price at day $t$. The log-return at day $t$ is
$$r_t = \log\frac{S_t}{S_{t-1}}.$$
1. Show the time series plots historical prices of these three stocks.
2. Show the time series plots of log-returns of these three stocks.
3. Use the whole periods to summarize their expected returns and risk. Draw these three points on the 2D-plane.
4. Report the portfolio weight of the global-minimum portfolio.
4. Assume we have 100,000 USD. Follow 3 and perform a backtest:
1. Start with the first 60 days of return and calculate the portfolio weight of the global minimum portfolio. Report the portfolio weight and the number of shares to buy for each stock.
2. *A rolling-window backtest procedure*
[(Details)](https://docs.google.com/spreadsheets/d/1SEGhzMLycKQh425jmCKHCsiHKKfdKHXXMDCK0kjWinY/edit#gid=0): Hold a portfolio for the next 5 days. Roll the window to use the latest 60 dys of return and hold a portfolio for 5 days. Continue these steps till the end of the study period. Show the accumalative return of the global minium variance portfolio and compare it with the 1/3 portfolio. Hint: let $P_t$ denote the market value of the portfolio. The acccumulative return is calcuated as
$$accR_t = (\frac{P_t-P_0}{P_0})\times 100\%$$
---