<jupyter_start><jupyter_text>Asset Pricing via Simulation <NAME><jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from numba import jit, prange
from numpy.random import randn<jupyter_output><empty_output><jupyter_text>We aim to compute the price dividend ratio$$    V_t = \mathbb E_t        \left[            M_{t+1} \frac{D_{t+1}}{D_t}            (1 + V_{t+1})        \right]$$given the SDF and dividend process.  Model 1 We consider the case of nonstationary dividends and consumption, where$$ \ln \frac{D_{t+1}}{D_t} = \mu_d + X_t + \sigma_d \eta_{d, t+1} $$The shock sequence $\{ \eta_{d,t} \}$ is IID and standard normal.  The state process $\{X_t\}$ obeys$$ X_{t+1} = \rho X_t + \sigma \xi_{t+1} $$where $\{ \xi_t \}$ is IID and standard normal. Consumption is also nonstationary, obeying$$ \ln \frac{C_{t+1}}{C_t} = \mu_c + X_t + \sigma_c \eta_{c, t+1} $$The sequence $\{ \eta_{c,t} \}$ is likewise IID and standard normal.We use the Lucas SDF$$ M_{t+1} = \beta \frac{u'(C_{t+1})}{u'(C_t)} $$The utility function is $$ u(c) = \frac{c^{1-\gamma}}{1 - \gamma} $$Hence$$     M_{t+1}     = \beta \left( \frac{C_{t+1}}{C_t} \right)^{-\gamma}     = \beta \exp(-\gamma(  \mu_c + X_t + \sigma_c \eta_{c, t+1} ))$$  Simulation Method For $m$ in 1 to $M$, simulate the observation$$ \Lambda(x, N, m) := \sum_{n=1}^N \prod_{i=1}^n A_i^{(m)} $$where $X_0 = x$ and $m$ indicates observation $m$. Compute$$ \hat v(x, M, n) := \frac{1}{M} \sum_{m=1}^M \Lambda(x, N, m) $$This is an estimate of $v(x)$<jupyter_code>@jit(nopython=True)
def simulate_forward_sum_ave(x0,
                         β=0.96,
                         γ=2.0,
                         ρ=0.9,
                         σ=0.05,
                         μ_d=0.01,
                         σ_d=0.01,
                         μ_c=0.05,
                         σ_c=0.01,
                         N=1000,
                         M=20000):
    
    Λ_vals = np.empty(M)
    
    for m in range(M):
        
        # Generate the path correspoding to m
        np.random.seed(m)
        A_path = np.empty(N)
        x = x0
        for t in range(N):
            η_c = randn()
            η_d = randn()
            t1 = -γ * μ_c + μ_d + (1 - γ) * x 
            t2 = - γ * σ_c * η_c + σ_d * η_d
            A_path[t] = β * np.exp(t1 + t2)
            x = ρ * x + σ * randn()

        # Compute the forward value of that path
        A_prod = 1.0
        Λ = 0.0
        for n in range(N):
            A_prod *= A_path[n]
            Λ += A_prod
    
        # Record the result, adding it to the sum
        Λ_vals[m] = Λ
            
    return Λ_vals.mean()
        
@jit(nopython=True, parallel=True)
def compute_prices_across_states(x_vals):
    n = len(x_vals)
    v_vals = np.empty(n)
    for i in prange(n):
        v_vals[i] = simulate_forward_sum_ave(x_vals[i])
    return v_vals
x_vals = np.linspace(-0.3, 0.3, 20)
v_vals = compute_prices_across_states(x_vals)
fig, ax = plt.subplots()
ax.plot(x_vals, v_vals)
ax.set_xlabel("$x$")
ax.set_ylabel("$v(x)$")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1570221066319896, 'fraction_numerical': 0.02340702210663199, 'mean_word_length': 1.9990253411306043, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '422002', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1174, 'n_words': 296, 'path': 'day3/applications/asset_pricing/asset_pricing_simulation.ipynb', 'repo_name': 'fkazemian/columbia_mini_course', 'size': '3085'}