I am trying to prove a theorem that is doing my head in a bit. I have tried to simplify the problem as much as possible and leave out the details, even though it might look a bit too big. The simplified problem comes down to solving the following integral: $$ -\frac{Ke^{-rT}}{2\pi}\int_{ai-\infty}^{ai+\infty}e^{-iz(\ln\frac{S}{K}+rT)}\varphi(-z)\left(\frac{i}{z}-\frac{i}{z-i} \right)dz $$ where $a>1$, $K,T,r,S$ are constants and $\varphi$ is some function, where $\varphi(0) = \varphi(-i) = 1$.
If my calculations are correct, the residue at $z=0$ is $\left(\frac{-Ke^{-rT}i}{2\pi}\right)$. Similarly, the residue at $z=i$ is $\left(\frac{iS}{2\pi}\right)$.
Now is when I cannot move forward: I am not sure which contour I should define in order to solve the problem. I would be very grateful if you could help me out.
If it helps you, I show below the answer to this problem (I don't know how to get there):
$$ -\frac{Ke^{-rT}}{2\pi}\int_{ai-\infty}^{ai+\infty}e^{-iz(\ln\frac{S}{K}+rT)}\varphi(-z)\left(\frac{i}{z}-\frac{i}{z-i} \right)dz = I_1 + I_2 $$ where $$ I_1 = \frac{1}{2}(2\pi i)\frac{Ke^{-rT}i}{2\pi}+\frac{Ke^{-rT}}{2\pi}Pr.Value\left(\int_{-\infty}^{\infty}e^{iu(\ln\frac{S}{K}+rT)}\varphi(u)\frac{i}{u}du \right) $$ and $$ I_2 = -\frac{1}{2}(2\pi i)\frac{iS}{2\pi}+\frac{Ke^{-rT}}{2\pi}Pr.Value\left(\int_{i-\infty}^{i+\infty}e^{iu(\ln\frac{S}{K}+rT)}\varphi(-z)\frac{i}{z-i}dz \right) $$ where in $I_1$ we have used the change of variable $u = -z$.
PS: I am especially confused about that $\frac{1}{2}$ at the beginning of the definition of $I_1$ and $I_2$. Why would we only take the half of the residuals?.
Thanks in advance.
What is going on is - after splitting the integral into two by distributing the factor $\frac{i}{z} - \frac{i}{z-i}$ - a shift of contour.
Let us suppose that $f$ is holomorphic (or more generally meromorphic) on $\{ z : u < \operatorname{Im} z < v\}$ and satisfies some appropriate growth restrictions as $\lvert\operatorname{Re} z\rvert \to \infty$. If $u < c < a < v$, and $f$ has no pole in $ci$, then the residue theorem asserts that
$$\int_{C_{R,\varepsilon}} \frac{f(z)}{z-ci}\,dz = 2\pi i \sum \operatorname{Res}\left(\frac{f(z)}{z-ci};\zeta\right),$$
where the sum is taken over all poles of $f$ enclosed by the contour $C_{R,\varepsilon}$, which consists of
If $\lvert f(\pm R + is)\rvert$ grows slower than $\lvert \pm R + is\rvert$ as $R\to\infty$, so $\frac{f(z)}{z-ci}\to 0$ for $\lvert \operatorname{Im} z\rvert \to \infty$ then the integrals over the vertical segments $[R+ci,R+ai]$ and $[-R+ai,-R+ci]$ tend to $0$,
leaving
$$\int_{ai-\infty}^{ai+\infty} \frac{f(z)}{z-ci}\,dz - 2\pi i \sum \operatorname{Res}\left(\frac{f(z)}{z-ci};\zeta\right) = \int_{L_\varepsilon} \frac{f(z)}{z-ci}\,dz,\tag{1}$$
where $L_\varepsilon$ is the contour consisting of the segements $(ci-\infty, ci-\varepsilon]$ and $[ci+\varepsilon,ci+\infty)$ and the semicircle $\kappa_\varepsilon$ that was already part of $C_{R,\varepsilon}$.
Now
$$\lim_{\varepsilon\to 0} \left(\int_{ci-\infty}^{ci-\varepsilon}\frac{f(z)}{z-ci}\,dz + \int_{ci+\varepsilon}^{ci+\infty} \frac{f(z)}{z-ci}\,dz\right) = \operatorname{v.p.} \int_{ci-\infty}^{ci+\infty} \frac{f(z)}{z-ci}\,dz$$
(I denote the principal value by the abbreviation of the French "valeur principale"), and for the integral over the semicircle $\kappa_\varepsilon$, since $\frac{f(z)}{z-ci}$ has a simple pole in $ci$, it follows that
$$\lim_{\varepsilon\to 0} \int_{\kappa_\varepsilon} \frac{f(z)}{z-ci}\,dz = -\pi i\operatorname{Res}\left(\frac{f(z)}{z-ci};ci\right) = -\pi i f(ci).$$
If, as seems to be the case here, $f(z) = e^{bz}\varphi(-z)$ has no singularities in the strip $u < \operatorname{Im} z < v$ for some $u < 0$ and $a < v$, $(1)$ simplifies to
$$\int_{ai-\infty}^{ai+\infty} \frac{f(z)}{z-ci}\,dz = -\pi i f(ci) + \operatorname{v.p.} \int_{ci-\infty}^{ci+\infty} \frac{f(z)}{z-ci}\,dz.\tag{2}$$
Apply the shift once for $c = 0$ [for the $\frac{i}{z}$ part], and once for $c = 1$ [for the $\frac{i}{z-i}$ part].
The factor $\pi i$ instead of $2\pi i$ for the residues in $0$ and $i$ is, informally, because a simple pole on the contour of integration lies "half on the left and half on the right of the contour".