Converting Expected value to integrals and differentiating Can you suggest me how to convert the following expected value function in to an integral and differentiate it with respect to $a$. 
\begin{equation*}
g \equiv E \left[ \max \left( a + x-b,0 \right) \times 1_{\{c+y \leq b \}} \right]
\end{equation*} 
where $a,b,c \in \mathbb{R} $ and the term after the multiplication sign is an indicator function. $x$ and $y$ are both random variables with continuous probability distribution functions $f_x$ and $f_y$. 
 A: The expectation of a function of two random variables is written as the following integral
$$
E[h(X,Y)] = \int_{-\infty}^\infty\int_{-\infty}^\infty h(x,y) f_{X,Y}(x,y) \;dxdy
$$
The function $f_{X,Y}(x,y)$ is the joint density of the random variables.  I'm going to assume that $X$ and $Y$ are independent random variables, in which case the joint density is the product of the marginals, $f_{X,Y}(x,y)=f_X(x)f_Y(y)$. In your case, $h(x,y)=\max(a+x-b,0)\times 1_{\{c+y\leq b\}}$, so the integral becomes
$$
\int_{-\infty}^{\infty}\int_{-\infty}^\infty \max(a+x-b,0) 1_{\{c+y\leq b\}} f_X(x)f_Y(y) \;dxdy
$$
Now, when $y>b-c$, the indicator function is zero and the integrand is zero.  Similarly, when $x<b-a$,  the $\max$ term is also zero and the integrand is zero.  These two facts allow us to absorb the effects of those two terms into the integration limits
$$
\int_{-\infty}^{b-c}\int_{b-a}^\infty (a+x-b) f_X(x)f_Y(y) \;dxdy
$$
The $y$ integration can be carried out in terms of the cumulative density function (CDF) for $Y$, $F_Y(y)$, since the integrand does not depend on $y$
$$
F_Y(b-c)\int_{b-a}^\infty (a+x-b) f_X(x) \;dx
$$
Break that up into two pieces, one involving $a-b$ and the other with just the $x$.  The first piece can also be written in terms of a CDF, $F_X(x)$
$$
F_Y(b-c)\left((a-b)(1-F_X(x))+\int_{b-a}^\infty x f_X(x) \;dx\right)
$$
Now you just have to differentiate w.r.t. $a$.
Edit 
OP says the variables are not independent.  In that case, I think you'd just need the joint density explicitly and slog through this integral
$$
\int_{-\infty}^{b-c}\int_{b-a}^\infty (a+x-b) f_{X,Y}(x,y) \;dxdy
$$
The problem is that in general, even if you know the marginal densities, you need more information to form the joint density.
