Example #1
0
def eval_portfolio_sphere_bounds(y, mu, P, s, eta, Ws, u_bounds):
    logging.info('Radius = {0}'.format(Ws[0, -1, -1]))
    logging.debug('Ws = {0}'.format(Ws))
    init_sol = gen_init_sol_sphere(y, eta, s, P, -Ws[0, -1, -1])
    prob = dccsupport_bounds.DccSupportProblem(mu, P, s, y, eta, Ws, u_bounds)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, 9*6)
    return eval_solution(sol, prob)
Example #2
0
def eval_portfolio_logbar(mu, sigma, variance_bound):
    logging.info("Solving for optimal variance bound portfolio.")
    logging.info("Variance_bound = {0}".format(variance_bound))
    init_sol = np.zeros(len(mu))
    # init_sol = np.ones(len(mu))
    prob = mv.MVProblem(mu, sigma, variance_bound)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, (1 + len(mu)) * 6)
    return eval_solution(sol, prob)
Example #3
0
def eval_portfolio_sphere(y, mu, P, s, eta, Ws, verbose):
    logging.info('Radius = {0}'.format(Ws[0, -1, -1]))
    logging.debug('Ws = {0}'.format(Ws))
    init_sol = gen_init_sol_sphere(y, eta, s, P, -Ws[0, -1, -1])
    prob = dccsupport.DccSupportProblem(mu, P, s, y, eta, Ws)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, 2*(len(mu)+1),
                                   verbose=verbose)
    return eval_solution(sol, prob)
Example #4
0
def base_portfolio_extended(er, y, s, eta):
    n = er.shape[1]
    N = n+1
    mu = ps.first_moment(er)
    P = ps.second_moment(er)
    init_sol = find_initial_solution(s, mu, P)
    prob = dccbase.DccBaseDetFormProblem(mu, P, s, y, eta)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.05, 9*6, using_finite_differences=True)
    logging.info('Solution = {0}'.format(sol))
    return sol[-n:], prob.eval_f(sol), sol, prob.eval_g(sol)
Example #5
0
def base_portfolio(er, s, eta, y):
    n = er.shape[1]
    N = n+1
    mu = ps.first_moment(er)
    P = ps.second_moment(er)
    init_sol = find_initial_solution(s, mu, P)
    prob = dccbase.DccBaseProblem(mu, P, s, y, eta)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, 2*N)
    logging.info('Solution = {0}'.format(sol))
    return sol[-n:]
Example #6
0
def portfolio_unconstrained(er, y, s, eta):
    n = er.shape[1]
    N = n+1
    mu = ps.first_moment(er)
    P = ps.second_moment(er)
    init_sol = gen_init_sol_sphere(y, eta, s, P)
    Ws = np.zeros((N,N)).reshape((1,N,N)) # No support constraint.
    prob = dccsupport.DccSupportProblem(mu, P, s, y, eta, Ws)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, 9*6)
    logging.info('Solution = {0}'.format(sol))
    return sol[-n:], prob.eval_f(sol), sol, prob.eval_g(sol)
Example #7
0
def portfolio_sphere_extended_fd(er, y, s, eta):
    n = er.shape[1]
    N = n+1
    mu = ps.first_moment(er)
    P = ps.second_moment(er)
    init_sol = gen_init_sol_sphere(y, eta, s, P)
    Ws = np.eye(N).reshape((1,N,N))
    Ws[-1] *= -1                # Radius of 1.
    prob = dccsupport.DccSupportProblem(mu, P, s, y, eta, Ws)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.05, 9*6, using_finite_differences=True)
    logging.info('Solution = {0}'.format(sol))
    return sol[-n:], prob.eval_f(sol), sol, prob.eval_g(sol)
Example #8
0
def eval_portfolio_bounds(mu, sigma, variance_bound, u_bounds):
    logging.info("Solving for optimal variance bound portfolio with bounded portfolio weights.")
    logging.info("Variance_bound = {0}".format(variance_bound))
    # init_sol = eval_portfolio_logbar(mu, sigma, variance_bound)[0]
    # if (any((init_sol - u_bounds['lower']) < 1e-6)
    #     or any((u_bounds['upper'] - init_sol) < 1e-6)):
    #     print 'DEBUG: unconstrained portfolio not feasible'
    #     print init_sol - u_bounds['lower']
    #     print u_bounds['upper'] - init_sol
    init_sol = np.zeros(len(mu))
    # init_sol = np.array([(lb + ub) / 2.0
    #                      for lb, ub in zip(u_bounds['lower'], u_bounds['upper'])])
    logging.info("Initial solution = {0}".format(init_sol))
    prob = mv_bounds.MVProblem(mu, sigma, variance_bound, u_bounds)
    sol = logbar.solve_log_barrier(init_sol, prob, 0.001, (1 + len(mu)) * 6)
    return eval_solution(sol, prob)