# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # <center>Financial Economics HW_03</center>
#
# **<center>11510691 程远星$\DeclareMathOperator*{\argmin}{argmin}
# \DeclareMathOperator*{\argmax}{argmax}
# \DeclareMathOperator*{\plim}{plim}
# \newcommand{\ffrac}{\displaystyle \frac}
# \newcommand{\d}[1]{\displaystyle{#1}}
# \newcommand{\space}{\text{ }}
# \newcommand{\bspace}{\;\;\;\;}
# \newcommand{\bbspace}{\;\;\;\;\;\;\;\;}
# \newcommand{\QQQ}{\boxed{?\:}}
# \newcommand{\void}{\left.\right.}
# \newcommand{\Tran}[1]{{#1}^{\mathrm{T}}}
# \newcommand{\CB}[1]{\left\{ #1 \right\}}
# \newcommand{\SB}[1]{\left[ #1 \right]}
# \newcommand{\P}[1]{\left( #1 \right)}
# \newcommand{\abs}[1]{\left| #1 \right|}
# \newcommand{\norm}[1]{\left\| #1 \right\|}
# \newcommand{\given}[1]{\left. #1 \right|}
# \newcommand{\using}[1]{\stackrel{\mathrm{#1}}{=}}
# \newcommand{\asim}{\overset{\text{a}}{\sim}}
# \newcommand{\RR}{\mathbb{R}}
# \newcommand{\EE}{\mathbb{E}}
# \newcommand{\II}{\mathbb{I}}
# \newcommand{\NN}{\mathbb{N}}
# \newcommand{\ZZ}{\mathbb{Z}}
# \newcommand{\QQ}{\mathbb{Q}}
# \newcommand{\PP}{\mathbb{P}}
# \newcommand{\AcA}{\mathcal{A}}
# \newcommand{\FcF}{\mathcal{F}}
# \newcommand{\AsA}{\mathscr{A}}
# \newcommand{\FsF}{\mathscr{F}}
# \newcommand{\dd}{\mathrm{d}}
# \newcommand{\I}[1]{\mathrm{I}\left( #1 \right)}
# \newcommand{\N}[1]{\mathcal{N}\left( #1 \right)}
# \newcommand{\Exp}[1]{\mathrm{E}\left[ #1 \right]}
# \newcommand{\Var}[1]{\mathrm{Var}\left[ #1 \right]}
# \newcommand{\Avar}[1]{\mathrm{Avar}\left[ #1 \right]}
# \newcommand{\Cov}[1]{\mathrm{Cov}\left( #1 \right)}
# \newcommand{\Corr}[1]{\mathrm{Corr}\left( #1 \right)}
# \newcommand{\ExpH}{\mathrm{E}}
# \newcommand{\VarH}{\mathrm{Var}}
# \newcommand{\AVarH}{\mathrm{Avar}}
# \newcommand{\CovH}{\mathrm{Cov}}
# \newcommand{\CorrH}{\mathrm{Corr}}
# \newcommand{\ow}{\text{otherwise}}
# \newcommand{\FSD}{\text{FSD}}
# \void^\dagger$</center>**

# ## Question 8.1
#
# $\bspace$We first write $n$ Eular equations
#
# $$u_0'\P{e_0 - \Tran S \theta} S_k = \sum_{\omega \in\Omega} \pi_\omega u_1'\P{e_{1\omega} + X_{\omega,\cdot} \theta} X_{\omega,k},\bspace k = 1,2,\dots,n$$
#
# $\bspace$whose solution $\theta$ is the optimal portfolio. The fact that $\tilde r_i$ are $i.i.d.$ implies that the preceding equation can be rewritten as, after letting $e_{1\omega} = 0$
#
# $$\begin{align}u_0'\P{e_0 - \Tran S \theta} S_k &= \Exp{u_1'\P{\SB{S_1+S_1\cdot\tilde r_1,S_2+S_2\cdot\tilde r_2, \cdots, S_n + S_n\cdot\tilde r_n}\theta\:} \cdot S_k\P{1+\tilde r_k}}\\
# u_0'\P{e_0 - \Tran S \theta}&= \Exp{u_1'\P{\SB{S_1+S_1\cdot\tilde r_1,S_2+S_2\cdot\tilde r_2, \cdots, S_n + S_n\cdot\tilde r_n}\theta\:}} \cdot \Exp{1+\tilde r_k}
# \end{align}$$
#
# $\bspace$And now if we consider the variance, unbalanced allocation of securities will lead to higher covariance, and so is the variance, consequently. So the optimal portfolio is to find a $\theta^*$ such that 
#
# $$\theta = \theta^*\cdot \iota$$

