Ejemplo n.º 1
0
def run(name, constructor):
    with scheduler.create() as world:
        
        ctx = Context(world, veusz.Graph)
        traders = constructor(ctx)
        
        books = orderBooksToRender(ctx, traders)
        
        for t in traders + books:
            for ts in t.timeseries:
                ts.graph.addTimeSerie(ts)
        
        r = registry.create()
        root = registry.Simulation(traders, list(ctx.books.itervalues()), ctx.graphs)
        r.insert(root)
        r.pushAllReferences()
        context.bind(root, {'world' : world })
        
        world.workTill(500)
        
        non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]
        
        veusz.render(name, non_empty_graphs)
        
        world._reset()
        context.reset(root)

        if runTwoTimes:
            world.workTill(500)
            veusz.render(name, non_empty_graphs)
Ejemplo n.º 2
0
def run(name, constructor, only_veusz):
    with scheduler.create() as world:

        ctx = Context(world, veusz.Graph)
        traders = constructor(ctx)

        if config.useMinorTraders:
            traders.extend([
                ctx.makeMinorTrader(strategy.RSI_linear(k=const(0.07)),
                                    "RSI 0.07"),
                ctx.makeMinorTrader(strategy.RSI_linear(k=const(-0.07)),
                                    "RSI -0.07"),
                ctx.makeMinorTrader(
                    strategy.Bollinger_linear(alpha=0.15, k=const(-0.5)),
                    "Bollinger -0.5"),
                ctx.makeMinorTrader(
                    strategy.Bollinger_linear(alpha=0.15, k=const(+0.5)),
                    "Bollinger +0.5"),
            ])

        books = orderBooksToRender(ctx, traders)

        for t in traders + books:
            for ts in t.timeseries:
                ts.graph.addTimeSerie(ts)

        r = registry.create()
        root = registry.Simulation(traders, list(ctx.books.itervalues()),
                                   ctx.graphs)
        r.insert(root)
        r.pushAllReferences()
        context.bind(root, {'world': world})

        def checks():
            if not only_veusz and config.checkConsistency:
                r.typecheck()
                try:
                    dumped = pickle.dumps(r)
                    pickle.loads(dumped)
                except Exception, err:
                    print err

        checks()
        stat = world.workTill(500)
        checks()

        if config.showTiming:
            print "\n", stat

        non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]

        veusz.render(name, non_empty_graphs)

        world._reset()
        context.reset(root)

        if False and config.runTwoTimes:
            world.workTill(500)
            veusz.render(name, non_empty_graphs)
Ejemplo n.º 3
0
def run(name, constructor, only_veusz):
    with createScheduler() as world:

        import time
        t0 = time.clock()
        
        ctx = Context(world, veusz.Graph)
        print time.clock() - t0
        traders = constructor(ctx)
        print time.clock() - t0

        if config.useMinorTraders:
            traders.extend([
                ctx.makeMinorTrader(strategy.position.RSI_linear(k = const(0.7)).Strategy(), "RSI 0.07"),
                ctx.makeMinorTrader(strategy.position.RSI_linear(k = const(-0.7)).Strategy(), "RSI -0.07"),
                ctx.makeMinorTrader(strategy.position.Bollinger_linear(alpha=0.15, k = const(-5.)).Strategy(), "Bollinger -0.5"),
                ctx.makeMinorTrader(strategy.position.Bollinger_linear(alpha=0.15, k = const(+5.)).Strategy(), "Bollinger +0.5"),
            ])
        
        books = orderBooksToRender(ctx, traders)
        
        r = registry.create()
        root = registry.Simulation(traders, list(ctx.books.itervalues()), ctx.graphs)
#        r.insert(root)
        print time.clock() - t0
        root.registerIn(r)
#        r.pushAllReferences()
        print time.clock() - t0
        root.bind_ex(context.BindingContextEx({'world' : world }))

        def checks():
            if not only_veusz and config.checkConsistency:
                r.typecheck()
                try:
                    dumped = pickle.dumps(r)
                    pickle.loads(dumped)
                except Exception, err:
                    print err

        print time.clock() - t0

        checks()        
        stat = world.workTill(config.veuszRunLength)
        checks()        

        if config.showTiming:
            print "\n", stat
        
        non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]
        
        veusz.render(name, non_empty_graphs)
        
        world.reset_ex(0)
        root.reset_ex(0)

        if config.runTwoTimes:
            world.workTill(config.veuszRunLength)
            veusz.render(name, non_empty_graphs)
