Ejemplo n.º 1
0
    def __init__(self):
        self.attributes = {"smooth":True}

        self._timer = event.Every(self.intervalDistr)
        event.subscribe(self._timer, _(self)._wakeUp, self)
        
        self.reset()
Ejemplo n.º 2
0
 def __init__(self):
     self._event = event.subscribe(self.source, _(self)._update, self)
     event.subscribe(event.Every(constant(self.timeframe)),
                     _(self)._flush, self)
     self.reset()
     self._mean = CMA(self.source)
     self._stddev = StdDev(self.source)
Ejemplo n.º 3
0
 def __init__(self):
     self._event = event.subscribe(self.source, _(self)._update, self)
     event.subscribe(event.Every(constant(self.timeframe)),
                     _(self)._flush, self)
     self.reset()
     self._mean = self.source.Cumulative.Avg
     self._stddev = self.source.Cumulative.StdDev
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def __init__(self):
     Strategy.__init__(self)
     self._current = None
     self._estimators = []
     for s in self.strategies:
         event.subscribe(s.on_order_created, _(self).send, self)
         e = self.performance(self.account(s))
         e._origin = s
         self._estimators.append(e)
     event.subscribe(event.Every(constant(1.)), _(self)._wakeUp, self)
Ejemplo n.º 6
0
    def __init__(self):

        # orders created by trader
        from marketsim.gen._out.trader._singleproxy import SingleProxy
        from marketsim.gen._out.orderbook._oftrader import OfTrader
        self._elements = []
        self._eventGen = event.Every(self.cancellationIntervalDistr)
        self._myTrader = SingleProxy()
        self._book = OfTrader(self._myTrader)
        self.on_order_created = event.Event()
Ejemplo n.º 7
0
 def __init__(self):
     self._quotes = None
     self._current = None
     event.subscribe(event.Every(constant(1)), _(self)._wakeUp, self)
Ejemplo n.º 8
0
 def __init__(self):
     self.attributes = {'smooth': True}
     self._dataSource = self.x
     IndicatorBase.__init__(self)
     self._subscription = event.subscribe(event.Every(constant(self.dt)),
                                          self.fire, self)
Ejemplo n.º 9
0
 def __init__(self):
     event.subscribe(event.Every(constant(1)), self.fire, self)