{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Expectations\n", "\n", "**Functions**\n", "\n", "`np.random.RandomState`, `RandomState.standard_normal`, `RandomState.standard_t`, `RandomState.chi2`,\n", "`np.exp`, `np.mean`, `np.std`, `scipy.integrate.quadrature`, `scipy.integrate.quad`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 11\n", "\n", "Compute $E\\left[X\\right]$, $E\\left[X^{2}\\right]$, $V\\left[X\\right]$ and the kurtosis of $X$ using Monte Carlo integration when $X$ is distributed:\n", "\n", "1. Standard Normal\n", "2. $N\\left(0.08,0.2^{2}\\right)$\n", "3. Students $t_{8}$\n", "4. $\\chi_{5}^{2}$\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:22.853548Z", "iopub.status.busy": "2023-09-28T12:33:22.853548Z", "iopub.status.idle": "2023-09-28T12:33:23.013031Z", "shell.execute_reply": "2023-09-28T12:33:23.013031Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Standard Normal" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.013031Z", "iopub.status.busy": "2023-09-28T12:33:23.013031Z", "iopub.status.idle": "2023-09-28T12:33:23.028054Z", "shell.execute_reply": "2023-09-28T12:33:23.028054Z" }, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$t_8$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.028054Z", "iopub.status.busy": "2023-09-28T12:33:23.028054Z", "iopub.status.idle": "2023-09-28T12:33:23.036516Z", "shell.execute_reply": "2023-09-28T12:33:23.036516Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\chi^2_5$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.036516Z", "iopub.status.busy": "2023-09-28T12:33:23.036516Z", "iopub.status.idle": "2023-09-28T12:33:23.045098Z", "shell.execute_reply": "2023-09-28T12:33:23.045098Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$N(8\\%, 20\\%^2)$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.045098Z", "iopub.status.busy": "2023-09-28T12:33:23.045098Z", "iopub.status.idle": "2023-09-28T12:33:23.053312Z", "shell.execute_reply": "2023-09-28T12:33:23.053312Z" }, "jupyter": { "outputs_hidden": false } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Function are useful for avoiding many blocks of repetitive code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.053312Z", "iopub.status.busy": "2023-09-28T12:33:23.053312Z", "iopub.status.idle": "2023-09-28T12:33:23.120576Z", "shell.execute_reply": "2023-09-28T12:33:23.120576Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 12 \n", "\n", "1. Compute $E\\left[\\exp\\left(X\\right)\\right]$ when $X\\sim N\\left(0.08,0.2^{2}\\right)$.\n", "2. Compare this to the analytical result for a Log-Normal random variable.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.120576Z", "iopub.status.busy": "2023-09-28T12:33:23.120576Z", "iopub.status.idle": "2023-09-28T12:33:23.147484Z", "shell.execute_reply": "2023-09-28T12:33:23.147484Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 13\n", "\n", "Explore the role of uncertainty in Monte Carlo integration by increasing the number of simulations 300% relative to the base case." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.154214Z", "iopub.status.busy": "2023-09-28T12:33:23.154214Z", "iopub.status.idle": "2023-09-28T12:33:23.210739Z", "shell.execute_reply": "2023-09-28T12:33:23.210739Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 14\n", "\n", "Compute the $N(8\\%, 20\\%^2)$ expectation in exercise 11 using quadrature.\n", "\n", "**Note**: This requires writing a function which will return $\\exp\\left(x\\right)\\times\\phi\\left(x\\right)$ where $\\phi\\left(x\\right)$ is the pdf evaluated at $x$." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2023-09-28T12:33:23.210739Z", "iopub.status.busy": "2023-09-28T12:33:23.210739Z", "iopub.status.idle": "2023-09-28T12:33:23.977125Z", "shell.execute_reply": "2023-09-28T12:33:23.977125Z" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 15 \n", "\n", "**Optional** (Much more challenging)\n", "\n", "Suppose log stock market returns are distributed according to a Students t with 8 degrees of\n", "freedom, mean 8% and volatility 20%. Utility maximizers hold a portfolio consisting of a\n", "risk-free asset paying 1% and the stock market. Assume that they are myopic and only care\n", "about next period wealth, so that \n", "\n", "$$U\\left(W_{t+1}\\right)=U\\left(\\exp\\left(r_{p}\\right)W_{t}\\right)$$\n", "\n", "and that $U\\left(W\\right)=\\frac{W^{1-\\gamma}}{1-\\gamma}$ is CRRA with risk aversion $\\gamma$.\n", "The portfolio return is $r_{p}=wr_{s}+\\left(1-w\\right)r_{f}$ where $s$ is for stock market\n", "and $f$ is for risk-free. A 4th order expansion of this utility around the expected wealth\n", "next period is\n", "\n", "$$E_{t}\\left[U\\left(W_{t+1}\\right)\\right]\\approx\\phi_{0}+\\phi_{1}\\mu_{1}^{\\prime}+\\phi_{2}\\mu_{2}^{\\prime}+\\phi_{3}\\mu_{3}^{\\prime}+\\phi_{4}\\mu_{4}^{\\prime}$$\n", "\n", "where\n", "\n", "$$\\phi_{j}=\\left(j!\\right)^{-1}U^{\\left(j\\right)}\\left(E_{t}\\left[W_{t+1}\\right]\\right),$$\n", "\n", "$$U^{(j)}=\\frac{\\partial^{j}U}{\\partial W^{j}},$$\n", "\n", "$$\\mu_{k}^{\\prime}=E_{t}\\left[\\left(r-\\mu\\right)_{p}^{k}\\right],$$\n", "\n", "and $\\mu=E_{t}\\left[r_{p}\\right]$. Use Monte Carlo integration to examine how the weight in\n", "the stock market varies as the risk aversion varies from 1.5 to 10. Note that when $\\gamma=1$, $U\\left(W\\right)=\\ln\\left(W\\right)$.\n", "Use $W_{t}=1$ without loss of generality since the portfolio problem is homogeneous of degree 0 in wealth." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } } }, "nbformat": 4, "nbformat_minor": 4 }