Overall Statistics
Total Trades
1335
Average Win
0.13%
Average Loss
-0.08%
Compounding Annual Return
11.768%
Drawdown
4.100%
Expectancy
0.332
Net Profit
15.895%
Sharpe Ratio
1.37
Probabilistic Sharpe Ratio
67.034%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.63
Alpha
0.086
Beta
-0.055
Annual Standard Deviation
0.06
Annual Variance
0.004
Information Ratio
0.077
Tracking Error
0.151
Treynor Ratio
-1.496
Total Fees
$2086.17
Estimated Strategy Capacity
$410000.00
Lowest Capacity Asset
SABRP XHVSM2QVDB39
# Long-Short Equity Rebalancing

from AlgorithmImports import *

class LongShortPF(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2021, 1, 1)  
        self.SetEndDate(2022, 5, 1)    
        self.SetCash(1000000)
        self.AddUniverse(self.CoarseSelection, self.FineSelection) 
        self.selected = []
        self.numb_stocks = 50
        self.universeMonth = -1             

	   
    def CoarseSelection(self, coarse):
        if self.Time.month == self.universeMonth:
            return self.filteredStocks
        self.filteredStocks = [x.Symbol for x in coarse if x.HasFundamentalData and (float(x.Price)) > 10 and x.DollarVolume > 5000000]
        return self.filteredStocks

		 
    def FineSelection(self,fine):
        no_fin = [sec for sec in fine if sec.AssetClassification.MorningstarSectorCode != MorningstarSectorCode.FinancialServices]
        tops = sorted(no_fin, key = lambda sec:sec.ValuationRatios.ForwardPERatio, reverse=True)[:self.numb_stocks]
        bottoms = sorted(no_fin, key = lambda sec:sec.ValuationRatios.ForwardPERatio, reverse=True)[-self.numb_stocks:]
        self.longs = [l.Symbol for l in tops if l.ValuationRatios.PEGRatio > 1]
        self.shorts = [s.Symbol for s in bottoms if s.ValuationRatios.PEGRatio < 1]        
        self.selected = self.longs + self.shorts
        return self.selected

   
    def OnData(self, data):
        if self.Time.month == self.universeMonth: return
        if not (self.Time.hour == 10 and self.Time.minute == 1): return

        for sec in self.Portfolio.Keys:
            if sec not in self.selected:
                self.Liquidate(sec)
        for sec in self.longs:
            wt = 0.45/len(self.longs) if len(self.longs) > 0 else 0
            self.SetHoldings(sec, wt)
        for sec in self.shorts:
            wt = -0.45/len(self.shorts) if len(self.shorts) > 0 else 0
            self.SetHoldings(sec, wt) 
        self.universeMonth = self.Time.month