Orders not getting filled on data1
-
i am having an issue getting orders based on data1 to get filled. I init cerebro with
cerebro.adddata(bt.feeds.PandasData(dataname=get_eod_data(instrument, strat_start_date, end_date), openinterest=None), name=instrument) cerebro.adddata(bt.feeds.PandasData(dataname=df_call_data, open=None, high=None, low=None, volume=None, openinterest=None), name='atm_call_price') cerebro.broker.setcash(100000) cerebro.addsizer(bt.sizers.PercentSizer, percents=2)
essentially data0 is the o/h/l/c of the underlying index and data1 is just the close for a synthetic atm call price with a given rfRate and impliedVol.
in my strategy i have the following basic code:
def next(self): # General Logic # sell a delta=50 (atm) 30day call # re-balance the delta daily if self.orders['option'] and self.orders['underlying']: return if self.day_counter % self.p.num_hold_days == 0: if self.position: self.logger.info(f'Need to close the option position') else: self.logger.info(f'Need to establish the initial option position') self.logger.info(f'{self.data0.datetime.datetime()} :: \ {self.data1.datetime.datetime()}') self.logger.info(f'{self.data0.close[0]} :: {self.data1.close[0]}') option_order = self.sell(data=self.data1, exectype=Order.Market)
my notify_order looks generic, I am just outputting stuff at this point:
def notify_order(self, order): if order.status in [order.Submitted, order.Accepted]: # Buy/Sell order submitted/accepted to/by broker - Nothing to do self.logger.info(f'Order {order.Status[order.status]} :: {order.ordtypename()} {order.size} {order.price}') return if order.status == Order.Completed: self.logger.info("[{}] FILLED {} {} @ {}".format(bt.num2date(order.executed.dt).date(), 'Buy' * order.isbuy() or 'Sell', order.executed.size, order.executed.price)) if order.is_option: self.orders['option'] = None elif order.status in [order.Canceled, order.Margin, order.Rejected]: self.logger.info(f'Order {order.Status[order.status]} :: {order.ordtypename()} {order.size} {order.price}') self.orders['option'] = None return
and i can see in my strategy outout:
14:25:15 [ strat]:INFO: Need to establish the initial option position 14:25:15 [ strat]:INFO: 2015-06-21 00:00:00 :: 2015-06-21 00:00:00 14:25:15 [ strat]:INFO: 243.944000244141 :: 21.058958519199706 14:25:15 [ strat]:INFO: Order Submitted :: Sell -94.97145825975088 None 14:25:15 [ strat]:INFO: Order Margin :: Sell -94.97145825975088 None
i can see that
- the dates of self.data0, self.data1 are inline
- the prices of data0.close[0] and data1.close[0] are what i would expect
- the position size is correct, im using a 2% Sizer, so if the initial broker cash is 100k, thats 2000/data1.close[0] = 94. and that is my size.
whats weird is that its automatically saying I need to get margin, i have no idea why, nor does the order.status ever change to completed. does anyone have any idea what is happening here ? Thanks-
-
@adamb032 I solved the issue, the data needs to have at least an open and close value in it for the simulated broker to work, once i made an open/high/low/close dataframe of all close values it works as expected.