Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem to create a custom a SlippageMode for futures

Hello,
I'm trying to add a custom slippage model for features, but it is not working... I think that my problem is related with slippage.create_transaction():


class PerStockSpreadSlippage(slippage.SlippageModel):

    def __init__(self, spreads):  
        self.spreads = spreads  
    def process_order(self, trade_bar, my_order):  
        spread = self.spreads[my_order.sid]  
        price = trade_bar.current(my_order.sid, 'price')  
        vol = trade_bar.current(my_order.sid, 'volume')  
        slip_amount_1 = min(vol/40,my_order.amount)  
        slip_amount_2 = my_order.amount-slip_amount_1  
        new_price_2 = price + (spread * my_order.direction)

        new_price = (new_price_2*slip_amount_2+price*slip_amount_1)/my_order.amount  
        return slippage.create_transaction(  
            my_order,  
            trade_bar,  
            new_price,  
            my_order.amount  
        )  
def initialize(context):  
    context.spreads = {  
        sid(1006201911): 0.005,  
        sid(1006202002): 0.005  
    }  
    # Initialize slippage settings given the parameters of our model  
    set_slippage(us_futures=PerStockSpreadSlippage(context.spreads))  

Can you help me please?

2 responses

What is it that is not working? Is there an error message somewhere?

Sadly there is runtime errors do not show any messenge. only "Something went wrong. Sorry for the inconvenience. Try using the built-in debugger to analyze your code. If you would like help, send us an email".

I try to solve it with the debbuger but I can't find the problem. When I use the buttom "step into next function call" the algorithm stops after the return of the "PerStockSpreadSlippage".
The return of the PerStockSpreadSlippage is:

Transaction: Transaction(asset=Future(1006201911 [FFX19]), dt=<zipline._protocol.BarData object at 0x7f47ee84bdf8>, amount=-10, price=97.45)