def runModelSuite(N, M, P, C, alpha, nu, myRho, rhoTarget, tenor, modelType):
    startTime = time.time()
    if modelType == 0:  # Binomial (independent-default) model
        el, ul, var, es = bp.independentBinomialSimulation(N, M, P, C, alpha)
        simTime = (time.time() - startTime)
    elif modelType == 1:  # Gaussian threshold model
        el, ul, var, es = th.oneFactorThresholdModel(N, M, P, C, myRho, nu,
                                                     alpha, 0)
        simTime = (time.time() - startTime)
    elif modelType == 2:  # Beta-binomial mixture model
        myP = np.mean(P)
        a, b = mix.betaCalibrate(myP, rhoTarget)
        M1 = mix.betaMoment(a, b, 1)
        M2 = mix.betaMoment(a, b, 2)
        print("a, b parameters are %0.1f and %0.1f." % (a, b))
        print("Targeted: %0.4f and calibrated: %0.4f default probability." %
              (myP, M1))
        print("Targeted: %0.3f and calibrated: %0.3f default correlation." %
              (rhoTarget, np.divide(M2 - M1**2, M1 - M1**2)))
        el, ul, var, es = mix.betaBinomialSimulation(N, M, C, a, b, alpha)
        simTime = (time.time() - startTime)
    elif modelType == 3:  # t-distributed threshold model
        el, ul, var, es = th.oneFactorThresholdModel(N, M, P, C, myRho, nu,
                                                     alpha, 1)
        simTime = (time.time() - startTime)
    elif modelType == 4:  # Basel IRB approach
        mAdjustedC = np.multiply(C, getMaturityAdjustment(tenor, P))
        el = np.dot(P, mAdjustedC)
        var = getBaselRiskCapital(P, tenor, C, alpha)
        ul = np.sum(P * (1 - P) * mAdjustedC)
        es = var
        simTime = (time.time() - startTime)
    elif modelType == 5:  # Asymptotic Gaussian threshold model (ASRF)
        meanP = np.maximum(0.0009, np.median(P))
        a, b = th.getAsrfMoments(meanP, myRho)
        el = np.sum(C) * a
        ul = np.sum(C) * b
        pdf, cdf, var, es = th.asrfModel(meanP, myRho, C, alpha)
        simTime = (time.time() - startTime)
    return el, ul, var, es, simTime
Example #2
0
# Set aside some memory
el = np.zeros([numberOfModels])
ul = np.zeros([numberOfModels])
var = np.zeros([len(alpha), numberOfModels])
es = np.zeros([len(alpha), numberOfModels])
cTime = np.zeros(numberOfModels)
a = np.zeros(numberOfModels)
b = np.zeros(numberOfModels)
M1 = np.zeros(numberOfModels)
M2 = np.zeros(numberOfModels)
print("Running BINOMIAL MODEL")
# (a) Calibrate
M1[0], M2[0] = mix.calibrateVerify(a[0], b[0], myP, myRho, 0)
# (b) Simulate
startTime = time.perf_counter()
el[0], ul[0], var[:, 0], es[:, 0] = bp.independentBinomialSimulation(N, M, p, c, alpha)
cTime[0] = time.perf_counter() - startTime
print("Running BETA-BINOMIAL MODEL")
# (a) Calibrate
a[1], b[1] = mix.betaCalibrate(myP, myRho)
M1[1], M2[1] = mix.calibrateVerify(a[1], b[1], myP, myRho, 1)
# (b) Simulate
startTime = time.perf_counter()
el[1], ul[1], var[:, 1], es[:, 1] = mix.betaBinomialSimulation(
    N, M, c, a[1], b[1], alpha
)
cTime[1] = time.perf_counter() - startTime
print("Running LOGIT-NORMAL MODEL")
# (a) Calibrate
logit = scipy.optimize.fsolve(
    mix.logitProbitCalibrate, np.array([1, 1]), args=(myP, myRho, 1)