# Calculate Covariance.

Let $K_1$ be a random variable defined piece-wise as follows:

$$K_1 = \begin{cases} a_1, & X_1 < H_1 \\ m_1 X_1+b_1, & H_1<X_1<H_2 \\ c_1, & X_1 > H_2 \end{cases}$$

$X_1$ is a random variable defined as:

$$X_1=L_1 (1+j_1 )$$

$L_1,H_1,H_2,a_1,m_1,b_1,c_1$ are arbitrary constants.

$$j_1\sim N(μ_1,σ_1^2)$$

Let $K_2$ be a random variable defined piece-wise as follows:

$$K_2 = \begin{cases} a_2, & X_2 < H_3 \\ m_2 X_2+b_2, & H_3 < X_2 < H_4 \\ c_2, & X_2 > H_4 \end{cases}$$

$X_2$ is a random variable defined as:

$$X_2=L_2 (1+j_2 )$$

$L_2,H_3,H_4,a_2,m_2,b_2,c_2$ are arbitrary constants.

$$j_2\sim N(μ_2,σ_2^2)$$

$j_1$ and $j_2$ are jointly normal with coefficient of correlation $\rho$

Problem. Calculate $\operatorname{Cov}(K_1,K_2)$.

Attempted Solution: $$Cov(K_1,K_2 )=E[K_1 K_2 ]-E[K_1]E[K_2]$$

How I went about calculating $E[K_1]$:

Substitute $L_1\left(1+j_1\right)$ for $X_1$ and write everything in terms of $j_1$:

$$K_1 = \begin{cases} a_1, & j_1 < \frac{H_1-L_1}{L_1} \\ \left(m_1L_1+b_1\right)+\left(m_1L_1j_1\right), & \frac{H_1-L_1}{L_1}<j_1<\frac{H_2-L_1}{L_1} \\ c_1, & j_1 > \frac{H_2-L_1}{L_1} \end{cases}$$

$$E[K_1]=a_1 ∫_{-∞}^{\frac{H_1-L_1}{L_1}}{f_j}_{1}(j_1 )dj_1+(m_1 L_1+b_1 ) ∫_{\frac{H_1-L_1}{L_1}}^{\frac{H_2-L_1}{L_1}}{f_j}_{1}(j_1 )dj_1+m_1 L_1 ∫_{\frac{H_1-L_1}{L_1}}^{\frac{H_2-L_1}{L_1}}j_1 {f_j}_{1}(j_1 )dj_1+c_1 ∫_{\frac{H_2-L_1}{L_1}}^{∞}{f_j}_{1}(j_1 )dj_1$$

Generally, $$∫_a^b{f_j}_{1}(j_1 ) dj_1=\phi\left(\frac{b-{μ_j}_{1}}{{σ_j}_{1}}\right)-\phi\left(\frac{a-{μ_j}_{1}}{{σ_j}_{1}}\right)$$ where ${f_j}_{1}(j_1 )=\frac{1}{{σ_j}_{1}\sqrt{2π}}e^\left(-\frac{1}{2}\left(\frac{j_1-{μ_j}_{1}}{{σ_j}_{1}})\right)^2 \right)$ and $\phi(z)$ denotes the standard normal cumulative distribution function.

Moreover, it can be verified that

$$∫_{\frac{H_1-L_1}{L_1}}^{\frac{H_2-L_1}{L_1}}j_1 {f_j}_{1}(j_1)dj_1={μ_j}_{1} \left(\phi\left(\frac{\frac{H_2-L_1}{L_1} -{μ_j}_{1}}{{σ_j}_{1}} \right)-\phi\left(\frac{\frac{H_1-L_1}{L_1} -{μ_j}_{1}}{{σ_j}_{1}} \right)\right){σ_j}_{1}\sqrt{2π}+{σ_j}_{1}^2 \left(e^\left(-\frac{1}{2} \left(\frac{\frac{H_1-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)^2\right)-e^\left(-\frac{1}{2} \left(\frac{\frac{H_2-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)^2\right)\right)$$

Therefore

$$E[K_1 ]=a_1\phi\left(\frac{\frac{H_1-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)+(m_1 L_1+b_1 )\left(\phi\left(\frac{\frac{H_2-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)-\phi\left(\frac{\frac{H_1-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)\right)+m_1 L_1 \left(μ_{j_1} \left(\phi\left(\frac{\frac{H_2-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)-\phi\left(\frac{\frac{H_1-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)\right) σ_{j_1} \sqrt{2π}+σ_{j_1}^2 \left(e^\left(-\frac{1}{2} \left(\frac{\frac{H_1-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)^2\right)-e^\left(-\frac{1}{2} \left(\frac{\frac{H_2-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)^2\right) \right)\right)+c_1\left(1-\phi\left(\frac{\frac{H_2-L_1}{L_1} -μ_{j_1}}{σ_{j_1}}\right)\right)$$

Same logic was used to calculate $E[K_2]$.

Not sure how to set up $E[K_1 K_2 ]$. This is because I am not sure how to calculate $K_1$$K_2, since the values of both piece-wise random variables are conditional on different random variables, X_1 and X_2. Assuming I could do that however, I would still be unsure about how to calculate the following double integral:$$E[K_1K_2]=∫_{-∞}^∞ ∫_{-∞}^∞\frac{K_1(j_1)K_2(j_2)}{2{σ_j}_{1} {σ_j}_{2} \sqrt{1-ρ^2}} e^\left(\frac{-1}{2(1-ρ^2)}\left(\left(\frac{j_1-{μ_j}_{1}}{{σ_j}_{1}}\right)^2+\left(\frac{j_2-{μ_j}_{2}}{{σ_j}_{2}}\right)^2-\frac{2ρ\left(j_1-{μ_j}_{1}\right)\left(j_2-{μ_j}_{2}\right)}{{σ_j}_{1} {σ_j}_{2}}\right)\right) dj_1dj_2$$So I just need help calculating K_1(j_1)$$K_2(j_2)$ and $E[K_1K_2]$.

$$E[K_1 K_2]=∑_{i=1}^{9}∫_c^d∫_a^bz_i (j_1,j_2){{f_j}_{1}},_{j_2}(j_1,j_2){d_j}_{1} {d_j}_{2}$$ where $$Z=K_1 K_2$$ $a$,$b$,$c$,$d$ = bounds in the $i^{th}$ case where $i=1,2,…,9$ and ${{f_j}_{1}},_{j_2}(j_1,j_2)$ is the bivariate normal probability density function.