# ## Question 8.2
#
# $\P{1}$
#
# $\bspace$Suppose we put $y\cdot w$ money in risk security and the rest in risk free security, then we write
#
# $$\tilde w = y\cdot w \P{1+\tilde r} + \P{1-y}w\P{1+r_F} = w\P{1+r_F + y\P{\tilde r-r_F}}$$
#
# $\bspace$With this we rewrite the optimization problem:
#
# $$\begin{array}{cc}
# \d{\max_y} & \Exp{w\P{1+r_F + y\P{\tilde r-r_F}} - \ffrac{1}{2}aw^2\P{1+r_F + y\P{\tilde r-r_F}}^2}
# \end{array}$$
#
# $\bspace$And take the derivative on $y$ we have the first order condition:
#
# $$\begin{align}
# \ffrac{\partial \Exp{\tilde w - \ffrac{1}{2}a\tilde w^2}}{\partial y} &= \Exp{w\P{\tilde r - r_F} - \ffrac{1}{2} aw^2\cdot 2\P{1+r_F + y\P{\tilde r - r_F}}\P{\tilde r - r_F}}\\
# &= w\P{\Exp{\tilde r} - r_F} - aw^2\P{\P{1+r_F}\P{\Exp{\tilde r} - r_F} + y\P{r_F^2 - 2r_F\Exp{\tilde r} + \Exp{\tilde r^2}}}\\
# &= w\P{\bar r - r_F} - aw^2\P{\P{1+r_F}\P{\bar r - r_F} + y\P{r_F^2 - 2r_F\bar r + \bar r^2 + \sigma^2}}=0\\
# \Rightarrow y &= \ffrac{\ffrac{\bar r - r_F}{aw} - \P{1+r_F}\P{\bar r - r_F}}{\P{\bar r - r_F}^2 + \sigma^2} = \ffrac{\P{\bar r - r_F}\P{1-aw\P{1+r_F}}}{aw\P{\P{\bar r - r_F}^2 + \sigma^2}}
# \end{align}$$
#
# $\P{2}$
#
# $\bspace$Here we give the intuitive answers.
#
# - $r_F$ and $y$ are negatively correlated, because agent will tend to put more money in risk free security given they can get more interest
# - $\bar r$ and $y$ are positively correlated, because agent will tend to put more money in risk security given they can get more interest, in a probabilistic sense
# - $\sigma$ and $y$ are negatively correlated, because rational agent will withdraw money from risk security given higher risk, or volatility
# - $a$ and $y$ are negatively correlated, not only can be seen from the explicit expression of $y$, but also the meaning of $a$. Given a increase in $a$ the absolute risk aversion $A\P{w} = \ffrac{a}{1-aw}$ increases meaning that the agent tend to withdraw some money from the risk security.

# ## Question 8.3
#
# $\P 1$
#
# $\bspace$The optimization problem is now
#
# $$\begin{array}{cc}
# \d{\max_y} & \Exp{ -\exp\CB{-aw\P{1+r_F + y\P{\tilde r-r_F}}}}
# \end{array}$$
#
# $\bspace$We first simplify this expression
#
# $$\begin{align}
# \Exp{ -\exp\CB{-aw\P{1+r_F + y\P{\tilde r-r_F}}}} &= -\exp\CB{-aw\P{1+r_F-yr_F}}\Exp{\exp\CB{-awy \tilde r}}\\
# &= -\exp\CB{-aw\P{1+r_F-yr_F}} \cdot \exp\CB{-\mu \cdot awy + \ffrac{\sigma^2}{2}\P{awy}^2}\\
# &= -\exp\CB{-aw\P{1+r_F} + aw\P{r_F - \mu}y  + \ffrac{\sigma^2}{2}\P{aw}^2y^2}
# \end{align}$$
#
# $\bspace$Since $\exp\CB{-aw\P{1+r_F}}$ is positive we have the simplified optimization problem
#
# $$\begin{array}{cc}
# \d{\max_y} & -\exp\CB{aw\P{r_F - \mu}y  + \ffrac{\sigma^2}{2}\P{aw}^2y^2}
# \end{array}$$
#
# $\bspace$And take the derivative on $y$ we have the first order condition:
#
# $$\begin{align}
# \ffrac{\partial \P{-\exp\CB{aw\P{r_F - \mu}y  + \ffrac{\sigma^2}{2}\P{aw}^2y^2}}}{\partial y} &= -\exp\CB{aw\P{r_F - \mu}y  + \ffrac{\sigma^2}{2}\P{aw}^2y^2}\cdot\P{aw\P{r_F - \mu} + \sigma^2\P{aw}^2y} = 0\\
# \Rightarrow \P{aw\P{r_F - \mu} + \sigma^2\P{aw}^2y}&=0 \Rightarrow y = \ffrac{\mu - r_F}{\sigma^2aw}
# \end{align}$$
#
# $\P{2}$
#
# $\bspace$Here we give the intuitive answers.
#
# - $r_F$ and $y$ are negatively correlated, because agent will tend to put more money in risk free security given they can get more interest
# - $\mu$ and $y$ are positively correlated, because agent will tend to put more money in risk security given they can get more interest, in a probabilistic sense
# - $\sigma$ and $y$ are negatively correlated, because rational agent will withdraw money from risk security given higher risk, or volatility
# - $a$ and $y$ are negatively correlated, not only can be seen from the explicit expression of $y$, but also the meaning of $a$. Given a increase in $a$ the absolute risk aversion $A\P{w} = a$ increases meaning that the agent tend to withdraw some money from the risk security.

