def calculate_signals(self, event, agent=None): print "Inside calculate_signals :", event.ticker, self.invested, self.ticks if event.type in [EventType.BAR, EventType.TICK ] and event.ticker in self.tickers: print "Calling Learning : agent.update" actionTobePerformed = agent.getLearningHandler().update( event, agent.indicator_dict, agent.portfolio_handler.portfolio) signal = SignalEvent(event.ticker, actionTobePerformed) if actionTobePerformed == "NONE": print " No action " elif actionTobePerformed == "BUY": if event.ticker not in agent.portfolio_handler.portfolio.positions: print "Buy Event recieved from learner. Ticker {} not in portfolio. Adding position".format( event.ticker) self.events_queue.put(signal) elif actionTobePerformed == "SELL": print "Exit Event received from learner. Ticker {} in portfolio. Removing position".format( event.ticker) if event.ticker in agent.portfolio_handler.portfolio.positions: self.events_queue.put(signal) self.ticks += 1
def calculate_signals(self, event, agent=None): if event.type == EventType.BAR and event.ticker in self.tickers: # Add latest adjusted closing price to the # short and long window bars if self.ticks % 5 == 0: print "Calling Learning : agent.update" actionTobePerformed = agent.getLearningHandler().update( event, self.learning_indictors, self.reward_indicators, agent.indicator_dict, agent.portfolio_handler.portfolio) signal = SignalEvent(event.ticker, actionTobePerformed) if actionTobePerformed == "NONE": print " No action " elif actionTobePerformed == "BOT": if event.ticker not in agent.portfolio_handler.portfolio.positions: print "Buy Event recieved from learner. Ticker {} not in portfolio. Adding position".format( event.ticker) self.events_queue.put(signal) elif actionTobePerformed == "EXIT": print "Exit Event received from learner. Ticker {} in portfolio. Removing position".format( event.ticker) if event.ticker in agent.portfolio_handler.portfolio.positions: self.events_queue.put(signal) self.ticks += 1
def calculate_signals(self, event, agent=None): """ For a particular received BarEvent, determine whether it is the end of the month (for that bar) and generate a liquidation signal, as well as a purchase signal, for each ticker. """ if (event.type in [EventType.BAR, EventType.TICK] and self._end_of_month(event.time)): ticker = event.ticker if self.tickers_invested[ticker]: liquidate_signal = SignalEvent(ticker, "EXIT") self.events_queue.put(liquidate_signal) long_signal = SignalEvent(ticker, "BOT") self.events_queue.put(long_signal) self.tickers_invested[ticker] = True
def calculate_signals(self, event,agent=None): if event.type in [EventType.BAR, EventType.TICK] and event.ticker in self.tickers: if event.ticker not in agent.portfolio_handler.portfolio.positions: signal = SignalEvent(event.ticker, "BOT") self.events_queue.put(signal) self.invested = True self.ticks += 1
def getSignal(self, ticker): return SignalEvent(self.tickers[0], "BOT")
def getSignal(self, ticker): print "TIC", ticker, self.signal return SignalEvent(ticker, self.signal[ticker])