def cal_funding_reward_HR(pop): fitness = np.zeros([pop.shape[0], 1], float) idx_mtr = np.zeros([pop.shape[0], 6], float) idx_norm = np.zeros([pop.shape[0], 6], float) for i in range(pop.shape[0]): a = "" b = "" c = "" for j in range(10): a = a + str(pop[i, j]) b = b + str(pop[i, j + 10]) c = c + str(pop[i, j + 20]) w_a = int(a, 2) w_b = int(b, 2) w_c = int(c, 2) check_one = w_a + w_b + w_c w_GSPC = w_a / check_one w_SP = w_b / check_one w_USDX = w_c / check_one idx_mtr[i, :] = nv.first_fund(GSPC_path, SP_path, USDX_path, w_GSPC, w_SP, w_USDX).__call__(GSPC_path, SP_path, USDX_path, w_GSPC, w_SP, w_USDX) for k in range(idx_mtr.shape[1]): if (idx_mtr[:, k].max() - idx_mtr[:, k].min()) == 0: idx_norm[:, k] = 1 else: idx_norm[:, k] = (idx_mtr[:, k] - idx_mtr[:, k].min()) / ( idx_mtr[:, k].max() - idx_mtr[:, k].min()) for l in range(pop.shape[0]): fitness[l] = idx_norm[l][5] * 0.8 + np.sum(idx_norm[l][0:4]) * 0.2 / 5 return idx_mtr, fitness
def get_idx(weight): idx = nv.first_fund(GSPC_path, SP_path, USDX_path, weight[0], weight[1], weight[2]).__call__(GSPC_path, SP_path, USDX_path, weight[0], weight[1], weight[2]) return idx
# -*- coding: utf-8 -*- """ Created on Sun Dec 29 23:37:37 2019 @author: tc_chien """ import new_vision as nv w_GSPC = 0.5 w_SP = 0.3 w_USDX = 0.2 GSPC_path = "GSPC.csv" SP_path = "SP500BDT.csv" USDX_path = "USDX.csv" idx = nv.first_fund(GSPC_path, SP_path, USDX_path, w_GSPC, w_SP, w_USDX).__call__(GSPC_path, SP_path, USDX_path, w_GSPC, w_SP, w_USDX) print(idx) # idx = [out_dic['sharp'], out_dic['sortino'], out_dic['excess'], out_dic['VAR'], out_dic['E on VaR']] # np.append(idx, out_dic['history'][0]['unrealized gains'][len(out_dic['history'][0]['unrealized gains'])-1]) # print(idx)