Esempio n. 1
0
    def _determine_sell_signals(self, register: SymbolDayRegister,
                                current_holdings: List[Stock]) -> List:

        holdings_dict = dict()
        for holding in current_holdings:
            holdings_dict[holding] = 1

        sell_signals = list()
        register_holdings = register.subset(current_holdings)
        for trader in self.traders:
            trader.holdings = holdings_dict
            stocks_sell = trader.determine_sells(self.today_epoch_s,
                                                 register_holdings)
            for stock in stocks_sell:
                recent_close = list()
                for i in range(10):
                    recent_close.append(
                        register_holdings.get_close(stock, self.today_epoch_s,
                                                    -i))
                sell_signal = {
                    'trader': trader.name,
                    'date': self.today_day_str,
                    'exchange': stock.exchange,
                    'symbol': stock.symbol,
                    'signal': 'SELL',
                    'recent_close': recent_close
                }
                print(yaml.dump(sell_signal))
                sell_signals.append(sell_signal)

        return sell_signals
Esempio n. 2
0
    def _determine_buy_signals(self, register: SymbolDayRegister,
                               candidates: List[Stock]) -> List:

        buy_signals = list()
        register_candidates = register.subset(candidates)
        for trader in self.traders:
            stocks_buy = trader.determine_buys(self.today_epoch_s,
                                               register_candidates)
            recent_close = list()
            for stock in stocks_buy:
                for i in range(10):
                    recent_close.append(
                        register_candidates.get_close(stock,
                                                      self.today_epoch_s, -i))
                buy_signal = {
                    'trader': trader.name,
                    'date': self.today_day_str,
                    'exchange': stock.exchange,
                    'symbol': stock.symbol,
                    'signal': 'BUY',
                    'recent_close': recent_close
                }
                buy_signals.append(buy_signal)
        return buy_signals