I have some data from the S&P500 of daily returns. I'm not sure if I can show my graph, as I will be using it in my undergraduate paper, but it looks essentially the same as the histogram here:
Just like in the figure above, I am attempting to fit distributions to the histogram. I will be fitting a Gaussian distribution (which I know will be a relatively poor fit due to its characteristic thin tails), a Lorentzian/Cauchy (will fit better) and a Lévy-stable distribution (alpha = 1.32, obtained from curve_fit) which I believe will fit the best.
I have used python scipy to fit the distributions to the histogram, and also calculate the chi-square values. Below is my procedure for calculating the chi-square statistic.
#chi-square goodness of fit
g_exp = Gaussian(bincentres, gopt[0], gopt[1], gopt[2])
g_chi2 = chisquare(counts, np.sum(counts)/np.sum(g_exp) * g_exp, ddof = len(bincentres)-len(initial_guess))
l_exp = Lorentzian(bincentres, lopt[0], lopt[1], lopt[2])
l_chi2 = chisquare(counts, np.sum(counts)/np.sum(l_exp) * l_exp, ddof = len(bincentres)-len(initial_guess))
s_exp = levy(bincentres, sopt[0], sopt[1], sopt[2], sopt[3])
s_chi2 = chisquare(counts, np.sum(counts)/np.sum(s_exp) * s_exp, ddof = len(bincentres)-len(initial_guess))
#print statistics
print('The chi-square test statistic for the Gaussian fit is', g_chi2[0])
print('The chi-square p-value for the Gaussian fit is', g_chi2[1])
print('The chi-square test statistic for the Lorentzian fit is', l_chi2[0])
print('The chi-square p-value for the Lorentzian fit is', l_chi2[1])
print('The chi-square test statistic for the Lévy-Stable fit is', s_chi2[0])
print('The chi-square p-value for the Lévy-Stable fit is', s_chi2[1])
My first question. I was a bit confused how to define the degrees of freedom argument for scipy.stats.chisquare(). I believe the degrees of freedom for both the Gaussian and Lorentzian are simply number of bins - number of parameters
, but according to ChatGPT (sorry!) the degrees of freedom for a lévy-stable distribution with alpha < 2
is apparently infinite? I haven't been able to confirm this from other sources and so I'm reluctant to trust this. Is this true? If so, how do I account for this when trying to calculate the chi-squared value. For the calculations below, I have assumed I can determine the degrees of freedom for the Lévy-stable fit the same way I did for the Gaussian and Lorentzian fits.
My other question: When I run this code, I get the following values:
The chi-square test statistic for the Gaussian fit is 1.7726251912776834e+221
The chi-square p-value for the Gaussian fit is 0.0
The chi-square test statistic for the Lorentzian fit is 79.84356081527558
The chi-square p-value for the Lorentzian fit is 4.594000744173512e-18
The chi-square test statistic for the Lévy-Stable fit is 40.74782285238357
The chi-square p-value for the Lévy-Stable fit is 1.4181517095051678e-09
I expected the Gaussian chi-square value to be highest as it had the poorest fit visually speaking, but is it very weird that it is so large compared to the other two values? Also why are the p-values so small. How do I interpret these results? Apologies if these are simple/silly things to ask, my knowledge of statistics is not too great.