def TwoAveragesEx(
    average1=None,  # mathutils.ewma(alpha = 0.15),
    average2=None,  # mathutils.ewma(alpha = 0.015),
    threshold=0,
    orderFactory=order.MarketFactory,
    creationIntervalDistr=mathutils.rnd.expovariate(1.0),
    volumeDistr=mathutils.rnd.expovariate(1.0),
):

    if average1 is None:
        average1 = mathutils.ewma(alpha=0.15)
    if average2 is None:
        average2 = mathutils.ewma(alpha=0.015)

    return defs(
        Generic(
            orderFactory=orderFactory,
            volumeFunc=volumeDistr,
            eventGen=scheduler.Timer(creationIntervalDistr),
            sideFunc=SignalSide(
                mathutils.sub(observable.Fold(_.price, average1), observable.Fold(_.price, average2)), threshold
            ),
        ),
        {"price": observable.Price(orderbook.OfTrader())},
    )
Example #2
0
def RSIbis (timeframe               = 0., 
            threshold               = 30,
            alpha                   = 1./14,
            orderFactory            = order.MarketFactory, 
            volumeDistr             = mathutils.rnd.expovariate(1.), 
            creationIntervalDistr   = mathutils.rnd.expovariate(1.)):
    
    thisBook = orderbook.OfTrader()
    
    return defs(Generic(orderFactory = orderFactory, 
                        volumeFunc   = volumeDistr, 
                        eventGen     = scheduler.Timer(creationIntervalDistr),
                        sideFunc     = SignalSide(mathutils.sub(mathutils.constant(50), 
                                                                _.rsi), 
                                                  50-threshold)), 
                { 'rsi' : observable.RSI(thisBook, timeframe, alpha) })