StarVine
starvine.bvcopula.copula.copula_base.CopulaBase Class Reference

Bivariate Copula base class. More...

Inheritance diagram for starvine.bvcopula.copula.copula_base.CopulaBase:
starvine.bvcopula.copula.clayton_copula.ClaytonCopula starvine.bvcopula.copula.frank_copula.FrankCopula starvine.bvcopula.copula.gauss_copula.GaussCopula starvine.bvcopula.copula.gumbel_copula.GumbelCopula starvine.bvcopula.copula.indep_copula.IndepCopula starvine.bvcopula.copula.t_copula.StudentTCopula

Public Member Functions

def __init__ (self, rotation=0)
 Init copula. More...
 
def cdf (self, u, v, theta)
 Evaluate the copula's CDF function. More...
 
def pdf (self, u, v, theta)
 Public facing PDF function. More...
 
def h (self, u, v, theta)
 
def hinv (self, u, v, theta)
 
def fitMLE (self, u, v, theta0, kwargs)
 Maximum likelyhood copula fit. More...
 
def sample (self, n=1000, mytheta)
 Draw N samples from the copula. More...
 
def setRotation (self, rotation=0)
 Set the copula's orientation: Allows for modeling negative dependence with the frank, gumbel, and clayton copulas (Archimedean Copula family is non-symmetric) More...
 
def kTau (self, rotation=0, theta)
 Public facing kendall's tau function.
 

Public Attributes

 rotation
 
 fittedParams
 

Private Member Functions

def _pdf (self, u, v, rotation=0, theta)
 Pure virtual density function. More...
 
def _cdf (self, u, v, rotation=0, theta)
 Default implementation of the cumulative density function. More...
 
def _ppf (self, u, v, rotation=0, theta)
 Percentile point function. More...
 
def _h (self, u, v, rotation=0, theta)
 Copula conditional distribution function. More...
 
def _hinv (self, u, v, rotation=0, theta)
 Inverse H function.
 
def _v (self, u, v, rotation=0, theta)
 Copula conditional distribution function. More...
 
def _vinv (self, u, v, rotation=0, theta)
 
def _nlogLike (self, u, v, rotation=0, theta)
 Default negative log likelyhood function. More...
 
def _logLike (self, u, v, rotation=0, theta)
 Default log likelyhood func.
 
def _invhfun_bisect (self, U, V, rotation, theta)
 Compute inverse of H function using bisection. More...
 
def _AIC (self, u, v, rotation=0, theta)
 Estimate the AIC of a fitted copula (with params == theta) More...
 
def _gen (self, t, theta)
 Copula generator function.
 
def _kTau (self, rotation=0, theta)
 Computes Kendall's tau. More...
 
def _rotPDF (cls, f)
 Define copula probability density function rotation.
 
def _rotCDF (cls, f)
 Define copula cumulative density function rotation.
 
def _rotHinv (cls, f)
 Define copula dependence function rotation.
 
def _rotH (cls, f)
 Define copula inverse dependence function rotation.
 
def _rotGen (cls, f)
 Copula generator wrapper.
 

Detailed Description

Bivariate Copula base class.

Meant to be subclassed with the PDF and CDF methods being overridden for a given specific copula.

Copula can be rotated by 90, 180, 270 degrees to accommodate negative dependence.

Constructor & Destructor Documentation

§ __init__()

def starvine.bvcopula.copula.copula_base.CopulaBase.__init__ (   self,
  rotation = 0 
)

Init copula.

Parameters
rotationint Copula orientation

Member Function Documentation

§ _AIC()

