'Hessian matrix of the likelihood function, evaluated at the given
parameters
Parameters
params : array_like
Array of parameters at which to evaluate the hessian.
args
Additional positional arguments to the `loglike` method.
kwargs
Additional keyword arguments to the `loglike` method.
Returns
hessian : array
Hessian matrix evaluated at `params`
Notes
This is a numerical approximation.
Both \*args and \*\*kwargs are necessary because the optimizer from
`fit` must call this function and only supports passing arguments via
\*args (for example `scipy.optimize.fmin_l_bfgs`).'

def hessian(self, params, *args, **kwargs):

    (transformed, method, approx_complex_step, approx_centered, kwargs) = self._handle_args(MLEModel._hessian_param_names, MLEModel._hessian_param_defaults, *args, **kwargs)
    if ('method' in kwargs):
        method = kwargs.pop('method')
    if ((not transformed) and approx_complex_step):
        raise ValueError('Cannot    use    complex-step    approximations    to    calculate    the    hessian    with    untransformed    parameters.')
    if (approx_complex_step is None):
        approx_complex_step = (not self.ssm._complex_endog)
    if (approx_complex_step and self.ssm._complex_endog):
        raise ValueError('Cannot    use    complex    step    derivatives    when    data    or    parameters    are    complex.')
    if (method == 'oim'):
        hessian = self._hessian_oim(params, transformed=transformed, approx_complex_step=approx_complex_step, approx_centered=approx_centered, **kwargs)
    elif (method == 'opg'):
        hessian = self._hessian_opg(params, transformed=transformed, approx_complex_step=approx_complex_step, approx_centered=approx_centered, **kwargs)
    elif ((method == 'approx') and approx_complex_step):
        return self._hessian_complex_step(params, transformed=transformed, **kwargs)
    elif (method == 'approx'):
        return self._hessian_finite_difference(params, transformed=transformed, approx_centered=approx_centered, **kwargs)
    else:
        raise NotImplementedError('Invalid    Hessian    calculation    method.')
    return hessian
