예제 #1
0
def eval_scenario(returns_params, backtest_params, portfolio_params):
    excess_returns = data.load_excess_returns(**returns_params)
    
    # Setup backtest return splits.
    training_returns, testing_returns = (
        backtest.split_returns(excess_returns, **backtest_params))
    
    results = list()
    period = 0
    for er_train, er_test in zip(training_returns, testing_returns):
        sol = mvportfolio.portfolio(
            er_train,
            **portfolio_params)
            
        portfolio = sol
        returns = er_test.dot(portfolio)
        result = {'portfolio': array2str(portfolio)}
        result['test_returns'] = array2str(returns)
        result['period'] = period
        period += 1
        
        results.append(result)
        logging.debug('period = {0}'.format(period))        
    
    return {'kwargs': {'returns': returns_params,
                       'backtest': backtest_params,
                       'portfolio': portfolio_params},
            'results': results}
예제 #2
0
def eval_scenario(returns_params, backtest_params, portfolio_params):
    excess_returns = data.load_excess_returns(**returns_params)
    
    # Setup backtest return splits.
    training_returns, testing_returns = (
        backtest.split_returns(excess_returns, **backtest_params))
    
    results = list()
    period = 0
    for er_train, er_test in zip(training_returns, testing_returns):
        try:
            sol = dccportfolio.portfolio_sphere(
                er_train, 
                extended_return=True, verbose=False, 
                **portfolio_params)
        except LinAlgError:
            logging.error('Linear algebra error encountered.')        
            sol = ('', '', '', '', 'linear_algebra_error')
            
        portfolio = sol[0]
        status = sol[4]

        if status == 'solution_found':
            returns = er_test.dot(portfolio)
        else:
            returns = ''
        
        sol_keys = ['portfolio', 'objective', 'sdp_solution', 'constraints', 'status']
        result = {
            k: pg.array2str(s) 
            for k, s in zip(sol_keys, sol)
        }
        result['test_returns'] = pg.array2str(returns)
        result['period'] = period        
        period += 1
        
        results.append(result)
        logging.debug('period = {0}'.format(period))        
    
    return {'kwargs': {'returns': returns_params,
                       'backtest': backtest_params,
                       'portfolio': portfolio_params},
            'results': results}
예제 #3
0
파일: dcc.py 프로젝트: venuur/dissertation
def eval_scenario(returns_params, portfolio_params):
    excess_returns = data.load_excess_returns(**returns_params)
    
    try:
        sol = dccportfolio.portfolio_sphere(
            excess_returns, 
            extended_return=True, verbose=False, 
            **portfolio_params)
    except LinAlgError:
        logging.error('Linear algebra error encountered.')        
        sol = ('', '', '', '', 'linear_algebra_error')
                                        
    sol_keys = ['portfolio', 'obj', 'sdp_solution', 'g', 'status']
    
    result = {
        k: pg.array2str(s) 
        for k, s in zip(sol_keys, sol)
    }
    
    return {
        'kwargs': {
            'returns': returns_params,
            'portfolio': portfolio_params},
        'result': result}