def F(y): the_sum = 0 for i in range(1, 200): def my_factorial(k): return GammaFunc(k + 1) c = GammaFunc((i * m - 3.0) / n) / my_factorial(i) the_sum += c * y**i return y**(3 / (n - m)) * (GammaFunc((n - 3.0) / n) - 3 / n * the_sum)
def dFdy(y): the_sum, the_derivsum = 0, 0 for i in range(1, 200): def my_factorial(k): return GammaFunc(k + 1) c = GammaFunc((i * m - 3.0) / n) / my_factorial(i) the_sum += c * y**i the_derivsum += i * c * y**(i - 1) return y**(3 / (n - m)) * (-3 / n * the_derivsum) + ( 3 / (n - m)) * y**(3 / (n - m) - 1) * (GammaFunc( (n - 3.0) / n) - 3 / n * the_sum)
def t_negative_llh(params, p, q, r, gjr=False, out=None): c, phi, theta = params[0], params[1:p + 1], params[p + 1:p + q + 1] if gjr: omega, alpha, gamma, beta, v = params[-5:] else: omega, alpha, beta, v = params[-4:] gamma = None eps = get_epsilon(c, phi, theta, r) sigma2 = get_sigma2(omega, alpha, beta, gamma, r, eps, gjr) llh = np.log(GammaFunc((v + 1) / 2) / (GammaFunc(v / 2) * np.sqrt(np.pi * (v - 2) * sigma2)) * \ (1 + eps ** 2 / ((v - 2) * sigma2)) ** (-(v + 1) / 2)) neg_llh = -llh # minimize negative log likelihood total_llh = np.sum(neg_llh) if out is None: return total_llh else: return total_llh, llh, sigma2
def t_negative_loglikelihood(params, r): c = params[0] phi = params[1] theta = params[2] omega = params[3] alpha = params[4] beta = params[5] v = params[6] eps = get_epsilon(c, phi, theta, r) sigma2 = get_sigma2(omega, alpha, beta, eps) llh = np.log(GammaFunc((v + 1) / 2) / (GammaFunc(v / 2) * np.sqrt(np.pi * (v - 2) * sigma2)) * \ (1 + eps ** 2 / ((v - 2) * sigma2)) ** (-(v + 1) / 2)) neg_llh = -llh # minimize negative log likelihood total_llh = np.sum(neg_llh) return total_llh
def my_factorial(k): return GammaFunc(k + 1)