Exemple #1
0
    def skewness(self):
        ans = self.KL_thi(0) / (self.KL_sec(0))**1.5
        return ans

    def kurtosis(self):
        ans = self.KL_for(0) / (self.KL_sec(0))**2 + 3
        return ans

if __name__ == '__main__':

    pf = portfolio_info()
    pf.init_obligor()
    df = pf.df

    cbvpara = CBVmodel()
    cbvpara.CBV3()

    coca = cgf_calculation(pf, cbvpara)
    skew_value = coca.skewness()
    kurt_value = coca.kurtosis()
    coca.KL_sec(0)

    root = coca.QL_root()

    ans_set1 = []
    ans_set2 = []
    spt_set = np.arange(3, 5, 0.05)
    i = 92
    for spt in spt_set:
        ans_set1.append(coca.new_KL_fir(spt, i))
Exemple #2
0
    return contr_df.loc[:, ["varc_mean", "varc_std", "esc_mean", "esc_std"]]


if __name__ == '__main__':

    pathdic = os.path.join(fileDir + '/MCmethod/MCResult/obligor/CBV2/')
    tp = np.arange(0.01, 0.11, 0.01)
    datap = pan.read_csv(os.path.join(pathdic, 'pmc_loss.csv'))
    pmc_ans = pmc_result(datap, tp)
    losshood = np.arange(4.1, 4.35, 0.05)
    datais = pan.read_csv(os.path.join(pathdic, 'ismc_data.csv'))
    ismc_ans = ismc_result(datais, losshood, SINGLE=False)

    pf = portfolio_info()
    pf.init_obligor()
    cbvpara = CBVmodel()
    cbvpara.CBV2()
    coca = cgf_calculation(pf, cbvpara)
    root = coca.QL_root()
    tailprob_set = np.arange(0.001, 0.05, 0.001)
    ans_set = pan.DataFrame(
        columns=["var1", "var2", "var_check", "es1", "es2", "es3", "es_check"])
    init = np.array(2.5, dtype="float")
    for idx, i in enumerate(tailprob_set):
        model = SPAcalculation(coca, est_spt=1.2, est_var=2.5, tailprob=i)
        var1, spt1 = model.solver_tailprob_changeto_VaR_spt()
        var2, spt2 = model.solver_tailprob_changeto_VaR_spt_2nd()
        es1 = model.ES1()
        es2 = model.ES2()
        es3 = model.ES3()
        es4 = minimize(model.check_function, init, method='Nelder-Mead')
                sing_contribution += tp_hat2 * self.gamma[idx_common][
                    idx_sector]

            # put into set
            set_contribution.append(
                (sing_exposure * sing_pd * sing_contribution / tp)[0])

        return set_contribution


if __name__ == '__main__':

    pf = portfolio_info()
    pf.init_rcobligor1()

    cbvpara = CBVmodel()
    cbvpara.CBV1()

    coca = cgf_calculation(pf, cbvpara)
    root = coca.QL_root()

    skew_value = coca.skewness()
    kurt_value = coca.kurtosis()
    coca.KL_sec(0)

    print("the mean of the portfolio loss:", coca.Lmean)
    print("the first order derivative of cgf at t=0:", coca.KL_fir(0))
    print("minimum upper bound of t inside the root of cgf:", root)

    ans_set = []
    spt_set = np.arange(0.01, root - 0.005, 0.05)