def Canceller(ctx): ctx.volumeStep = 15 return [ ctx.makeTrader_A(strategy.LiquidityProvider(), "LiquidityProviderEx-"), ctx.makeTrader_A(strategy.Canceller(), "canceller"), ctx.makeTrader_A( strategy.FundamentalValue(fundamentalValue=const(1000)), "fv_1000") ]
def FundamentalValue(ctx): ctx.volumeStep = 30 fv = 200 demo = ctx.addGraph('demo') myVolume = lambda: [(trader.Position(), demo)] myPrice = lambda: [(orderbook.MidPrice(), demo)] return [ ctx.makeTrader_A( strategy.LiquidityProvider( orderFactory = order.side_price.WithExpiry(const(10), order.side_price.Limit(volume=const(6)))), "liquidity"), ctx.makeTrader_A( strategy.FundamentalValue( event.Every(const(1.)), order.side.Market(volume = const(1.)), const(fv)), "fv_200", myVolume()), ]
def s_fv(fv): return strategy.TradeIfProfitable( strategy.FundamentalValue( fundamentalValue=const(fv), orderFactory=order.side.Market(volume=const(1))))
def Complete(ctx): ctx.volumeStep = 100 c_200 = const(200.) fv_200_12 = strategy.FundamentalValue( fundamentalValue=c_200, orderFactory=order.side.Market(volume=const(12))) fv_200 = strategy.FundamentalValue( fundamentalValue=c_200, orderFactory=order.side.Market(volume=const(1))) def s_fv(fv): return strategy.TradeIfProfitable( strategy.FundamentalValue( fundamentalValue=const(fv), orderFactory=order.side.Market(volume=const(1)))) def fv_virtual(fv): return ctx.makeTrader_A(s_fv(fv), "v" + str(fv)) return [ ctx.makeTrader_A( strategy.LiquidityProvider( orderFactory=order.side_price.WithExpiry( constant(10), order.side_price.Limit( volume=constant(170)))), "liquidity"), ctx.makeTrader_A(fv_200_12, "t200"), ctx.makeTrader_A(fv_200, "t200_1"), ctx.makeTrader_A( strategy.FundamentalValue(event.Every(constant(1.)), order.side.Market(const(1.)), fundamentalValue=const(150.)), "t150"), ctx.makeTrader_A( strategy.MeanReversion(event.Every(constant(1.)), order.side.Market(const(1.))), "mr_0_15"), ctx.makeTrader_A(strategy.CrossingAverages(event.Every(constant(1.)), order.side.Market( const(1.)), ewma_alpha_1=0.15, ewma_alpha_2=0.015), label="avg+"), ctx.makeTrader_A(strategy.CrossingAverages(event.Every(constant(1.)), order.side.Market( const(1.)), ewma_alpha_2=0.15, ewma_alpha_1=0.015), label="avg-"), ctx.makeTrader_A(strategy.TradeIfProfitable(fv_200), "v_fv200"), fv_virtual(160.), fv_virtual(170.), fv_virtual(180.), fv_virtual(190.), ctx.makeTrader_A( strategy.ChooseTheBest([ s_fv(160.), s_fv(170.), s_fv(180.), s_fv(190.), ]), "best") ]
def fv(x): return strategy.FundamentalValue( event.Every(constant(1.)), order.side.Market(volume=constant(1.)), fundamentalValue=const(x))
def MultiarmedBandit(ctx): ctx.volumeStep = 30 demo = ctx.addGraph('demo') myVolume = lambda: [(trader.Position(), demo)] def fv(x): return strategy.FundamentalValue( event.Every(constant(1.)), order.side.Market(volume=constant(1.)), fundamentalValue=const(x)) xs = range(100, 300, 50) + range(160, 190, 10) def strategies(): return map(fv, xs) def fv_traders(): return [ctx.makeTrader_A(fv(x), "fv" + str(x), myVolume()) for x in xs] return [ ctx.makeTrader_A( strategy.LiquidityProvider(orderFactory=order.side_price.Limit( volume=constant(45))), "liquidity"), ctx.makeTrader_A( strategy.FundamentalValue(event.Every(constant(1.)), order.side.Market(volume=constant(12.)), fundamentalValue=const(200)), 'fv 12-200'), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.virtualMarket(), strategy.weight.efficiencyTrend()), 'virt trend', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit(strategies(), strategy.account.real(), strategy.weight.efficiencyTrend()), 'real trend', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.virtualMarket(), strategy.weight.efficiency()), 'virt efficiency', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit(strategies(), strategy.account.real(), strategy.weight.efficiency()), 'real efficiency', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.virtualMarket(), strategy.weight.score(), strategy.weight.atanPow()), 'virt score', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.real(), strategy.weight.score(), strategy.weight.clamp0()), 'real score', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.virtualMarket(), strategy.weight.efficiencyTrend(), strategy.weight.identityF(), strategy.weight.chooseTheBest()), 'virt best', myVolume()), ctx.makeTrader_A( strategy.MultiArmedBandit( strategies(), strategy.account.real(), strategy.weight.unit(), strategy.weight.identityF()), 'uniform', myVolume()), ] + fv_traders()