One object for every distribution
scipy.stats gives every probability distribution as one object, for example stats.norm, stats.t and stats.lognorm. They all share the same four methods. pdf(x) is the density, which says how likely values near are. cdf(x) is the probability of being at or below . ppf(p) is the inverse of the cdf: it returns the value that has probability below it, which is called a quantile. rvs(size) draws random numbers. Every distribution has a location (loc) and a scale (scale), so a value is loc + scale * standard_value. The call dist.fit(data) runs maximum likelihood, which means it picks the parameters that make your data most probable. For a normal distribution the fitted mean is the sample mean and the fitted standard deviation divides by , not by .
Daily returns have fat tails: big days happen far more often than a normal curve says. A Student t distribution with degrees of freedom has fatter tails, and a smaller means fatter tails. Its variance is (it needs ), so to give it a chosen standard deviation you use the scale . The one-day 99% value at risk (VaR) is the loss that is exceeded on only 1% of days. You get it from the 1% quantile of the returns.
- Same four methods:
pdffor density,cdffor probability below,ppffor the quantile andrvsfor random draws. - Fit, then check:
fitgives the maximum likelihood parameters (a normal sigma divides by ), and you still compare the tail counts with the data. - Fat tails matter for risk: a t distribution with a small gives a bigger VaR than a normal with the same standard deviation.
Lab · what's graded
- A normal VaR15 pts
- The maximum likelihood sigma15 pts
- The scale of a t distribution10 pts
- The t distribution's VaR15 pts
- The four shared methods10 pts
- A tail-risk workflow10 pts
- Why the normal understates the loss25 pts