Exemplo n.º 1
0
def yt_class_maker(accumulated_dir, df_name):
    pd_pkl_list = os.listdir(accumulated_dir)

    if 'YearTable_class' in pd_pkl_list:
        pass
    else:
        os.mkdir(accumulated_dir + 'YearTable_class')
    if 'YearTable_csv' in pd_pkl_list:
        pass
    else:
        os.mkdir(accumulated_dir + 'YearTable_csv')

    pd_pkl_list_raw = os.listdir(accumulated_dir + 'YearTable_csv')
    if 'raw_csv' in pd_pkl_list_raw:
        pass
    else:
        os.mkdir(accumulated_dir + 'YearTable_csv/raw_csv')

    if df_name + '.pkl' in pd_pkl_list:
        temp = pickle_read(accumulated_dir + df_name + '.pkl')
        # making pickle object of YearTable class
        pickle_write(Ityt.YearTable(np.array(temp), df_name),
                     accumulated_dir + 'YearTable_class/' + df_name + '.pkl')
        # making CSV data from pandas DataFrame
        temp.to_csv(accumulated_dir + 'YearTable_csv/raw_csv/' + df_name +
                    '.csv',
                    sep='\t',
                    index=False)
    else:
        pass
Exemplo n.º 2
0
def csv_to_df_YTclass(accumulated_dir):
    temp_list = os.listdir(accumulated_dir + 'YearTable_csv/raw_csv')
    for i in temp_list:
        df = pd.read_csv(accumulated_dir + 'YearTable_csv/raw_csv/' + i)
        j = i.replace('.csv', '.pkl')
        pickle_write(df, accumulated_dir + j)
        pickle_write(Ityt.YearTable(np.array(df), df.name),
                     accumulated_dir + 'YearTable_class/' + j)
Exemplo n.º 3
0
def obj_func_PSO(w1):
    w1 = list(np.array(w1) * np.array(alpso_weight) + 1.)
    f = Ityt.Uwg(ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
                 ITMC.MCbase(Expense_list, w1, cycle)).rorac(alpha) * -1.
    g = [0.] * 2
    g[0] = Ityt.Uwg(ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
                    ITMC.MCbase(Expense_list, w1, cycle)).xtvar(alpha) - Ityt.Uwg(
        ITMC.MCbase(Premium_list, w_initial, cycle), ITMC.MCbase(Loss_list, w_initial, cycle),
        ITMC.MCbase(Expense_list, w_initial, cycle)).xtvar(alpha)
    g[1] = 0.9 * Ityt.Uwg(ITMC.MCbase(Premium_list, w_initial, cycle), ITMC.MCbase(Loss_list, w_initial, cycle),
                          ITMC.MCbase(Expense_list, w_initial, cycle)).xtvar(alpha) - Ityt.Uwg(
        ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
        ITMC.MCbase(Expense_list, w1, cycle)).xtvar(alpha)
    fail = 0
    print 'obj_value : ', f, ' variable : ', w1
    print 'penalty(negative value is valid) : ', g[0], g[1]
    return f, g, fail
Exemplo n.º 4
0
def GA_const_JandH(w, C_JandH, alpha_JandH, ngen_count, feasible, adjuster):
    xtvar_check = Ityt.Uwg(ITMC.MCbase(Premium_list, w_initial, cycle), ITMC.MCbase(Loss_list, w_initial, cycle),
                           ITMC.MCbase(Expense_list, w_initial, cycle)).xtvar(alpha) - Ityt.Uwg(
        ITMC.MCbase(Premium_list, w, cycle), ITMC.MCbase(Loss_list, w, cycle),
        ITMC.MCbase(Expense_list, w, cycle)).xtvar(alpha)
    if abs(xtvar_check) < feasible:
        feasible_ret = 0
    else:
        feasible_ret = (C_JandH * ngen_count) ** alpha_JandH * abs(xtvar_check)

    return feasible_ret * adjuster
