示例#1
0
def createSimulation(name='All'):
    
    with scheduler.create() as world:
        
        myRegistry = registry.create()
    
        myRegistry.insert(Side.Sell)
        myRegistry.insert(Side.Buy)    
        ctx = Context(world, js.Graph)
        dependency = strategy.v0.Dependency(ctx.book_B)
        dependency_ex = strategy.Dependency(event.Every(mathutils.rnd.expovariate(1.)),
                                            order.factory.side.Market(), 
                                            ctx.book_B)
        
        def register(annotated_objects):
            for obj, alias in annotated_objects:
                if alias is not None:
                    obj._alias = alias
                myRegistry.insert(obj)
                
        register([
                  (dependency, ["Basic", "Dependency"]),
                  (dependency_ex, None),
        ])
        
        myRegistry.pushAllReferences()

        def process(name):
            constructor = predefined[name]
        
            traders = constructor(ctx)

            books = orderBooksToRender(ctx, traders)
        
            for t in traders + list(ctx.books.itervalues()) + ctx.graphs:
                myRegistry.insert(t)
                
        if name != 'All':
            process(name)
        else: 
            for n in predefined.iterkeys():
                process(n)
            
        myRegistry.insert(world)
        
        root = myRegistry.insert(registry.createSimulation(myRegistry))
        context.bind(myRegistry.get(root), { "world" : world })

        if name != 'All':
            current_dir = current_user_dir()
            ensure_dir_ex(current_dir)
            
            if os.path.exists(os.path.join(current_dir, name)):
                i = 0
                while os.path.exists(os.path.join(current_dir, name + "." + str(i))): 
                    i += 1
                name += '.' + str(i) 
        
        return name, root, myRegistry, world
示例#2
0
def createSimulation(name='All'):

    with createScheduler() as world:

        myRegistry = registry.create()

        ctx = Context(world, Graph)
        dependency_ex = strategy.side.PairTrading(ctx.book_B)\
                                     .Strategy(event.Every(math.random.expovariate(1.)),
                                               order.side.Market())

        def register(annotated_objects):
            for obj, alias in annotated_objects:
                if alias is not None:
                    obj._alias = alias
                myRegistry.insert(obj)

        register([
            (dependency_ex, None),
        ])

        myRegistry.pushAllReferences()

        def process(name):
            constructor = predefined[name]

            traders = constructor(ctx)

            books = orderBooksToRender(ctx, traders)

            for t in traders + list(ctx.books.itervalues()) + ctx.graphs:
                myRegistry.insert(t)

        if name != 'All':
            process(name)
        else:
            for n in predefined.iterkeys():
                process(n)

        myRegistry.insert(world)

        root = myRegistry.insert(registry.createSimulation(myRegistry))
        from marketsim.context import BindingContextEx
        myRegistry.get(root).bind_ex(BindingContextEx({"world": world}))
        myRegistry.get(root).registerIn(myRegistry)

        if name != 'All':
            current_dir = current_user_dir()
            ensure_dir_ex(current_dir)

            if os.path.exists(os.path.join(current_dir, name)):
                i = 0
                while os.path.exists(
                        os.path.join(current_dir, name + "." + str(i))):
                    i += 1
                name += '.' + str(i)

        return name, root, myRegistry, world
示例#3
0
def createSimulation(name='All'):
    
    with createScheduler() as world:
        
        myRegistry = registry.create()
    
        ctx = Context(world, Graph)
        dependency_ex = strategy.side.PairTrading(ctx.book_B)\
                                     .Strategy(event.Every(math.random.expovariate(1.)),
                                               order.side.Market())
        
        def register(annotated_objects):
            for obj, alias in annotated_objects:
                if alias is not None:
                    obj._alias = alias
                myRegistry.insert(obj)
                
        register([
                  (dependency_ex, None),
        ])
        
        myRegistry.pushAllReferences()

        def process(name):
            constructor = predefined[name]
        
            traders = constructor(ctx)

            books = orderBooksToRender(ctx, traders)
        
            for t in traders + list(ctx.books.itervalues()) + ctx.graphs:
                myRegistry.insert(t)
                
        if name != 'All':
            process(name)
        else: 
            for n in predefined.iterkeys():
                process(n)
            
        myRegistry.insert(world)
        
        root = myRegistry.insert(registry.createSimulation(myRegistry))
        from marketsim.context import BindingContextEx
        myRegistry.get(root).bind_ex(BindingContextEx({ "world" : world }))
        myRegistry.get(root).registerIn(myRegistry)

        if name != 'All':
            current_dir = current_user_dir()
            ensure_dir_ex(current_dir)
            
            if os.path.exists(os.path.join(current_dir, name)):
                i = 0
                while os.path.exists(os.path.join(current_dir, name + "." + str(i))): 
                    i += 1
                name += '.' + str(i) 
        
        return name, root, myRegistry, world