예제 #1
0
def independentPoissonAnalytic(N, c, myLam, alpha):
    pmfPoisson = np.zeros(N + 1)
    for k in range(0, N + 1):
        pmfPoisson[k] = util.poissonDensity(myLam, k)
    cdfPoisson = np.cumsum(pmfPoisson)
    varAnalytic = c * np.interp(alpha, cdfPoisson, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmfPoisson, c)
    return pmfPoisson, cdfPoisson, varAnalytic, esAnalytic
예제 #2
0
def independentBinomialAnalytic(N, p, c, alpha):
    pmfBinomial = np.zeros(N + 1)
    for k in range(0, N + 1):
        pmfBinomial[k] = util.getBC(N, k) * (p ** k) * ((1 - p) ** (N - k))
    cdfBinomial = np.cumsum(pmfBinomial)
    varAnalytic = c * np.interp(alpha, cdfBinomial, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmfBinomial, c)
    return pmfBinomial, cdfBinomial, varAnalytic, esAnalytic
def betaBinomialAnalytic(N, c, a, b, alpha):
    pmfBeta = np.zeros(N + 1)
    den = util.computeBeta(a, b)
    for k in range(0, N + 1):
        pmfBeta[k] = util.getBC(N, k) * util.computeBeta(a + k,
                                                         b + N - k) / den
    cdfBeta = np.cumsum(pmfBeta)
    varAnalytic = c * np.interp(alpha, cdfBeta, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmfBeta, c)
    return pmfBeta, cdfBeta, varAnalytic, esAnalytic
def logitProbitBinomialAnalytic(N, c, mu, sigma, alpha, isLogit):
    pmf = np.zeros(N + 1)
    for k in range(0, N + 1):
        pmf[k], err = nInt.quad(logitProbitMixtureFunction,
                                0,
                                1,
                                args=(N, k, mu, sigma, isLogit))
    cdf = np.cumsum(pmf)
    varAnalytic = c * np.interp(alpha, cdf, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmf, c)
    return pmf, cdf, varAnalytic, esAnalytic
def poissonMixtureAnalytic(N, myC, a, b, alpha, whichModel):
    pmfMixture = np.zeros(N + 1)
    for k in range(0, N + 1):
        pmfMixture[k], err = nInt.quad(poissonMixtureIntegral,
                                       0,
                                       k + 1,
                                       args=(k, a, b, N, whichModel))
    cdfMixture = np.cumsum(pmfMixture)
    varAnalytic = myC * np.interp(alpha, cdfMixture, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmfMixture, myC)
    return pmfMixture, cdfMixture, varAnalytic, esAnalytic
def poissonGammaAnalytic(N, c, a, b, alpha):
    pmfPoisson = np.zeros(N + 1)
    q = np.divide(b, b + 1)
    den = math.gamma(a)
    for k in range(0, N + 1):
        num = np.divide(math.gamma(a + k), scipy.misc.factorial(k))
        pmfPoisson[k] = np.divide(num, den) * np.power(q, a) * np.power(
            1 - q, k)
    cdfPoisson = np.cumsum(pmfPoisson)
    varAnalytic = c * np.interp(alpha, cdfPoisson, np.linspace(0, N, N + 1))
    esAnalytic = util.analyticExpectedShortfall(N, alpha, pmfPoisson, c)
    return pmfPoisson, cdfPoisson, varAnalytic, esAnalytic