# Fitting a CDF to differentiate symbolically

I'm trying to curve fit a functional form to observed data - where my observed data is a physical observation that represents a CDF.

Visually - my data points currently look like this:

y_spl_2d = y_spl.derivative(n=1)
plt.plot(x_range,y_spl_2d(x_range), 'ro')


My goal is to get an accurate representation of the PDF. Just a visual inspection of the CDF looks good (I know... not that that means much).

If I take the second derivative of this function numerically there is TONS of noise introduced. This is what it looks like:

This is where I'm at. Can I fit a functional form to this CDF data so I can take a derivative symbolically?

What is the best way - in a statistical sense - to not lose information like bi-modal PDFs and other things like this. How can I include enough parameters in my functional form to include skewness, kurtosis, etc (to not force a perfectly Gaussian distribution)?

The original fit where all of this data derives from is the derivative of an options price to the strike.

• (1) Could you explain the relevance of the second derivative of the CDF to your question? (2) Derivatives (of any order) are unstable. You need to smooth the CDF first. It would help to know whether you expect the CDF to have a particular kind of formula and what that formula might be. It is not essential that the formula be perfectly correct--but it can provide valuable guidance concerning how to choose a good smoothing technique. – whuber Oct 26 '16 at 19:37
• Try fitting a sigmoid function. You can use your favorite fitting algorithm to do so. Looks like you did this in python. Check Scipy's documentation for fitting procedures. – Demetri Pananos Oct 26 '16 at 19:38
• @Demetri If by "sigmoid" you mean something like a logistic or tanh function, then that clearly won't work: this CDF is highly skewed. – whuber Oct 26 '16 at 19:39
• @whuber Might be worth a shot to see how bad it can be. I can't think of any other closed for functions with that behavior. Other than that, maybe use a non-parametric method and then approximate the derivatives with finite differences? – Demetri Pananos Oct 26 '16 at 19:41
• Why is this "cdf" clearly not monotonic non-decreasing? Can you explain what calculation leads to such an outcome? – Glen_b Oct 26 '16 at 20:37

This is definitively not the case for density estimation. There is no way to get good estimates of the PDF without either enforcing smoothness (kernel density estimation or log-splines, for example) or other assumptions (belongs to parametric family, is log-concave, etc). This is because without any smoothness assumptions/priors, the distribution that would make the data we have seen most likely would be the distribution that puts probability $1/n$ on each of the data points we observed. Since we observed a finite data set, this is necessarily a discrete random variable, for which the PDF is undefined (i.e., it is defined by a probability mass function, not probability density function).
In my experience, I've found kernel density estimation to be most reliable. In fact, R's density function uses this and the default settings tend to be quite reasonable. But be warned that you don't have to look too hard to find cases where the results may be unsatisfactory.