Ejemplo n.º 1
0
def run_backest(kwargs):
    try:
        file = kwargs.pop('code')
        with codecs.open(file, 'r', 'utf-8') as f:
            code = f.read()
            f.close()
        user = '******'
        parameters = kwargs.pop('paras')
        start_time = kwargs.pop('start_time')
        end_time = kwargs.pop('end_time')
        symbol = kwargs.pop('symbol')
        time_frame = kwargs.pop('time_frame')
        log = kwargs.pop('log')
        backtest = Backtesting(user, 'test', code, [symbol], time_frame, start_time, end_time)
        if log:
            handle = logging.FileHandler(log, encoding='utf-8')
            logger = logging.getLogger('backtest')
            logger.addHandler(handle)
            logger.setLevel(logging.INFO)
            backtest.set_logger(logger)
        backtest.start(paras=parameters)
        performance = backtest.get_performance()
        result = performance.optimize_info
        temp = pd.Series({signal + '.' + k: v for signal, paras in parameters.items() for k, v in paras.items()})
        result = pd.concat([temp, result])
        backtest.log(backtest.time("绩效计算完毕,耗时:{0}"), logging.INFO)
        return result
    except Exception as e:
        print("Error: {0}, Para: {1}".format(e, parameters))
        print(traceback.format_exc())
        return None
Ejemplo n.º 2
0
def run_backest(**parameters):
    with codecs.open('../test/testcode9.py', 'r', 'utf-8') as f:
        code = f.read()
    user = '******'
    backtest = Backtesting(user, 'test', code, ['EURUSD'], 'M30', '2015-01-02', '2015-03-01')
    backtest.start(paras=parameters)
    performance = backtest.get_performance()
    result = performance.optimize_info
    temp = pd.Series({signal + '.' + k: v for signal, paras in parameters.items() for k, v in paras.items()})
    result = pd.concat([temp, result])
    backtest.log(backtest.time("绩效计算完毕,耗时:{0}"), logging.INFO)
    return result