{ "cells": [ { "cell_type": "markdown", "id": "5820c3ba", "metadata": {}, "source": [ "# Elementary Asset Pricing Theory\n", "\n", "\n", "" ] }, { "cell_type": "markdown", "id": "b9d8932c", "metadata": {}, "source": [ "## Contents\n", "\n", "- [Elementary Asset Pricing Theory](#Elementary-Asset-Pricing-Theory) \n", " - [Overview](#Overview) \n", " - [Key Equation](#Key-Equation) \n", " - [Implications of Key Equation](#Implications-of-Key-Equation) \n", " - [Expected Return - Beta Representation](#Expected-Return---Beta-Representation) \n", " - [Mean-Variance Frontier](#Mean-Variance-Frontier) \n", " - [Empirical Implementations](#Empirical-Implementations) \n", " - [Exercises](#Exercises) \n", " - [Solutions](#Solutions) " ] }, { "cell_type": "markdown", "id": "ba9ddf18", "metadata": {}, "source": [ "## Overview\n", "\n", "This lecture summarizes the heart of applied asset-pricing theory.\n", "\n", "From a single equation, we’ll derive\n", "\n", "- a mean-variance frontier \n", "- a single-factor model of excess returns on each member of a collection of assets \n", "\n", "\n", "To do this, we use two ideas:\n", "\n", "- an asset pricing equation \n", "- a Cauchy-Schwartz inequality \n", "\n", "\n", "For background and basic concepts, see our lecture [orthogonal projections and their applications](https://python-advanced.quantecon.org/orth_proj.html).\n", "\n", "As a sequel to the material here, please see our lecture [two modifications of mean-variance portfolio theory](https://python-advanced.quantecon.org/black_litterman.html)." ] }, { "cell_type": "markdown", "id": "b24281a5", "metadata": {}, "source": [ "## Key Equation\n", "\n", "We begin with a **key asset pricing equation**:\n", "\n", "\n", "\n", "$$\n", "E m R^i = 1 \\tag{35.1}\n", "$$\n", "\n", "for $i=1, \\ldots, I$ and where\n", "\n", "\n", "\\begin{aligned}\n", "m &=\\text { stochastic discount factor } \\\\\n", "R^{i} &= \\text {random gross return on asset } i \\\\\n", "E &\\sim \\text { mathematical expectation }\n", "\\end{aligned}\n", "\n", "\n", "The random gross returns $R^i$ and the scalar stochastic discount factor $m$ live\n", "live in a common probability space.\n", "\n", "[[HR87](https://python-advanced.quantecon.org/zreferences.html#id111)] and [[HJ91](https://python-advanced.quantecon.org/zreferences.html#id16)] explain how the existence of a scarlar stochastic discount factor that verifies equation\n", "[(35.1)](#equation-eq-emr1) is implied by a **law of one price** that requires that all portfolios of assets\n", "that end up having the same payouts must have the same price.\n", "\n", "They also explain how the **absence of an arbitrage** implies that the stochastic discount\n", "factor $m \\geq 0$." ] }, { "cell_type": "markdown", "id": "4fe25594", "metadata": {}, "source": [ "## Implications of Key Equation\n", "\n", "We combine key equation [(35.1)](#equation-eq-emr1) with a remark of Lars Peter Hansen that “asset pricing theory is all about covariances”.\n", "\n", ">**Note**\n", ">\n", ">Lars Hansen’s remark is a concise summary of ideas in [[HR87](https://python-advanced.quantecon.org/zreferences.html#id111)] and\n", "[[HJ91](https://python-advanced.quantecon.org/zreferences.html#id16)]. For other important foundations of these ideas, see\n", "[[Ros76](https://python-advanced.quantecon.org/zreferences.html#id12)], [[Ros78](https://python-advanced.quantecon.org/zreferences.html#id11)], [[HK79](https://python-advanced.quantecon.org/zreferences.html#id13)], [[Kre81](https://python-advanced.quantecon.org/zreferences.html#id14)], and\n", "[[CR83](https://python-advanced.quantecon.org/zreferences.html#id10)].\n", "\n", "By that remark, Lars Hansen meant that interesting restrictions can be deduced by recognizing that $E m R^i$ is a component of the covariance between $m$ and $R^i$ and then using that fact to rearrange key equation [(35.1)](#equation-eq-emr1).\n", "\n", "Let’s do this step by step.\n", "\n", "First note that the definition\n", "$\\operatorname{cov}\\left(m, R^{i}\\right) = E (m - E m)(R^i - E R^i)$\n", "of a\n", "covariance implies that\n", "\n", "$$\n", "E m R^i = E m E R^{i}+\\operatorname{cov}\\left(m, R^{i}\\right)\n", "$$\n", "\n", "Substituting this result into\n", "key equation [(35.1)](#equation-eq-emr1) gives\n", "\n", "\n", "\n", "$$\n", "1 = E m E R^{i}+\\operatorname{cov}\\left(m, R^{i}\\right) \\tag{35.2}\n", "$$\n", "\n", "Next note that for a risk-free asset with non-random gross return $R^f$, equation\n", "[(35.1)](#equation-eq-emr1) becomes\n", "\n", "$$\n", "1 = E R^f m = R^f E m.\n", "$$\n", "\n", "This is true because we can pull the constant $R^f$ outside the mathematical expectation.\n", "\n", "It follows that the gross return on a risk-free asset is\n", "\n", "$$\n", "R^{f} = 1 / E(m)\n", "$$\n", "\n", "Using this formula for $R^f$ in equation [(35.2)](#equation-eq-emr2) and rearranging, it follows that\n", "\n", "$$\n", "R^{f} = E R^{i}+\\operatorname{cov}\\left(m, R^{i} \\right) R^{f}\n", "$$\n", "\n", "which can be rearranged to become\n", "\n", "$$\n", "E R^i = R^{f}-\\operatorname{cov}\\left(m, R^{i}\\right) R^{f} .\n", "$$\n", "\n", "It follows that we can express an **excess return** $E R^{i}-R^{f}$ on asset $i$ relative to the risk-free rate as\n", "\n", "\n", "\n", "$$\n", "E R^{i}-R^{f} = -\\operatorname{cov}\\left(m, R^{i}\\right) R^{f} \\tag{35.3}\n", "$$\n", "\n", "Equation [(35.3)](#equation-eq-emr3) can be rearranged to display important parts of asset pricing theory." ] }, { "cell_type": "markdown", "id": "1d1e0349", "metadata": {}, "source": [ "## Expected Return - Beta Representation\n", "\n", "We can obtain the celebrated **expected-return-Beta -representation** for gross return $R^i$ simply by rearranging excess return equation [(35.3)](#equation-eq-emr3) to become\n", "\n", "$$\n", "E R^{i}=R^{f}+\\left(\\underbrace{\\frac{\\operatorname{cov}\\left(R^{i}, m\\right)}{\\operatorname{var}(m)}}_{\\quad\\quad\\beta_{i,m} = \\text{regression coefficient}}\\right)\\left(\\underbrace{-\\frac{\\operatorname{var}(m)}{E(m)}}_{\\quad\\lambda_{m} = \\text{price of risk}}\\right)\n", "$$\n", "\n", "or\n", "\n", "\n", "\n", "$$\n", "E R^{i}=R^{f}+\\beta_{i, m} \\lambda_{m} \\tag{35.4}\n", "$$\n", "\n", "Here\n", "\n", "- $\\beta_{i,m}$ is a (population) least squares regression coefficient of gross return $R^i$ on stochastic discount factor $m$, an object that is often called asset $i$’s **beta** \n", "- $\\lambda_m$ is minus the variance of $m$ divided by the mean of $m$, an object that is often called the **price of risk**. \n", "\n", "\n", "To interpret this representation it helps to provide the following widely used example.\n", "\n", "**Example**\n", "\n", "A popular model of $m$ is\n", "\n", "$$\n", "m_{t+1} = \\exp(-\\rho) \\exp(- \\gamma(c_{t+1} - c_t))\n", "$$\n", "\n", "where $\\rho > 0$, $\\gamma > 0$, and the log of consumption growth is governed by\n", "\n", "$$\n", "c_{t+1} - c_t = \\mu + \\sigma_c \\epsilon_{t+1}\n", "$$\n", "\n", "where $\\epsilon_{t+1} \\sim {\\mathcal N}(0,1)$.\n", "\n", "Here\n", "\n", "- $\\gamma >0$ is a coefficient of relative risk aversion \n", "- $\\rho >0$ is a fixed intertemporal discount rate \n", "\n", "\n", "$$\n", "m_{t+1} = \\exp(-\\rho) \\exp( - \\gamma \\mu - \\gamma \\sigma_c \\epsilon_{t+1})\n", "$$\n", "\n", "In this case\n", "\n", "$$\n", "E m_{t+1} = \\exp(-\\rho) \\exp \\left( - \\gamma \\mu + \\frac{\\sigma_c^2 \\gamma^2}{2} \\right)\n", "$$\n", "\n", "and\n", "\n", "$$\n", "\\operatorname{var}(m_{t+1}) = E(m) [ \\exp(\\sigma_c^2 \\gamma^2) - 1) ]\n", "$$\n", "\n", "When $\\gamma >0$, it is true that\n", "\n", "- when consumption growth is **high**, $m$ is **low** \n", "- when consumption growth is **low**, $m$ is **high** \n", "\n", "\n", "According the representation [(35.4)](#equation-eq-erbetarep), an asset with an $R^i$ that can be expected to be high when consumption growth is low has $\\beta_i$ positive and a low expected return.\n", "\n", "- because it has a high gross return when consumption growth is low, it is a good hedge against consumption risk, which justifies its low average return \n", "\n", "\n", "An asset with an $R^i$ that is low when consumption growth is low has $\\beta_i$ negative and a high expected return.\n", "\n", "- because it has a low gross return when consumption growth is low, it is a poor hedge against consumption risk, which justifies its high average return " ] }, { "cell_type": "markdown", "id": "b9af4d24", "metadata": {}, "source": [ "## Mean-Variance Frontier\n", "\n", "Now we’ll derive the celebrated **mean-variance frontier**.\n", "\n", "We do this using a classic method of Lars Peter Hansen and Scott\n", "Richard [[HR87](https://python-advanced.quantecon.org/zreferences.html#id111)].\n", "\n", ">**Note**\n", ">\n", ">Methods of Hansen and Richard are described and used extensively by [[Coc05](https://python-advanced.quantecon.org/zreferences.html#id15)].\n", "\n", "Their idea was rearrange the key equation [(35.1)](#equation-eq-emr1), namely, $E m R^i = 1$, and then to apply the Cauchy-Schwarz inequality.\n", "\n", "A convenient way to remember the Cauchy-Schwartz inequality in our context is that it says that an $R^2$ in any regression has to be less than or equal to $1$.\n", "\n", "Let’s apply that idea to deduce\n", "\n", "\n", "\n", "$$\n", "1= E\\left(m R^{i}\\right)=E(m) E\\left(R^{i}\\right)+\\rho_{m, R^{i}}\\frac{\\sigma(m)}{E(m)} \\sigma\\left(R^{i}\\right) \\tag{35.5}\n", "$$\n", "\n", "where $\\rho_{m, R^i}$ is the correlation coefficient defined as\n", "\n", "$$\n", "\\rho_{m, R^i} \\equiv \\frac{\\operatorname{cov}\\left(m, R^{i}\\right)}{\\sigma(m) \\sigma\\left(R^{i}\\right)}\n", "$$\n", "\n", "and where $\\sigma$ denotes the standard deviation of the variable in parentheses\n", "\n", "Equation [(35.5)](#equation-eq-emr5) implies\n", "\n", "$$\n", "E R^{i}=R^{f}-\\rho_{m, R^i} \\frac{\\sigma(m)}{E(m)} \\sigma\\left(R^{i}\\right)\n", "$$\n", "\n", "Because $\\rho_{m, R^i} \\in [-1,1]$, it follows that $|\\rho_{m, R^i}| \\leq 1$ and that\n", "\n", "\n", "\n", "$$\n", "\\left|E R^i-R^{f}\\right| \\leqslant \\frac{\\sigma(m)}{E(m)} \\sigma\\left(R^{i}\\right) \\tag{35.6}\n", "$$\n", "\n", "Inequality [(35.6)](#equation-eq-erm6) delineates a **mean-variance frontier**\n", "\n", "(Actually, it looks more like a **mean-standard-deviation frontier**)\n", "\n", "Evidently, points on the frontier correspond to gross returns that are perfectly correlated\n", "(either positively or negatively) with the stochastic discount factor $m$.\n", "\n", "We summarize this observation as\n", "\n", "$$\n", "\\rho_{m, R^{i}}=\\left\\{\\begin{array}{ll}\n", "+1 & \\implies R^i \\text { is on lower frontier } \\\\\n", "-1 & \\implies R^i \\text { is on an upper frontier }\n", "\\end{array}\\right.\n", "$$\n", "\n", "The image below illustrates a mean-variance frontier.\n", "\n", "![https://python-advanced.quantecon.org/_static/lecture_specific/asset_pricing_lph/AssetPricing_v1.jpg](https://python-advanced.quantecon.org/_static/lecture_specific/asset_pricing_lph/AssetPricing_v1.jpg)\n", "\n", " \n", "The mathematical structure of the mean-variance frontier described by inequality [(35.6)](#equation-eq-erm6) implies\n", "that\n", "\n", "- all returns on frontier are perfectly correlated. \n", " Thus, \n", " - Let $R^m, R^{mv}$ be two returns on frontier. \n", " - Then for some scalar $a$ \n", " - $R^{m v}=R^{f}+a\\left(R^{m}-R^{f}\\right)$ \n", " This is an **exact** equation with no **residual** \n", "- each return $R^i$ that is on the mean-variance frontier is perfectly correlated with $m$ \n", " - $\\left(\\rho_{m, R^{i}}=-1\\right) \\Rightarrow \\begin{cases} m=a+b R^{m v} \\\\ R^{m v}=e+d m \\end{cases}$ for some scalars $a, b, e, d$, \n", " Therefore, **any return on the mean-variance frontier is a legitimate stochastic discount factor** \n", "- for any mean-variance-efficient return $R^{m v}$ that is on the frontier but that is **not** $R^{f}$, there exists a **single-beta representation** for any return $R^i$ that takes the form: \n", "\n", "\n", "\n", "\n", "$$\n", "E R^{i}=R^{f}+\\beta_{i, R^{m v}}\\left[E\\left(R^{m v}\\right)-R^{f}\\right] \\tag{35.7}\n", "$$\n", "\n", "- The special case of a single-beta representation [(35.7)](#equation-eq-emr7) with $R^{i}=R^{m v}$ is \n", " $E R^{m v}=R^{f}+1 \\cdot\\left[E\\left(R^{m v}\\right)-R^{f}\\right]$ " ] }, { "cell_type": "markdown", "id": "0fb3941f", "metadata": {}, "source": [ "## Empirical Implementations\n", "\n", "We briefly describe empirical implementations of multi-factor generalizations of the single-factor model described above.\n", "\n", "The single-beta representation [(35.7)](#equation-eq-emr7) is a special case with there being just a single factor.\n", "\n", "Two representations are often used in empirical work.\n", "\n", "One is a **time-series regression** of gross return $R_t^i$ on multiple\n", "risk factors $f_t^j, j = a, b, \\ldots$ that is designed to uncover exposures of return $R^i$ to each of a set of **risk-factors** $f_t^j, j = a, b, \\ldots,$:\n", "\n", "$$\n", "R_{t}^{i}=a_{i}+\\beta_{i, a} f_{t}^{a}+\\beta_{i, b} f_{t}^{b}+\\ldots+\\epsilon_{t}^{i}, \\quad t=1,2, \\ldots, T\\\\\n", "\\epsilon_{t}^{i} \\perp f_{t}^{j}, i=1,2, \\ldots, I; j = a, b, \\ldots\n", "$$\n", "\n", "For example:\n", "\n", "- a popular **single-factor** model specifies the single factor $f_t$ to be the return on the market portfolio \n", "- another popular **single-factor** model called the consumption based model specifies the factor to be $m_{t+1} = \\beta \\frac{u^{\\prime}\\left(c_{t+1}\\right)}{u^{\\prime}\\left(c_{t}\\right)}$, where $c_t$ is a representative consumer’s time $t$ consumption. \n", "\n", "\n", "Model objects are interpreted as follows:\n", "\n", "- $\\beta_{i,a}$ is the exposure of return $R^i$ to factor $f_a$ risk \n", "- $\\lambda_{a}$ is the price of exposure to factor $f_a$ risk \n", "\n", "\n", "The other representation entails a **cross-section regression** of **average returns** $E R^i$ for assets\n", "$i =1, 2, \\ldots, I$ on **prices of risk** $\\lambda_j$ for $j =a, b, c, \\ldots$\n", "\n", "Here is the regression specification:\n", "\n", "$$\n", "E R^{i} =\\gamma+\\beta_{i, a} \\lambda_{a}+\\beta_{i, b} \\lambda_{b}+\\cdots\n", "$$\n", "\n", "**Testing strategies:**\n", "\n", "Time-series and cross-section regressions play roles in both **estimating** and **testing** beta representation\n", "models.\n", "\n", "The basic idea is to implement the following two steps.\n", "\n", "**Step 1:**\n", "\n", "- Estimate $a_{i}, \\beta_{i, a}, \\beta_{i, b}, \\cdots$ by running a **time series regression:** $R_{t}^{i}$ on a constant and $f_{t}^{a}, f_{t}^{b}, \\ldots$ \n", "\n", "\n", "**Step 2:**\n", "\n", "- take the $\\beta_{i, j}$’s estimated in step one as regressors together with data on average returns\n", " $E R^i$ over some period and then estimate the **cross-section regression** \n", "\n", "\n", "$$\n", "\\underbrace{E\\left(R^{i}\\right)}_{\\text{average return over time series}}=\\gamma+\\underbrace{\\beta_{i, a}}_{\\text{regressor}\\quad} \\underbrace{\\lambda_{a}}_{\\text{regression}\\text{coefficient}}+\\underbrace{\\beta_{i, b}}_{\\text{regressor}\\quad} \\underbrace{\\lambda_{b}}_{\\text{regression}\\text{coefficient}}+\\cdots+\\underbrace{\\alpha_{i}}_{\\text{pricing errors}}, i=1, \\ldots, I; \\quad \\underbrace{\\alpha_i \\perp \\beta_{i,j},j = a, b, \\ldots}_{\\text{least squares orthogonality condition}}\n", "$$\n", "\n", "- estimate $\\gamma, \\lambda_{a}, \\lambda_{b}, \\ldots$ by an appropriate regression technique, being thoughtful about recognizing that the regressors have been generated by a step 1 regression. \n", "\n", "\n", "Note that presumably the risk-free return $E R^{f}=\\gamma$.\n", "\n", "For excess returns $R^{ei} = R^i - R^f$ we have\n", "\n", "$$\n", "E R^{e i}=\\beta_{i, a} \\lambda_{a}+\\beta_{i, b} \\lambda_{b}+\\cdots+\\alpha_{i}, i=1, \\ldots, I\n", "$$" ] }, { "cell_type": "markdown", "id": "cb86f87b", "metadata": {}, "source": [ "## Exercises\n", "\n", "Let’s start with some imports." ] }, { "cell_type": "code", "execution_count": null, "id": "3215f7b3", "metadata": { "hide-output": false }, "outputs": [], "source": [ "import numpy as np\n", "from scipy.stats import stats\n", "import statsmodels.api as sm\n", "from statsmodels.sandbox.regression.gmm import GMM\n", "import matplotlib.pyplot as plt\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "id": "d0c5b361", "metadata": {}, "source": [ "Lots of our calculations will involve computing population and sample OLS regressions.\n", "\n", "So we define a function for simple univariate OLS regression that calls the OLS routine from statsmodels." ] }, { "cell_type": "code", "execution_count": null, "id": "0dcfed13", "metadata": { "hide-output": false }, "outputs": [], "source": [ "def simple_ols(X, Y, constant=False):\n", "\n", " if constant:\n", " X = sm.add_constant(X)\n", "\n", " model = sm.OLS(Y, X)\n", " res = model.fit()\n", "\n", " β_hat = res.params[-1]\n", " σ_hat = np.sqrt(res.resid @ res.resid / res.df_resid)\n", "\n", " return β_hat, σ_hat" ] }, { "cell_type": "markdown", "id": "3b59c92a", "metadata": {}, "source": [ "### Exercise 1\n", "\n", "Look at the equation,\n", "\n", "$$\n", "R^i_t - R^f = \\beta_{i, R^m} (R^m_t - R^f) + \\sigma_i \\varepsilon_{i, t}.\n", "$$\n", "\n", "Verify that this equation is a regression equation." ] }, { "cell_type": "markdown", "id": "a2f97712", "metadata": {}, "source": [ "### Exercise 2\n", "\n", "Give a formula for the regression coefficient $\\beta_{i, R^m}$." ] }, { "cell_type": "markdown", "id": "619b3a44", "metadata": {}, "source": [ "### Exercise 3\n", "\n", "Recall our earlier discussions of a **direct problem** and an **inverse problem**.\n", "\n", "- A direct problem is about simulating a particular model. \n", "- An inverse problem is about using data to **estimate** or **choose** a particular model from a manifold of models. \n", "\n", "\n", "Please assume the parameter values set below and then simulate 2000 observations from the theory specified\n", "above for 5 assets, $i = 1, \\ldots, 5$.\n", "\n", "\n", "\\begin{align*}\n", "E\\left[R^f\\right] &= 0.02 \\\\\n", "\\sigma_f &= 0.00 \\\\\n", "\\xi &= 0.06 \\\\\n", "\\lambda &= 0.04 \\\\\n", "\\beta_{1, R^m} &= 0.2 \\\\\n", "\\sigma_1 &= 0.04 \\\\\n", "\\beta_{2, R^m} &= .4 \\\\\n", "\\sigma_2 &= 0.04 \\\\\n", "\\beta_{3, R^m} &= .6 \\\\\n", "\\sigma_3 &= 0.04 \\\\\n", "\\beta_{4, R^m} &= .8 \\\\\n", "\\sigma_4 &= 0.04 \\\\\n", "\\beta_{5, R^m} &= 1.0 \\\\\n", "\\sigma_5 &= 0.04\n", "\\end{align*}\n", "\n", "\n", "**More Exercises**\n", "\n", "Now come some even more fun parts!\n", "\n", "Our theory implies that there exist values of two scalars, $a$ and $b$, such that a legitimate stochastic discount factor is:\n", "\n", "$$\n", "m_t = a + b R^m_t\n", "$$\n", "\n", "The parameters $a, b$ must satisfy the following equations:\n", "\n", "\n", "\\begin{align*}\n", "E[(a + b R_t^m) R^m_t)] &= 1 \\\\\n", "E[(a + b R_t^m) R^f_t)] &= 1\n", "\\end{align*}\n", "" ] }, { "cell_type": "markdown", "id": "93a24dfc", "metadata": {}, "source": [ "### Exercise 4\n", "\n", "Using the equations above, find a system of two **linear** equations that you can solve for $a$ and $b$ as functions of the parameters $(\\lambda, \\xi, E[R_f])$.\n", "\n", "Write a function that can solve these equations.\n", "\n", "Please check the **condition number** of a key matrix that must be inverted to determine a, b" ] }, { "cell_type": "markdown", "id": "f3cbd77e", "metadata": {}, "source": [ "### Exercise 5\n", "\n", "Using the estimates of the parameters that you generated above, compute the implied stochastic discount factor." ] }, { "cell_type": "markdown", "id": "686b1e7d", "metadata": {}, "source": [ "## Solutions" ] }, { "cell_type": "markdown", "id": "da203f5d", "metadata": {}, "source": [ "### Solution to Exercise 1\n", "\n", "To verify that it is a **regression equation** we must show that the residual is orthogonal to the regressor.\n", "\n", "Our assumptions about mutual orthogonality imply that\n", "\n", "$$\n", "E\\left[\\epsilon_{i,t}\\right]=0,\\quad E\\left[\\epsilon_{i,t}u_{t}\\right]=0\n", "$$\n", "\n", "It follows that\n", "\n", "\n", "\\begin{aligned}\n", "E\\left[\\sigma_{i}\\epsilon_{i,t}\\left(R_{t}^{m}-R^{f}\\right)\\right]&=E\\left[\\sigma_{i}\\epsilon_{i,t}\\left(\\xi+\\lambda u_{t}\\right)\\right] \\\\\n", "\t&=\\sigma_{i}\\xi E\\left[\\epsilon_{i,t}\\right]+\\sigma_{i}\\lambda E\\left[\\epsilon_{i,t}u_{t}\\right] \\\\\n", "\t&=0\n", "\\end{aligned}\n", "" ] }, { "cell_type": "markdown", "id": "1617cdd2", "metadata": {}, "source": [ "### Solution to Exercise 2\n", "\n", "The regression coefficient $\\beta_{i, R^m}$ is\n", "\n", "$$\n", "\\beta_{i,R^{m}}=\\frac{Cov\\left(R_{t}^{i}-R^{f},R_{t}^{m}-R^{f}\\right)}{Var\\left(R_{t}^{m}-R^{f}\\right)}\n", "$$" ] }, { "cell_type": "markdown", "id": "dc53facc", "metadata": {}, "source": [ "### Solution to Exercise 3\n", "\n", "**Direct Problem:**" ] }, { "cell_type": "code", "execution_count": null, "id": "e1e7b2fd", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Code for the direct problem\n", "\n", "# assign the parameter values\n", "ERf = 0.02\n", "σf = 0.00 # Zejin: Hi tom, here is where you manipulate σf\n", "ξ = 0.06\n", "λ = 0.08\n", "βi = np.array([0.2, .4, .6, .8, 1.0])\n", "σi = np.array([0.04, 0.04, 0.04, 0.04, 0.04])" ] }, { "cell_type": "code", "execution_count": null, "id": "bd7c22bc", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# in this cell we set the number of assets and number of observations\n", "# we first set T to a large number to verify our computation results\n", "T = 2000\n", "N = 5" ] }, { "cell_type": "code", "execution_count": null, "id": "24eba8bc", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# simulate i.i.d. random shocks\n", "e = np.random.normal(size=T)\n", "u = np.random.normal(size=T)\n", "ϵ = np.random.normal(size=(N, T))" ] }, { "cell_type": "code", "execution_count": null, "id": "4b78d8a8", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# simulate the return on a risk-free asset\n", "Rf = ERf + σf * e\n", "\n", "# simulate the return on the market portfolio\n", "excess_Rm = ξ + λ * u\n", "Rm = Rf + excess_Rm\n", "\n", "# simulate the return on asset i\n", "Ri = np.empty((N, T))\n", "for i in range(N):\n", " Ri[i, :] = Rf + βi[i] * excess_Rm + σi[i] * ϵ[i, :]" ] }, { "cell_type": "markdown", "id": "2d9be15b", "metadata": {}, "source": [ "Now that we have a panel of data, we’d like to solve the inverse problem by assuming the theory specified above and estimating the coefficients given above." ] }, { "cell_type": "code", "execution_count": null, "id": "850e2737", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Code for the inverse problem" ] }, { "cell_type": "markdown", "id": "57ae1eae", "metadata": {}, "source": [ "**Inverse Problem:**\n", "\n", "We will solve the inverse problem by simple OLS regressions.\n", "\n", "1. estimate $E\\left[R^f\\right]$ and $\\sigma_f$ " ] }, { "cell_type": "code", "execution_count": null, "id": "71e152be", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ERf_hat, σf_hat = simple_ols(np.ones(T), Rf)" ] }, { "cell_type": "code", "execution_count": null, "id": "716ad953", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ERf_hat, σf_hat" ] }, { "cell_type": "markdown", "id": "757a7c87", "metadata": {}, "source": [ "Let’s compare these with the *true* population parameter values." ] }, { "cell_type": "code", "execution_count": null, "id": "e4a417a7", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ERf, σf" ] }, { "cell_type": "markdown", "id": "528dbcd9", "metadata": {}, "source": [ "1. $\\xi$ and $\\lambda$ " ] }, { "cell_type": "code", "execution_count": null, "id": "d2a0992c", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ξ_hat, λ_hat = simple_ols(np.ones(T), Rm - Rf)" ] }, { "cell_type": "code", "execution_count": null, "id": "c60e6f46", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ξ_hat, λ_hat" ] }, { "cell_type": "code", "execution_count": null, "id": "f128ae1e", "metadata": { "hide-output": false }, "outputs": [], "source": [ "ξ, λ" ] }, { "cell_type": "markdown", "id": "608de142", "metadata": {}, "source": [ "1. $\\beta_{i, R^m}$ and $\\sigma_i$ " ] }, { "cell_type": "code", "execution_count": null, "id": "72f93016", "metadata": { "hide-output": false }, "outputs": [], "source": [ "βi_hat = np.empty(N)\n", "σi_hat = np.empty(N)\n", "\n", "for i in range(N):\n", " βi_hat[i], σi_hat[i] = simple_ols(Rm - Rf, Ri[i, :] - Rf)" ] }, { "cell_type": "code", "execution_count": null, "id": "23aa7112", "metadata": { "hide-output": false }, "outputs": [], "source": [ "βi_hat, σi_hat" ] }, { "cell_type": "code", "execution_count": null, "id": "9126e630", "metadata": { "hide-output": false }, "outputs": [], "source": [ "βi, σi" ] }, { "cell_type": "markdown", "id": "c2768b9b", "metadata": {}, "source": [ "Q: How close did your estimates come to the parameters we specified?" ] }, { "cell_type": "markdown", "id": "9283ea38", "metadata": {}, "source": [ "### Solution to Exercise 4\n", "\n", "\n", "\n", "\n", "\\begin{align}\n", "a ((E(R^f) + \\xi) + b ((E(R^f) + \\xi)^2 + \\lambda^2 + \\sigma_f^2) & =1 \\cr\n", "a E(R^f) + b (E(R^f)^2 + \\xi E(R^f) + \\sigma_f ^ 2) & = 1 \n", "\\end{align} \\tag{35.8}\n", "" ] }, { "cell_type": "code", "execution_count": null, "id": "e72e0a24", "metadata": { "hide-output": false }, "outputs": [], "source": [ "# Code here\n", "def solve_ab(ERf, σf, λ, ξ):\n", "\n", " M = np.empty((2, 2))\n", " M[0, 0] = ERf + ξ\n", " M[0, 1] = (ERf + ξ) ** 2 + λ ** 2 + σf ** 2\n", " M[1, 0] = ERf\n", " M[1, 1] = ERf ** 2 + ξ * ERf + σf ** 2\n", "\n", " a, b = np.linalg.solve(M, np.ones(2))\n", " condM = np.linalg.cond(M)\n", "\n", " return a, b, condM" ] }, { "cell_type": "markdown", "id": "929dfae7", "metadata": {}, "source": [ "Let’s try to solve $a$ and $b$ using the actual model parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "1a543e8f", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a, b, condM = solve_ab(ERf, σf, λ, ξ)" ] }, { "cell_type": "code", "execution_count": null, "id": "6c74b7bf", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a, b, condM" ] }, { "cell_type": "markdown", "id": "8823c624", "metadata": {}, "source": [ "### Solution to Exercise 5\n", "\n", "Now let’s pass $\\hat{E}(R^f), \\hat{\\sigma}^f, \\hat{\\lambda}, \\hat{\\xi}$ to the function solve_ab." ] }, { "cell_type": "code", "execution_count": null, "id": "39c2e379", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a_hat, b_hat, M_hat = solve_ab(ERf_hat, σf_hat, λ_hat, ξ_hat)" ] }, { "cell_type": "code", "execution_count": null, "id": "abaadd7b", "metadata": { "hide-output": false }, "outputs": [], "source": [ "a_hat, b_hat, M_hat" ] } ], "metadata": { "date": 1637718163.04752, "filename": "asset_pricing_lph.md", "kernelspec": { "display_name": "Python", "language": "python3", "name": "python3" }, "title": "Elementary Asset Pricing Theory" }, "nbformat": 4, "nbformat_minor": 5 }