Ejemplo n.º 4
0
def run(name, constructor, only_veusz):
    with scheduler.create() as world:
        
        ctx = Context(world, veusz.Graph)
        traders = constructor(ctx)

        if config.useMinorTraders:
            traders.extend([
                ctx.makeMinorTrader(strategy.RSI_linear(k = const(0.07)), "RSI 0.07"),
                ctx.makeMinorTrader(strategy.RSI_linear(k = const(-0.07)), "RSI -0.07"),
                ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(-0.5)), "Bollinger -0.5"),
                ctx.makeMinorTrader(strategy.Bollinger_linear(alpha=0.15, k = const(+0.5)), "Bollinger +0.5"),
            ])
        
        books = orderBooksToRender(ctx, traders)
        
        for t in traders + books:
            for ts in t.timeseries:
                ts.graph.addTimeSerie(ts)
        
        r = registry.create()
        root = registry.Simulation(traders, list(ctx.books.itervalues()), ctx.graphs)
        r.insert(root)
        r.pushAllReferences()
        context.bind(root, {'world' : world })
                    
        if False:
            req = request.EvalMarketOrder(Side.Sell, 500, _print)
            world.schedule(10, _(ctx.remote_A, req).process)
        
        def checks():
            if not only_veusz and config.checkConsistency:
                r.typecheck()
                try:
                    dumped = pickle.dumps(r)
                    pickle.loads(dumped)
                except Exception, err:
                    print err

        checks()        
        stat = world.workTill(500)
        checks()        

        if config.showTiming:
            print "\n", stat
        
        non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]
        
        veusz.render(name, non_empty_graphs)
        
        world._reset()
        context.reset(root)

        if False and config.runTwoTimes:
            world.workTill(500)
            veusz.render(name, non_empty_graphs)
Ejemplo n.º 5
0
def run(name, constructor, only_veusz):
    with createScheduler() as world:

        import time
        t0 = time.clock()

        ctx = Context(world, veusz.Graph)
        print time.clock() - t0
        traders = constructor(ctx)
        print time.clock() - t0

        if config.useMinorTraders:
            traders.extend([
                ctx.makeMinorTrader(
                    strategy.position.RSI_linear(k=const(0.7)).Strategy(),
                    "RSI 0.07"),
                ctx.makeMinorTrader(
                    strategy.position.RSI_linear(k=const(-0.7)).Strategy(),
                    "RSI -0.07"),
                ctx.makeMinorTrader(
                    strategy.position.Bollinger_linear(
                        alpha=0.15, k=const(-5.)).Strategy(),
                    "Bollinger -0.5"),
                ctx.makeMinorTrader(
                    strategy.position.Bollinger_linear(
                        alpha=0.15, k=const(+5.)).Strategy(),
                    "Bollinger +0.5"),
            ])

        books = orderBooksToRender(ctx, traders)

        r = registry.create()
        root = registry.Simulation(traders, list(ctx.books.itervalues()),
                                   ctx.graphs)
        #        r.insert(root)
        print time.clock() - t0
        root.registerIn(r)
        #        r.pushAllReferences()
        print time.clock() - t0
        root.bind_ex(context.BindingContextEx({'world': world}))

        def checks():
            if not only_veusz and config.checkConsistency:
                r.typecheck()
                try:
                    dumped = pickle.dumps(r)
                    pickle.loads(dumped)
                except Exception, err:
                    print err

        print time.clock() - t0

        checks()
        stat = world.workTill(config.veuszRunLength)
        checks()

        if config.showTiming:
            print "\n", stat

        non_empty_graphs = [g for g in ctx.graphs if len(g._datas)]

        veusz.render(name, non_empty_graphs)

        world.reset_ex(0)
        root.reset_ex(0)

        if config.runTwoTimes:
            world.workTill(config.veuszRunLength)
            veusz.render(name, non_empty_graphs)
Ejemplo n.º 6
0
        lp_A = trader.SingleAsset(book_A,  
                           strategy.LiquidityProvider(volumeDistr=volume(10)), 
                           "A"+i)
        
        lp_a = trader.SingleAsset(book_A,  
                           strategy.LiquidityProvider(volumeDistr=volume(1)),
                           "a"+i)
        
        for t in [lp_A, lp_a]: t.run()
        
        spread_graph += [observable.BidPrice(book_A), 
                         observable.AskPrice(book_A)]
        
        eff_graph += [observable.Efficiency(lp_a),
                      observable.PnL(lp_a)]
        
def createJob(i):
    world = scheduler.create()
    createSimulation(world, str(i))
    world.workTill(500)

threads = [threading.Thread(target=createJob, args=(i,)) for i in range(N)]

for t in threads:
    t.start()

for t in threads:
    t.join()

veusz.render("threading", [price_graph, spread_graph, eff_graph])