Exemplo n.º 5
0
        quicksum(
            Aggregate(x[i], Premium_list_gurobi[i], realization_num) -
            Aggregate(x[i], Loss_list_gurobi[i], realization_num) -
            Aggregate(x[i], Expense_list_gurobi[i], realization_num)
            for i in range(I)) / realization_num, GRB.MAXIMIZE)

    model_TVaR.update()

    model_TVaR.__data = x
    model_TVaR.__data = VaR

    return model_TVaR


default_TVaR = Ityt.Uwg(ITMC.MCbase(Premium_list, w0, cycle),
                        ITMC.MCbase(Loss_list, w0, cycle),
                        ITMC.MCbase(Expense_list, w0, cycle)).xtvar(alpha)

model_TVaR = markowitz_TVaR(I, cycle, default_TVaR, alpha, Premium_list_gurobi,
                            Loss_list_gurobi, Expense_list_gurobi)
model_TVaR.optimize()

status = model_TVaR.Status
if status == GRB.Status.UNBOUNDED or status == GRB.Status.INF_OR_UNBD:
    model_TVaR.setObjective(0, GRB.MAXIMIZE)
    model_TVaR.optimize()
    status = model_TVaR.Status
if status == GRB.Status.OPTIMAL:
    print 'UNbounded'
elif status == GRB.Status.INFEASIBLE:
    print 'Infeasible'
Exemplo n.º 6
0
def obj_func_ga_initial(w1):
    return Ityt.Uwg(ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
                    ITMC.MCbase(Expense_list, w1, cycle)).rorac(alpha),
Exemplo n.º 7
0
def obj_func_ga(w1, ngen_count):
    return Ityt.Uwg(ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
                    ITMC.MCbase(Expense_list, w1, cycle)).rorac(alpha) - GA_const_JandH(w1, C_JandH,
                                                                                        alpha_JandH,
                                                                                        ngen_count, feasible,
                                                                                        adjuster),
Exemplo n.º 8
0
def obj_func(w1):
    return (Ityt.Uwg(ITMC.MCbase(Premium_list, w1, cycle), ITMC.MCbase(Loss_list, w1, cycle),
                     ITMC.MCbase(Expense_list, w1, cycle)).uwg_mean() - (Risk_charge * np.array(w1)).sum()) * -1. / total_capital
Exemplo n.º 9
0
            axes[1].xaxis.set_major_formatter(ptick.ScalarFormatter(useMathText=True))
            axes[1].yaxis.set_major_formatter(ptick.ScalarFormatter(useMathText=True))
            axes[1].ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
            axes[1].tick_params(labelsize=9)
            result_w = []  # result of allocation
            result_uwg = []  # Uwg class list
            result_uwg_mean = []
            result_xtvar = []

            for i in range(MC_cycle):
                w = ITMC.weight_gen(w_lower, w_upper)
                if ITMC.constraints(global_const, w):
                    result_w.append(w)

                    result_uwg.append(
                        Ityt.Uwg(ITMC.MCbase(Premium_list, w, cycle), ITMC.MCbase(Loss_list, w, cycle),
                                 ITMC.MCbase(Expense_list, w, cycle)))
                    uwg_mean_temp = Ityt.Uwg(ITMC.MCbase(Premium_list, w, cycle), ITMC.MCbase(Loss_list, w, cycle), ITMC.MCbase(Expense_list, w, cycle)).uwg_mean()
                    xtvar_temp = Ityt.peril_allocation(Loss_list, w, cycle).xtvar(alpha)

                    xtvar_temp = Ityt.peril_allocation(Loss_list, w, cycle).xtvar(alpha)
                    result_uwg_mean.append(uwg_mean_temp)
                    result_xtvar.append(xtvar_temp)
                    print('%d th \t uwg_mean : %d \t\t XTVaR \t : %d' % (i + 1, int(uwg_mean_temp), int(xtvar_temp)))
                    axes[0].plot(uwg_mean_temp, xtvar_temp, 'o', ms=4, color=mklist[0])
                else:
                    print('\n data is in the infeasible region . \n')

            glabel = ITMC.clustering(result_uwg_mean, result_xtvar, num_clusters, result_w, global_opt_result)
            for i in range(num_clusters):
                axes[1].plot(np.array(result_uwg_mean)[glabel == i], np.array(result_xtvar)[glabel == i], 'o',
                             color=mklist[i + 1],