Hello,

I'm a recent joiner and have been going through the bootcamp tutorials in order to learn the QC platform. I'm trying to replicate a strategy I configured using the Interactive Brokers Portfolio Builder & Backtester. Basically, my strategy goes Long the Bottom 10 ranked by PE Ratio and goes Short the Top 10 ranked by PE Ratio on a daily basis.

I came across the Liquid Value Stocks tutorial which does something similar by separating the top 10 and bottom 10 by Earning Yield.

def SelectFine(self, algorithm, fine):
  
        sortedByYields = sorted(fine, key=lambda f: f.ValuationRatios.EarningYield, reverse=True)
        universe = sortedByYields[:10] + sortedByYields[-10:]
        return [f.Symbol for f in universe]

However, when it came to generating the daily buy/sell signals (I think you guys call it emitting Insights), the tutorial used a simple line of logic to go Long if the EarningYield was greater than 0 and Short otherwise, as below, In other words, separating out by top 10 & bottom 10 didn't matter to the trading strategy as that was not really used. Maybe the instructor didn't want to make the lesson too complex.

for security in algorithm.ActiveSecurities.Values:
            direction = 1 if security.Fundamentals.ValuationRatios.EarningYield > 0 else -1 
            insights.append(Insight.Price(security.Symbol, timedelta(28), direction)) 
        return insights

I, however, would like to go Short all of my top 10 stocks ranked by PE Ratio and Long all of my bottom 10 stocks on a daily basis. I've searched through the documentation & the forum for help on this but alas couldn't find anything related.

Can someone help me with some actual code to generate Long & Short signals for Top 10 and Bottom 10? Thanks in advance.

Sheikh