Example #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)
Example #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)
def reset():
    w = current_user_workspace()
    save_state_before_changes(w.registry)
    with w.world: 
        w.world._reset()
        context.reset(w.registry.get(w.root))
    save_current_workspace()
    return changes(w)
Example #4
0
def reset():
    w = current_user_workspace()
    save_state_before_changes(w.registry)
    with w.world: 
        w.world._reset()
        context.reset(w.registry.get(w.root))
    save_current_workspace()
    return changes(w)
Example #5
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)
Example #6
0
 def _update(self, _):
     x = self.source()
     if x is not None:
         if self._open is None:
             self._open = x
             self._max = x
             self._min = x
             context.reset(self._mean)
             context.reset(self._stddev)
         if self._min > x: self._min = x
         if self._max < x: self._max = x
         self._close = x
 def _update(self, _):        
     x = self.source()
     if x is not None:
         if self._open is None:
             self._open = x
             self._max = x
             self._min = x
             context.reset(self._mean)
             context.reset(self._stddev)
         if self._min > x: self._min = x
         if self._max < x: self._max = x
         self._close = x