def run(self, prices, timestamp, cash, **kwargs): symbol = "AAPL" orders = Orders() if (prices.loc[timestamp, symbol] * 100) < cash: orders.add_order(symbol, 100) return orders
def run(self, prices, timestamp, cash, data, **kwargs): """ Takes bollinger event data and generates orders """ events = data['events'] if not hasattr(self, 'sell_orders'): self.setup(events) orders = Orders() # Find buy events for this timestamp timestamps = prices.index daily_data = events.loc[timestamp] order_series = daily_data[daily_data > 0] # Sell 5 market days after bought index = timestamps.get_loc(timestamp) if index + 5 >= len(timestamps): sell_datetime = timestamps[-1] else: sell_datetime = timestamps[index + 5] symbols = order_series.index self.sell_orders.loc[sell_datetime, symbols] -= 100 daily_sell_data = self.sell_orders.loc[timestamp] daily_sell_orders = daily_sell_data[daily_sell_data != 0] # Buy and sell in increments of 100 for symbol in daily_sell_orders.index: orders.add_order(symbol, -100) daily_event_data = events.loc[timestamp] daily_buy_orders = daily_event_data[daily_event_data != 0] # Buy and sell in increments of 100 for symbol in daily_buy_orders.index: orders.add_order(symbol, 100) return orders