# Module Levy¶

This is a package for calculation of Levy stable distributions (probability density function and cumulative density function) and for fitting these distributions to data.

It operates by interpolating values from a table, as direct computation of these distributions requires a lengthy numerical integration. This interpolation scheme allows fast fitting of data by Maximum Likelihood .

Does not support alpha values less than 0.5.

`levy.``change_par`(alpha, beta, mu, sigma, par_input, par_output)

Returns mu in the parametrization ‘par_output’, from the parametrization ‘par_input”.

Example:
```>>> change_par(1.8, 1, 0, 1, 1, 0)
-0.32491969623290645
```
Parameters: alpha (float) – alpha beta (float) – beta mu (float) – mu sigma (float) – sigma par_input (int) – par_input par_output (int) – par_output value of mu in the par_output parametrization float
`levy.``random`(alpha, beta, mu=0.0, sigma=1.0, shape=(), par=0)

Generate random values sampled from an alpha-stable distribution. Parametrization can be chosen according to Nolan, par={0,1}.

Example:
```>>> x = random(1.5, 0, shape=100, par=0)
```
Parameters: alpha (float) – alpha beta (float) – beta mu (float) – mu sigma (float) – sigma shape (tuple) – shape (numpy array type) of the resulting array par (int) – parametrization generated random values `ndarray`
`levy.``levy`(x, alpha, beta, mu=0.0, sigma=1.0, cdf=False, par=0)

Levy distribution with the tail replaced by the analytical (power law) approximation.

alpha in (0, 2] is the index of stability, or characteristic exponent. beta in [-1, 1] is the skewness. mu in real and sigma > 0 are the center and scale of the distribution (corresponding to delta and gamma in Nolan’s notation; note that sigma in levy corresponds to sqrt(2) sigma in the normal distribution). cdf is a Boolean that specifies if it returns the cdf instead of the pdf.

Parametrization can be chosen according to Nolan, par={0,1}.

Example:
```>>> x = np.array([1, 2, 3])
>>> levy(x, 1.5, 0, cdf=True)
array([0.20203811, 0.08453908, 0.03150926])
```
Parameters: x (`ndarray`) – values where the function is evaluated alpha (float) – alpha beta (float) – beta mu (float) – mu sigma (float) – sigma cdf (bool) – it specifies if you want the cdf instead of the pdf par (int) – parametrization values of the pdf (or cdf if parameter ‘cdf’ is set to True) at ‘x’ `ndarray`
`levy.``fit_levy`(x, alpha=None, beta=None, mu=None, sigma=None, par=0)

Estimate parameters of Levy stable distribution given data x, using Maximum Likelihood estimation.

By default, searches all possible Levy stable distributions. However you may restrict the search by specifying the values of one or more parameters. Parametrization can be chosen according to Nolan, par={0,1}.

Examples:
```>>> np.random.seed(0)
>>> x = random(1.5, 0, 0, 1, shape=200)
>>> fit_levy(x) # -- Fit a stable distribution to x
(1.523332454855073, -0.08374679328809703, 0.05006400708816064, 0.9850660292714712, 402.44279062026806)
```
```>>> fit_levy(x, beta=0.0) # -- Fit a symmetric stable distribution to x
(1.5275585459739105, 0.0, 0.028412901208016147, 0.9874304715515858, 402.5204574692911)
```
```>>> fit_levy(x, beta=0.0, mu=0.0) # -- Fit a symmetric distribution centered on zero to x
(1.5292748496827586, 0.0, 0.0, 0.98865238323717, 402.55578262026063)
```
```>>> fit_levy(x, alpha=1.0, beta=0.0) # -- Fit a Cauchy distribution to x
(1.0, 0.0, 0.10120172254704864, 0.9014243199508114, 416.5364751270402)
```

Returns a tuple of (alpha, beta, mu, sigma, negative log density)

Parameters: x (`ndarray`) – values to be fitted alpha (float) – alpha beta (float) – beta mu (float) – mu sigma (float) – sigma par (int) – parametrization estimated parameters `ndarray`