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
model_TVaR.setObjective( 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:
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),
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),
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
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
'skyblue', 'crimson'] ####################################################################################################################### # # todo parameter setting work_dir_name = '1512macro/' accumulated_dir = './accumulated_data/' + work_dir_name # all data is class type accumulated_dir_risk_metric = './risk_metrics/' + work_dir_name global_opt_result = './global_opt_result/' + work_dir_name local_opt_result = './local_opt_result/' + work_dir_name cycle = 100000 alpha = 0.995 # 200yr --> 0.995 100yr --> 0.99 beta = 0.998 MC_cycle = 2000 num_clusters = 5 global_const = [lambda w: ITMC.MCbase(USEQ_list, w, cycle).tvar(alpha) / SGO_USEQ_limit < 1.1, lambda w: ITMC.MCbase(USWS_list, w, cycle).tvar(alpha) / SGO_USWS_limit < 1.1, lambda w: ITMC.MCbase(EUWS_list, w, cycle).tvar(alpha) / SGO_EUWS_limit < 1.1, lambda w: ITMC.MCbase(JPWS_list, w, cycle).tvar(alpha) / SGO_JPWS_limit < 1.1, lambda w: ITMC.MCbase(JPEQ_list, w, cycle).tvar(alpha) / SGO_JPEQ_limit < 1.1, lambda w: ITMC.MCbase(RoW_list, w, cycle).tvar(alpha) / SGO_RoW_limit < 1.1 ] weight_list = list(pd.read_table('weight.txt').columns) # setting of Optimized Variable's name w_initial = [1.] * len(weight_list) w_lower = list(pd.read_table('weight.txt').ix[0, :]) w_upper = list(pd.read_table('weight.txt').ix[1, :]) bnds = np.array([w_lower, w_upper]) Premium_list = [] Loss_list = [] Expense_list = []