# ## Question 9.1
#
# $\bspace\newcommand{\FSD}{\text{FSD}}
# \newcommand{\SSD}{\text{SSD}}$Consider first stochastic dominance, $A\not\succsim_{\FSD} B$ if $u\P x = x^3$, nor $B\not\succsim_{\FSD} A$ if $u\P x = x+1$.
#
# $\bspace$Then the second stochastic dominance, using the theorem, we let $d=1$ and define $\tilde e$
#
# $$\begin{array}{c|cccc}
# & \omega_1 & \omega_2 &\omega_3&\omega_4\\\hline
# \tilde e & 0.4 & 0.3 & -0.3 & -0.4\\
# p & 0.25 & 0.25 & 0.25 & 0.25\\
# \tilde x_A & 1.5 & 1.5 & 1.7 & 1.7
# \end{array}$$
#
# $$\begin{align}
# \Exp{\tilde e \mid x_A} &= \sum_{i} \tilde e_i \cdot p\P{\tilde e_i\mid x_{A,i}}\\
# &= 0.4\times0.25 + 0.3 \times 0.25 - 0.3 \times 0.25 - 0.4 \times 0.25 = 0
# \end{align}$$
#
# $\bspace$So $A\succsim_{\SSD} B$.

# ## Question 9.2
#
# $\P{\text a.1}$
#
# $$\bspace \tilde r_B = \tilde x + \tilde e = 1 \cdot \tilde r_A + \tilde e \Rightarrow \tilde x_B = 1 \cdot \tilde x_A + \tilde e $$
#
# $\bspace$And due to the independency, $\Exp{\tilde e\mid \tilde x_A} = \Exp{\tilde e} = 0$, thus $A\succsim_{\void_\SSD} B$.
#
# $\P{\text a.2}$
#
# $$\begin{align}
# \Exp{u\P{\tilde w}} &= \Exp{u\P{a\P{1+\tilde r_A} + \P{1-a}\P{1+\tilde r_B}}}\\
# &= \Exp{u\P{1+ a\P{\tilde x - \tilde x - \tilde e} + \tilde x + \tilde e}}\\
# &= \Exp{u\P{1+\P{1-a}\tilde e + \tilde x}}
# \end{align}$$
#
# $\bspace$Since $\Exp{\tilde e} = 0$, we take the derivative on $a$ and have the following:
#
# $$\begin{align}
# \ffrac{\partial^2 \Exp{u\P{\tilde w}}}{\partial a^2} &=\Exp{u''\P{1+\P{1-a}\tilde e + \tilde x}\tilde e^2}\leq 0\\
# \ffrac{\partial \Exp{u\P{\tilde w}}}{\partial a} &= \Exp{-u'\P{1+\P{1-a}\tilde e + \tilde x}\tilde e}\\
# &= \sum_{e<0}e\cdot P\CB{\tilde e = e}\cdot u'\P{1+\P{1-a}e + \tilde x} + \sum_{e>0}e\cdot P\CB{\tilde e = e}\cdot u'\P{1+\P{1-a}e + \tilde x}\\
# &\geq \sum_{e<0}e\cdot P\CB{\tilde e = e}\cdot u'\P{1+\P{1-a}\cdot 0 + \tilde x} + \sum_{e>0}e\cdot P\CB{\tilde e = e}\cdot u'\P{1+\P{1-a}\cdot 0 + \tilde x}\\
# & = u'\P{1 + \tilde x}\cdot\Exp{\tilde e} = 0
# \end{align}$$
#
# $\bspace$Thus $\Exp{u\P{\tilde w}}$ gets to its maximum at $a=1$. The conclusion is same when $\tilde e$ is continuous.
#
# $\P{\text b.1}$
#
# $\bspace$With the same reasoning, we can prove that $A\succsim_{\void_\SSD} B$.
#
# $\P{\text b.2}$
#
# $\bspace$Now $\Exp{u\P{\tilde w}} = \Exp{u\P{a\tilde x + \P{1-a}\P{\tilde y + \tilde e}}} = \Exp{u\P{\tilde y + \tilde e + a\P{\tilde x - \tilde y - \tilde e}}}$. Still we have its second order direvative on $a$ positive. Then
#
# $$\begin{align}
# \ffrac{\partial \Exp{u\P{\tilde w}}}{\partial a} &= \Exp{u'\P{\tilde y + \tilde e + a\P{\tilde x - \tilde y - \tilde e}}\P{\tilde x - \tilde y - \tilde e}}\\
# \end{align}$$
#
# $\bspace$At $a = 0.5$, this equals to $\Exp{u'\P{a\P{\tilde x + \tilde y + \tilde e}}\P{\tilde x - \tilde y - \tilde e}} = -\Exp{u'\P{a\P{\tilde x + \tilde y + \tilde e}}\tilde e}$, with the same form we've proved in $\P{\text a.2}$. Thus $\given{\ffrac{\partial \Exp{u\P{\tilde w}}}{\partial a}}_{a=0.5}\geq0$. In order to reach the maximum, we have now $a>0.5$.
#
# $\P{\text{c}}$
#
# $\bspace$The result is intuitively obvious. In $\P{\text a}$, $\tilde r_B$ has got a higher volatility than $\tilde r_A$, so the optimal strategy is to ignore asset $B$. In $\P{\text b}$, we know that in probabilistic sense asset $A$ has a lower volatility than asset $B$, thus, we put more money in $A$ and consequently $a>0.5$.

