def trade(mega_config): ''' One function to rule them all ''' from neuronquant.gears.engine import Simulation from neuronquant.utils.logger import get_nestedlog # General simulation behavior #NOTE Portfolio server setup in Setup() object, #if needed, create it manually here configuration = mega_config['configuration'] strategie = mega_config['strategie'] # Remote: ZMQ based messaging, route logs on the network # (catched by server's broker) log_setup = get_nestedlog(level=configuration['loglevel'], file=configuration['logfile']) with log_setup.applicationbound(): # Backtest or live engine engine = Simulation(configuration) # Setup quotes data and financial context (location, market, ...) # simulation from user parameters Wrap _configure_data() and # _configure_context() you can use directly for better understanding data, trading_context = engine.configure() # See neuronquant/gears/engine.py for details of results which is an # analyzes object analyzes = engine.run(data, configuration, strategie, trading_context) assert analyzes
'''__________________________________________________________________ Setup ____''' # Dedicated object for configuration setup setup = Setup() # General simulation behavior is defined using command line arguments configuration = setup.parse_commandline() # Color_setup : Pretty print of errors, warning, and so on # Remote_setup: ZMQ based messaging, route logs on the network # (catched by server's broker) #TODO Parametric log handler and level #log_setup = (utils.remote_setup if configuration['remote'] else #utils.color_setup) #FIXME Remote log broken here log_setup = get_nestedlog(level=configuration['loglevel'], filename=configuration['logfile']) with log_setup.applicationbound(): ''' TODO HUGE: Run multiple backtest with communication possibilities (ZMQ) for sophisticated multiple strategies strategy - Available capital allocation import ipdb; ipdb.set_trace() # XXX BREAKPOINT - Strategies repartition - Use of each-other signals behavior - Global monitoring and evaluation ''' # Fill strategie and manager parameters # Localy, reading configuration file # Remotely, listening gor messages through zmq socket strategie = setup.get_strategie_configuration(remote=configuration['remote'])
#TODO Externalize tests def server_test(): server = ZMQ_Server() server.run_forever(ports=5555, on_recv=handle_json) def client_test(): client = ZMQ_Client(timeout=5) client.connect(host='localhost', ports=[5555, 5555, 5555]) for request in range(1, 5): reply = client.send('Hello', acknowledgment=True) assert(reply) def dealer_test(): client = ZMQ_Dealer(id='client_test') client.run(host='127.0.0.1', port=5570) client.receive() for request in range(2): client.noblock_recv() time.sleep(0.5) client.send('test number {}'.format(request), channel='dashboard', json=True) client.send_to_android({'title': 'Buy signal on google', 'priority': 4, 'description': 'Google dual moving average crossed: you should buy 23 stocks with a risk of 0.23'}) if __name__ == '__main__': log_setup = get_nestedlog(uri='tcp://127.0.0.1:5555') with log_setup.applicationbound(): dealer_test()
'''__________________________________________________________________ Setup ____''' # Dedicated object for configuration setup setup = Setup() # General simulation behavior is defined using command line arguments configuration = setup.parse_commandline() # Color_setup : Pretty print of errors, warning, and so on # Remote_setup: ZMQ based messaging, route logs on the network # (catched by server's broker) #TODO Parametric log handler and level #log_setup = (utils.remote_setup if configuration['remote'] else #utils.color_setup) #FIXME Remote log broken here log_setup = get_nestedlog(level=configuration['loglevel'], filename=configuration['logfile']) with log_setup.applicationbound(): ''' TODO HUGE: Run multiple backtest with communication possibilities (ZMQ) for sophisticated multiple strategies strategy - Available capital allocation import ipdb; ipdb.set_trace() # XXX BREAKPOINT - Strategies repartition - Use of each-other signals behavior - Global monitoring and evaluation ''' # Fill strategie and manager parameters # Localy, reading configuration file # Remotely, listening gor messages through zmq socket strategie = setup.get_strategie_configuration(
client.connect(host='localhost', ports=[5555, 5555, 5555]) for request in range(1, 5): reply = client.send('Hello', acknowledgment=True) assert (reply) def dealer_test(): client = ZMQ_Dealer(id='client_test') client.run(host='127.0.0.1', port=5570) client.receive() for request in range(2): client.noblock_recv() time.sleep(0.5) client.send('test number {}'.format(request), channel='dashboard', json=True) client.send_to_android({ 'title': 'Buy signal on google', 'priority': 4, 'description': 'Google dual moving average crossed: you should buy 23 stocks with a risk of 0.23' }) if __name__ == '__main__': log_setup = get_nestedlog(uri='tcp://127.0.0.1:5555') with log_setup.applicationbound(): dealer_test()