# How to handle bid-offer spread causing negative estimations of risk-neutral densities from option prices?

I have attempted to estimate the risk-neutral probability density, from CBOE options prices on S&P500 from 2010 to 2016, using the following approximation from Hull (2018).

For call options on a given date with equal maturity, prices $c_1,c_2,c_3$ and strikes $K_1 = K_2-\delta, K_2,K_3=K_2+\delta$.

$\hat{g}(S_T=K) = e^{-r*(T-t)}\frac{c_1+c_3-2 * c_2}{\delta^2} \quad (1)$

For some reason, this expressions returns a negative value for some strikes.

Here is an example from my dataset:

dtmyears libor3m bid offer cp_flag strike     g
.032 .0025063 188.9 192.3 "C"     925            .
.032 .0025063 164.1 167.4 "C"     950            .
.032 .0025063 139.2 142.6 "C"     975        4.54e-17
.032 .0025063 114.4 117.8 "C"     1000      -.00016  <----  Why is it negative?
.032 .0025063  89.6  92.9 "C"     1025       .00048
.032 .0025063  64.9  68.3 "C"     1050       .00032
.032 .0025063  41.2  43.9 "C"     1075       .00336
.032 .0025063  19.6  21.6 "C"     1100        .0112
.032 .0025063   4.8   6.3 "C"     1125       .01616
.032 .0025063    .3   1.1 "C"     1150       .00752


In the example above, i have calculated $g(S_T = 1000)$ as follows (ignoring discounting):

$\hat{g}(S_T=1000) =\frac{142.6+92.9-2*117.8}{25^2}=-.00016$

This occurs both for puts and calls in all years, and both for bids, offers and averages of these.

I suspect, that this is caused by differences in spread between the strikes.

Is it possible to incorporate the bid-offer spread in $(1)$, such that the effect is eliminated?

You could for example parametrize your risk-neutral density $\hat{g}(S_T=x)$ as a polynomial:
$$\hat{g}(S_t=x)=\sum_ia_ix^i$$
and solve the program for a chosen polynomial order $n =\max i$:
\begin{align} & \min_{(a_i)}\left[\sum_k\left(\sum_i a_ix_k^i-\hat{g}(S_t=x_k)\right)^2\right] \\[3pt] & \ \forall \ k, \ \sum_ia_ix_k^i\geq0 \end{align}