Esempio n. 1
0
def portfolio_bounds(er, variance_bound, u_bounds, extended_return=True):
    logging.info("Initialize and calculate variance bound portfolio with bounded portfolio weights.")
    n = er.shape[1]
    mu = ps.first_moment(er)
    sigma = ps.covariance(er)
    sol = eval_portfolio_bounds(mu, sigma, variance_bound, u_bounds)

    logging.info("Solution = {0}".format(sol))
    if extended_return:
        return sol
    else:
        return sol[0]
Esempio n. 2
0
def portfolio_logbar(er, variance_bound, extended_return=True):
    logging.info("Initialize parameters and calculate variance bound portfolio.")
    n = er.shape[1]
    mu = ps.first_moment(er)
    sigma = ps.covariance(er)
    sol = eval_portfolio_logbar(mu, sigma, variance_bound)

    logging.info("Solution = {0}".format(sol))
    if extended_return:
        return sol
    else:
        return sol[0]
Esempio n. 3
0
def bench_exact_hess(x):
    test_prob.eval_hess_bar_g(x)
    

def benchmark_fd_exact_hess_bar_g():
    print(timeit.timeit('bench_fd_hess()', setup='from dccsupport import bench_fd_hess',
                        number=1000))
    print(timeit.timeit('bench_exact_hess()', setup='from dccsupport import bench_exact_hess',
                        number=1000))



# test_xm = np.concatenate([np.array([[ -1.3125 ,  -1.125  ,  -1.0625 ,  -0.5625 ],
#                                     [ -1.125  ,  -1.8125 ,  -1.25   ,  -0.90625],
#                                     [ -1.0625 ,  -1.25   ,  -1.3125 ,  -0.625  ],
#                                     [ -0.5625 ,  -0.90625,  -0.625  ,  -1.025  ]]).reshape(-1),
#                           np.array([0.1667, 0.3333, 0.5])]) / 10.

# test_xm = init_tau(test_xm, 3, 1)/100.
# test_xm_extended = init_tau(test_xm, 3, 2)/100.

if __name__ == '__main__':
    test_er = loaddata.load_fama_french_10_industry().values[-300:, :3]
    mu, sigma = ps.first_moment(test_er), ps.covariance(test_er)
    # mu, P = ps.shrinkage_moments(test_er.values[300:,:3], bootstrap_size=100)
    variance_bound = 0.03
    u_bounds = {'lower': -0.1*np.ones(3), 'upper': 0.5*np.ones(3)}
    test_prob = MVProblem(mu, sigma, variance_bound, u_bounds)
    # test_prob_extended = DccSupportProblem(mu, P, s, y, eta, extended_Ws)
Esempio n. 4
0
def portfolio(excess_returns, mean_weight):
    mu = ps.first_moment(excess_returns)
    sigma = ps.covariance(excess_returns)

    return mean_weight * 0.5 * la.solve(sigma, mu)