arbitragelab.copula_approach.base

Abstract class for bivariate copula implementation.

Module Contents

Classes

Copula

Copula class houses common functions for each copula subtype.

class Copula(copula_name: str)

Bases: abc.ABC

Copula class houses common functions for each copula subtype.

__slots__ = ()
describe() pandas.Series

Print the description of the copula’s name and parameter as a pd.Series.

Note: the descriptive name is different from the copula’s class name, but its full actual name. E.g. The Student copula class has its descriptive name as ‘Bivariate Student-t Copula’.

Return description:

(pd.Series) The description of the copula, including its descriptive name, class name, and its parameter(s) when applicable.

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_cop_density(u: float, v: float, eps: float = 1e-05) float

Get the copula density c(u, 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 = 1e-05) float

Get the evaluation of copula, equivalently the cumulative joint distribution C(u, 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 evaluation of copula (aka cumulative joint distribution).

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 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.

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].

abstract sample(num: int = None, unif_vec: numpy.array = None) numpy.array

Place holder for sampling from copula.

Parameters:
  • num – (int) Number of points to generate.

  • unif_vec – (np.array) Shape=(num, 2) array, two independent uniformly distributed sets of data.

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.