arbitragelab.copula_approach.mixed_copulas.base
Class template for mixed copulas.
Module Contents
Classes
Class template for mixed copulas. |
- class MixedCopula(copula_name: str)
Bases:
arbitragelab.copula_approach.base.Copula
,abc.ABC
Class template for mixed copulas.
- __slots__ = ()
- describe() pandas.Series
Describe the components and coefficients of the mixed copula.
The description includes descriptive name, class name, the copula dependency parameter for each mixed copula component and their weights.
- Returns:
(pd.Series) The description of the specific mixed copula.
- get_cop_density(u: float, v: float, eps: float = 1e-05) float
Calculate probability density of the bivariate copula: P(U=u, V=v).
Result is analytical. Also the u and v will be remapped into [eps, 1-eps] to avoid edge values that may result in infinity or NaN.
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
eps – (float) Optional. The distance to the boundary 0 or 1, such that the value u, v will be mapped back. Defaults to 1e-5.
- Returns:
(float) The probability density (aka copula density).
- get_cop_eval(u: float, v: float, eps: float = 0.0001) float
Calculate cumulative density of the bivariate copula: P(U<=u, V<=v).
Result is analytical except for Student-t copula. Also at the u and v will be remapped into [eps, 1-eps] to avoid edge values that may result in infinity or NaN.
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
eps – (float) Optional. The distance to the boundary 0 or 1, such that the value u, v will be mapped back. Defaults to 1e-4.
- Returns:
(float) The cumulative density.
- get_condi_prob(u: float, v: float, eps: float = 1e-05) float
Calculate conditional probability function: P(U<=u | V=v).
Result is analytical. Also at the u and v will be remapped into [eps, 1-eps] to avoid edge values that may result in infinity or NaN.
Note: This probability is symmetric about (u, v).
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
eps – (float) Optional. The distance to the boundary 0 or 1, such that the value u, v will be mapped back. Defaults to 1e-5.
- Returns:
(float) The conditional probability.
- sample(num: int) numpy.array
Generate pairs according to P.D.F., stored in a 2D np.array of shape (num, 2).
- Parameters:
num – (int) Number of points to generate.
- Return sample_pairs:
(np.array) Shape=(num, 2) array, sampled data for this copula.
- static theta_hat(tau: float) float
Calculate theta hat from Kendall’s tau from sample data.
- Parameters:
tau – (float) Kendall’s tau from sample data.
- Returns:
(float) The associated theta hat for this very copula.
- get_log_likelihood_sum(u: numpy.array, v: numpy.array) float
Get log-likelihood value sum.
- Parameters:
u – (np.array) 1D vector data of X pseudo-observations. Need to be uniformly distributed [0, 1].
v – (np.array) 1D vector data of Y pseudo-observations. Need to be uniformly distributed [0, 1].
- Returns:
(float) Log-likelihood sum value.
- c(u: float, v: float) float
Placeholder for calculating copula density.
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
- C(u: float, v: float) float
Placeholder for calculating copula evaluation.
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
- condi_cdf(u: float, v: float) float
Placeholder for calculating copula conditional probability.
- Parameters:
u – (float) A real number in [0, 1].
v – (float) A real number in [0, 1].
- fit(u: numpy.array, v: numpy.array) float
Fit copula to empirical data (pseudo-observations). Once fit, self.theta is updated.
- Parameters:
u – (np.array) 1D vector data of X pseudo-observations. Need to be uniformly distributed [0, 1].
v – (np.array) 1D vector data of Y pseudo-observations. Need to be uniformly distributed [0, 1].
- Returns:
(float) Theta hat estimate for fit copula.
- plot_cdf(plot_type: str = '3d', grid_size: int = 50, levels: list = None, **kwargs) matplotlib.pyplot.axis
Plot either ‘3d’ or ‘contour’ plot of copula CDF.
- Parameters:
plot_type – (str) Either ‘3d’ or ‘contour’(2D) plot.
grid_size – (int) Mesh grid granularity.
kwargs – (dict) User-specified params for ‘ax.plot_surface’/’plt.contour’.
levels – (list) List of float values that determine the number and levels of lines in a contour plot. If not provided, these are calculated automatically.
- Returns:
(plt.axis) Axis object.
- plot_scatter(num_points: int = 100) matplotlib.axes.Axes
Plot copula scatter plot of generated pseudo-observations.
- Parameters:
num_points – (int) Number of samples to generate.
- Returns:
(plt.axis) Axis object.
- plot_pdf(plot_type: str = '3d', grid_size: int = 50, levels: list = None, **kwargs) matplotlib.figure.Figure
Plot either ‘3d’ or ‘contour’ plot of copula PDF.
- Parameters:
plot_type – (str) Either ‘3d’ or ‘contour’(2D) plot.
grid_size – (int) Mesh grid granularity.
levels – (list) List of float values that determine the number and levels of lines in a contour plot. If not provided, these are calculated automatically.
- Returns:
(plt.axis) Axis object.