# ## Question 9.5
#
# $\bspace$Using $Theorem\space 9.5$, when all $\tilde r_n$ are $i.i.d.$, whatever preference you have, the portfolio you hold is equivelent to a equal-weight portfolio. Thus the utility function of any agent, say $k$, can now be linearly transformed to the utility function of any other agent, say $j$, meaning that the utility functions of all agents, are equivalent, in linear sense. So then we have single fund separation.

# ## Question 9.6
#
# $\P{1}$
#
# $\bspace$The weights on all $N$ risky securities are $\alpha = \SB{a_1;a_2;\cdots;a_N}$. Then we write
#
# $$\tilde w = w\P{1+r_F} + \sum_{i=1}^N a_i\P{\tilde r_i - r_F} = w\P{1+r_F} + \Tran\alpha\P{\tilde r - r_F\cdot \iota}$$
#
# $\bspace$We then take the derivative on $\alpha$ to derive the first order condition
#
# $\begin{align}
# &\ffrac{\partial \Exp{\tilde w - \ffrac{1}{2}a\tilde w^2}}{\partial \alpha}\\ 
# =\;& \ffrac{\partial \Exp{w\P{1+r_F} + \Tran{\P{\tilde r - r_F\cdot\iota}}\alpha - \ffrac{1}{2}a \P{w^2\P{1+r_F}^2 + \Tran\alpha\P{\tilde r - r_F\cdot\iota} \Tran{\P{\tilde r - r_F\cdot\iota}}\alpha + 2w\P{1+r_F}\Tran{\P{\tilde r - r_F\cdot\iota}}\alpha}}}{\partial \alpha}\\
# =\;& \Exp{\Tran{\P{\tilde r - r_F\cdot\iota}} - \ffrac{1}{2} a\Tran\alpha\P{\P{\tilde r - r_F\cdot\iota}\Tran{\P{\tilde r - r_F\cdot\iota}} + \P{\tilde r - r_F\cdot\iota}\Tran{\P{\tilde r - r_F\cdot\iota}}} - aw\P{1+r_F}\Tran{\P{\tilde r - r_F\cdot\iota}}}\\
# =\;& \Exp{\Tran{\P{\tilde r - r_F\cdot\iota}}\P{1 - aw\P{1+r_F}}- a\Tran\alpha\P{\P{\tilde r - r_F\cdot\iota}\Tran{\P{\tilde r - r_F\cdot\iota}}}}\\
# =\;& \Tran{\P{\bar r - r_F \cdot \iota}}\P{1-aw\P{1+r_F}} - a\Tran\alpha \Sigma = 0
# \end{align}$
#
# $\bspace$So that $\alpha = \ffrac{1-aw\P{1+r_F}}{a} \Sigma^{-1}\P{\bar r - r_F \cdot \iota}$
#
# $\P{2}$
#
# $\bspace$From $Theorem\space 9.6$, the assertion is obviously true. And the proof is given in Chapter 12, so...

# ***

StarcoderdataJupyterScriptsDedupFiltered