def starvine.bvcopula.copula.copula_base.CopulaBase._AIC (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Estimate the AIC of a fitted copula (with params == theta)

Parameters
thetaCopula paramter list

§ _cdf()

def starvine.bvcopula.copula.copula_base.CopulaBase._cdf (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Default implementation of the cumulative density function.

Very slow. Recommended to replace with an analytic CDF if possible.

Parameters
thetaCopula parameter list
rotationint copula rotation parameter
unp_1darray Rank CDF data vector
vnp_1darray Rank CDF data vector

§ _h()

def starvine.bvcopula.copula.copula_base.CopulaBase._h (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Copula conditional distribution function.

Provides $ h $ given $ V $ and $ \theta $ .

\[ h(u|v, \theta) = \frac{\partial C( F(u|v), F(u|v) | \theta) }{\partial F(u|v)} \]

Parameters
unp_1darray is uniformly distributed on [0, 1]
vnp_1darray is distributed acording to some some known DF
rotationCopula rotation paramter
thetaKnown copula paramter list
Returns
h $ h(u|v, \theta) $

§ _invhfun_bisect()

def starvine.bvcopula.copula.copula_base.CopulaBase._invhfun_bisect (   self,
  U,
  V,
  rotation,
  theta 
)
private

Compute inverse of H function using bisection.

Update (11/08/2016) performance improvement: finish with newton iterations Update (12/04/2016) Newton can minimization needs bounds checks! TODO: move to scipy.minmize

§ _kTau()

def starvine.bvcopula.copula.copula_base.CopulaBase._kTau (   self,
  rotation = 0,
  theta 
)
private

Computes Kendall's tau.

Requires that the copula has a _gen() method implemented. This method should be overridden if an analytic form of kendall's tau is avalible.

Let $ T = C(u, v) $ represent a random variable and $ t $ is an RV distributed according to $ T() $.

\[ K_c(t) = \frac{\phi(t)}{\phi'(t)} \]

\[ \tau = 1 + 4 \int_0^1 K_c(t) dt \]

where $ \phi(t) $ is the copula generating function.

Note: For the gauss and students-t copula:

\[ \tau = \frac{2.0}{\pi} arcsin(\rho) \]

where $ \rho $ is the linear correlation coefficient.

§ _nlogLike()

def starvine.bvcopula.copula.copula_base.CopulaBase._nlogLike (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Default negative log likelyhood function.

Used in MLE fitting

§ _pdf()

def starvine.bvcopula.copula.copula_base.CopulaBase._pdf (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Pure virtual density function.

Parameters
unp_1darray Rank CDF data vector
vnp_1darray Rank CDF data vector
rotation_thetaint Copula rotation (0 == 0deg, 1==90deg, ...)

§ _ppf()

def starvine.bvcopula.copula.copula_base.CopulaBase._ppf (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Percentile point function.

Equivilent to the inverse of the CDF. Used to draw random samples from the bivariate distribution.

EX: will draw 100 samples from a t-copula with params [0.21, 20]

>>> import starvine.bvcopula as bvc
>>> My_Copula = bvc.t_copula.StudentTCopula()
>>> u, v = np.random.uniform(0, 1, 100)
>>> My_Copula._ppf(u, v, rotation=0, 0.21, 20)

§ _v()

def starvine.bvcopula.copula.copula_base.CopulaBase._v (   self,
  u,
  v,
  rotation = 0,
  theta 
)
private

Copula conditional distribution function.

Provides $ V$ given $ u $ and $ \theta $

§ cdf()

def starvine.bvcopula.copula.copula_base.CopulaBase.cdf (   self,
  u,
  v,
  theta 
)

Evaluate the copula's CDF function.

Parameters
unp_1darray Rank data vector
vnp_1darray Rank data vector
thetalist of float Copula parameter list

§ fitMLE()

def starvine.bvcopula.copula.copula_base.CopulaBase.fitMLE (   self,
  u,
  v,
  theta0,
  kwargs 
)

Maximum likelyhood copula fit.

Parameters
unp_1darray Rank data vector
vnp_1darray Rank data vector
theta0Initial guess for copula parameter list
Returns
tuple : (np_array Array of MLE fit copula parameters, int Fitting success flag, 1==success)

§ pdf()

def starvine.bvcopula.copula.copula_base.CopulaBase.pdf (   self,
  u,
  v,
  theta 
)

Public facing PDF function.

Parameters
unp_1darray Rank data vector
vnp_1darray Rank data vector
thetalist of float Copula parameter list

§ sample()

def starvine.bvcopula.copula.copula_base.CopulaBase.sample (   self,
  n = 1000,
  mytheta 
)

Draw N samples from the copula.

Parameters
nNumber of samples
thetaParameter list
rotationCopula rotation parameter
Returns
np_array (n, 2) size vector. Resampled (U, V) data pairs from copula with paramters: *theta

§ setRotation()

def starvine.bvcopula.copula.copula_base.CopulaBase.setRotation (   self,
  rotation = 0 
)

Set the copula's orientation: Allows for modeling negative dependence with the frank, gumbel, and clayton copulas (Archimedean Copula family is non-symmetric)

Parameters
rotationint Copula rotation. 0 == 0 deg, 1 == 90 deg rotation, 2 == 180 deg rotation, 3 == 270 deg rotation

The documentation for this class was generated from the following file: