Solved – Goodness of fit for stock prices

chi-squared-testfinancegoodness of fitkolmogorov-smirnov test

I'm in my first days of learning R and hit a roadblock with a small use case from finance.


(EDIT) Basically I want to know how to test sample fitness against any distribution. Say, find the degree of freedom of a t-distribution which would have the best fit with the given list of asset returns. I thought the way to go is to generate a random dataset with given properties, and qqplot it against the actual data, along with an abline to see if it's linear or not. In the question I'm using normal/lognormal just as an example which I thought would be easier to discuss.


So, there's a list of stock prices (presumably a lognormal distribution), from which I calculate a list of returns (presumably a normal distribution). Now I want to check my assumptions about the distributions, so I plot both:

par(mfcol=c(2,3))

#plot densities
plot(density(sbux.prices))
plot(density(sbux.returns))

#plot q-q probabilities for normal distribution
sbux.prices.norm = rnorm(n=1000, mean=mean(sbux.prices), sd=sd(sbux.prices))
qqplot(sbux.prices.norm, sbux.prices)
abline(0,1) 
sbux.returns.norm = rnorm(n=1000, mean=mean(sbux.returns), sd=sd(sbux.returns))
qqplot(sbux.returns.norm, sbux.returns)
abline(0,1)

#plot q-q probabilities for lognormal distribution
sbux.prices.lnorm = rlnorm(n=1000, mean=mean(sbux.prices), sd=sd(sbux.prices))
qqplot(sbux.prices.lnorm, sbux.prices)
abline(0,1) 
sbux.returns.lnorm = rlnorm(n=1000, mean=mean(sbux.returns), sd=sd(sbux.returns))
qqplot(sbux.returns.lnorm, sbux.returns)
abline(-1,1)

enter image description here

Two questions here.

  1. By just looking at the plots above, I can tell that prices follow lognormal distribution – because the corresponding QQ plot has a much better fit with lognormal than with normal. But returns seem to fit well with both distributions – is that correct or I'm doing something wrong?
  2. Obviously I'd better rely on a mathematical estimation of fitness rather than on a human checking the charts. I think, I can use Chi-squared or Kolmogorov-Smirnov test, but cannot understand how exactly to do that. E.g., ks.test(sbux.returns, sbux.returns.norm) gives me p-value = 0.007781 so I'm definitely missing something.

Best Answer

As I see the density plot on top for prices the distribution doesn't appear to be normal nor lognormal. It seems to have 2 humps and a lognormal would not. But that could be an artifact of the kernel width (I am assuming a kernel density estimation was used). Is that what the density function in R does? I am not very familiar with R.

To my eye the density for returns fits well to a normal distribution but there is possibly a problem in the lower tail as seen from the qq plot. i don't think it fits well to a lognormal. The qq plot diverges from the line in both tails.

Why do you think the lognormal fit looks good for prices? The line is very steep indicating that the scales must be different. It should follow the 45 degree line if the quantiles on both axes used the same scale. Because the slope is so steep and the circles so fat I don't think it is really clear that the quantiles fall on a straight line.

Related Question