I want to plot a histogram, density (Gaussian kernel) and the fitted corresponding normal distribution, of the simple losses of the Allianz SE company.
(That means, the simple losses are minus the simple returns)
I have the following code:
hist(alvsloss,breaks = 100, freq=F,main="Histogramm,
density curve (gaussian kernel) of Allianz simple losses ",xlab="loss in percent",ylab="density")
lines(density(alvsloss), col="red", lwd=2)
curve(dnorm(x, mean = mean(alvsloss), sd = mean(alvsloss)), add=TRUE, col="blue", lty="dotted")
Now I have the first problem:
The fitted normal distribution is not drawn, I get the (german) error message:
In dnorm(x, mean = mean(alvsloss), sd = mean(alvsloss)) :
NaNs wurden erzeugt
The normal distribution curve is not plotted.
The second is a question in general:
If I leave out the normal distribution, so I only have the histogram and the density. Than I can change between frequency true and false via the command
freq=T
or
freq=F
I attached a screenshot of both pictures (I have to upload it, since I have not at least 10 reputations). I do not understand them, if I have freq=T that means, I have the density values at the y axis. So there should be values like 0.0012 or 0.1, but not values of 300 or 400, density should be relative values? Also the kernel does not match in any way, it is clearly wrong? If I have freq=F I get the right picture. Now I have absolute values, so e.g. there were 30 cases in which I had a return which was about 0.0 (the middle high peak), right? Now the density does fit, but I would have expected it to do not fit in this case, since I thought it is in freq=T values, so it should be another way round, in this picture it should be wrong?
If this is answered, I would have further questions:
I do not like the x axis, how can I have a more detailed scaling?
Is it right to say the following: The tail on the right from 0.5 up to 0.1 is heavier than the tail on the left side, so in this area we have a higher probability of losses than of gains? Whereas the extreme values occur only on the left side: Values of -0.2 and even one with approx -0.4. So extreme losses in this case are not occurring, whereas extreme gains are realized? Is this right?
What is my mistake, I cannot see it?
Screenshot:
You can find the data here
It is the alvsloss data
The complete solution is:
hist(alvsloss,breaks = 100, freq=F,main="Histogramm, density curve (gaussian kernel) of Allianz simple losses ",xlab="loss in percent",ylab="density")
lines(density(alvsloss), col="red", lwd=2)
curve(dnorm(x, mean = mean(alvsloss), sd = sd(alvsloss)), add=TRUE, col="blue",lwd=2)
which gives the following picture:
seems to be correct, right?