示例#1
0
def kill_process():
    ''' When done, stop daemons by sending them SIGINT signal '''
    log.info('Killing process...')
    os.system('killall nodejs')
    os.system('killall R')
    # Check
    show_process()
示例#2
0
def kill_process():
    ''' When done, stop daemons by sending them SIGINT signal '''
    log.info('Killing process...')
    os.system('killall nodejs')
    os.system('killall R')
    # Check
    show_process()
示例#3
0
def main(configuration):
    ''' Setup labo: run shiny webapp frontend and node.js distributed bridge
    Parameters
    ----------
    configuration: dict
        local settings, from config.sh
    Returns
    -------
    None
    '''
    os.system('clear')
    log.info('Building up trade laboratory environment...')
    if configuration['architecture'] == 'local':
        root_path = os.environ['QTRADE']

        log.info('Running remote wrapper for backtest module')
        with log.catch_exceptions():
            os.system('nodejs ' + '/'.join((root_path, 'network', 'server.js' + ' &')))

        log.info('Running remote shiny gui')
        host = 'localhost'
        if configuration['mode'] == 'dev':
            port = '8100'
            app_path = ''
            with log.catch_exceptions():
                os.system('R -q -e "shiny::runApp(\\\"{}/network/shiny-backtest\\\")" &'.format(root_path))
        elif configuration['mode'] == 'prod':
            # Use node.js shiny-server module to ensure public and reliable webapp deployment
            port = '3838'
            app_path = '/users/xavier/shiny-backtest'
            with log.catch_exceptions():
                os.system('sudo ' + '/'.join((root_path, 'network', 'node_modules', '.bin', 'shiny-server')) + ' ' +
                              '/'.join((root_path, 'network', 'shiny-server.config')))
            log.info('{} mode, turned online shiny on {}{}, port {}'.format(configuration['mode'], host, app_path, port))
        else:
            raise ValueError()

        log.info('Opening web-browser to shiny remote interface')
        time.sleep(3)
        os.system('chromium-browser http://{}:{}{}'.format(host, port, app_path))

    else:
        raise NotImplementedError()
    print('\n\n')
    log.info('Done.')
示例#4
0
def show_process():
    ''' Use system "ps" command to check if server daemons are still running '''
    log.info('Running process:')
    os.system('ps -aux | grep server.js')
    os.system('ps -aux | grep shiny')
示例#5
0
def clear_log():
    ''' Reset log file with a UNIX trick '''
    log.info('Reseting log file')
    os.system('echo "" > ' + os.environ['QTRADE_LOG'])
示例#6
0
if __name__ == '__main__':
    # use 'setup' configuration for logging
    with remote_setup.applicationbound():
        '''-------------------------------------------------------------------------------------------    Backtest    ----'''
        # Backtest or live engine used
        engine  = Simulation()

        # 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,
示例#7
0
def main(configuration):
    ''' Setup labo: run shiny webapp frontend and node.js distributed bridge
    Parameters
    ----------
    configuration: dict
        local settings, from config.sh
    Returns
    -------
    None
    '''
    os.system('clear')
    log.info('Building up trade laboratory environment...')
    if configuration['architecture'] == 'local':
        root_path = os.environ['QTRADE']

        log.info('Running remote wrapper for backtest module')
        with log.catch_exceptions():
            os.system('nodejs ' + '/'.join((root_path, 'network', 'server.js' + ' &')))

        log.info('Running remote shiny gui')
        host = 'localhost'
        if configuration['mode'] == 'dev':
            port = '8100'
            app_path = ''
            with log.catch_exceptions():
                os.system('R -q -e "shiny::runApp(\\\"{}/network/shiny-backtest\\\")" &'.format(root_path))
        elif configuration['mode'] == 'prod':
            # Use node.js shiny-server module to ensure public and reliable webapp deployment
            port = '3838'
            app_path = '/users/xavier/shiny-backtest'
            with log.catch_exceptions():
                os.system('sudo ' + '/'.join((root_path, 'network', 'node_modules', '.bin', 'shiny-server')) + ' ' +
                              '/'.join((root_path, 'network', 'shiny-server.config')))
            log.info('{} mode, turned online shiny on {}{}, port {}'.format(configuration['mode'], host, app_path, port))
        else:
            raise ValueError()

        log.info('Opening web-browser to shiny remote interface')
        time.sleep(3)
        os.system('chromium-browser http://{}:{}{}'.format(host, port, app_path))

    else:
        raise NotImplementedError()
    print('\n\n')
    log.info('Done.')
示例#8
0
def show_process():
    ''' Use system "ps" command to check if server daemons are still running '''
    log.info('Running process:')
    os.system('ps -aux | grep server.js')
    os.system('ps -aux | grep shiny')
示例#9
0
def clear_log():
    ''' Reset log file with a UNIX trick '''
    log.info('Reseting log file')
    os.system('echo "" > ' + os.environ['QTRADE_LOG'])