count[stock][1] += 1 else: count[stock][0] = index count[stock][1] = 1 else: count[stock] = [0, 0] for quote, k in zip(quotes, range(len(quotes))): if count[quote.symbol][ 1] < 3: # and stocks['SPY'].get_average(date[0], date[1]).average > average: trader.buy(prices[quote.symbol], weight=weights[k]) trade() print(trader.get_percent_change()) def trade1(): for quotes in top: trader.update(quotes[0].date_to) for quote, i in zip(quotes, range(0, len(quotes))): count[quote.symbol] = count[ quote.symbol] + 1 if quote.symbol in count else 1 if count[quote.symbol] < 3: print(quote) trader.buy(quote, weight=weights[i]) else: trader.sell(quote)