Ejemplo n.º 1
0
        # Read local (.cfg files and command line args) or remote (ZMQ Messages) backtest, algorithm and manager configuration
        args    = engine.configure()

        # See neuronquant/calculus/engine.py or zipline for details on results dataframe
        results = engine.run_backtest()

        '''---------------------------------------------------------------------------------------------    Results   ----'''
        log.info('Portfolio returns: {}'.format(results.portfolio_value[-1]))

        if args['live'] or results.portfolio_value[-1] == 100000:
            # Currently tests don't last more than 20min, analysis is not relevant, neither backtest without orders
            sys.exit(0)

        #TODO Implement in datafeed a generic save method (which could call the correct database save method)
        #NOTE Could do a generic save client method (retrieve the correct model, with correct fields)
        perf_series  = engine.rolling_performances(timestamp='one_month', save=False, db_id='test')
        #TODO save returns not ready yet, don't try to save
        #TODO more benchmarks choice (zipline modification)
        returns_df   = engine.get_returns(benchmark='SP500', save=False)
        risk_metrics = engine.overall_metrics(save=True, db_id='test')

        log.info('\n\nReturns: {}% / {}%\nVolatility:\t{}\nSharpe:\t\t{}\nMax drawdown:\t{}\n\n'.format(
                 risk_metrics['Returns'] * 100.0,
                 risk_metrics['Benchmark.Returns'] * 100.0,
                 risk_metrics['Volatility'],
                 risk_metrics['Sharpe.Ratio'],
                 risk_metrics['Max.Drawdown']))

        # If we work in local, draw a quick summary plot
        if not args['remote']:
            data = returns_df.drop(['Returns', 'Benchmark.Returns'], axis=1)
Ejemplo n.º 2
0
        # Read local (.cfg files and command line args) or remote (ZMQ Messages) backtest, algorithm and manager configuration
        args    = engine.configure()

        # See neuronquant/calculus/engine.py or zipline for details on results dataframe
        results = engine.run_backtest()

        '''---------------------------------------------------------------------------------------------    Results   ----'''
        log.info('Portfolio returns: {}'.format(results.portfolio_value[-1]))

        if args['live'] or results.portfolio_value[-1] == 100000:
            # Currently tests don't last more than 20min, analysis is not relevant, neither backtest without orders
            sys.exit(0)

        #TODO Implement in datafeed a generic save method (which could call the correct database save method)
        #NOTE Could do a generic save client method (retrieve the correct model, with correct fields)
        perf_series  = engine.rolling_performances(timestamp='one_month', save=True, db_id=args['database'])
        #TODO save returns not ready yet, don't try to save
        #TODO more benchmarks choice (zipline modification)
        returns_df   = engine.get_returns(benchmark='^GSPC', save=False)
        risk_metrics = engine.overall_metrics(save=True, db_id=args['database'])

        #FIXME irrelevant results if no transactions were made
        log.info('\n\nReturns: {}% / {}%\nVolatility:\t{}\nSharpe:\t\t{}\nMax drawdown:\t{}\n\n'.format(
                 risk_metrics['Returns'] * 100.0,
                 risk_metrics['Benchmark.Returns'] * 100.0,
                 risk_metrics['Volatility'],
                 risk_metrics['Sharpe.Ratio'],
                 risk_metrics['Max.Drawdown']))

        # If we work in local, draw a quick summary plot
        if not args['remote']: