Created with Highcharts 12.1.2EquityDec 2023Dec…Jan 2024Feb 2024Mar 2024Apr 2024May 2024Jun 2024Jul 2024Aug 2024Sep 2024Oct 2024Nov 2024Dec 20241,000,000
Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
1000000
End Equity
1000000
Net Profit
0%
Sharpe Ratio
0
Sortino Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-2.216
Tracking Error
0.101
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
from AlgorithmImports import *

class LiquidUniverseSelection(QCAlgorithm):
    
    filteredByPrice = None
    hasPrintedTopStocks = False  # Variable to control printing once
    
    def Initialize(self):
        self.SetStartDate(2023, 12, 1)  
        self.SetEndDate(2024, 12, 1) 
        self.SetCash(1000_000)

        # Adding universe using the FineSelectionFunction
        self.AddUniverse(self.FineSelectionFunction)
    
        self.UniverseSettings.Resolution = Resolution.Daily
        self.SetSecurityInitializer(lambda x: x.SetDataNormalizationMode(DataNormalizationMode.Raw))

        # Set leverage to 2
        self.UniverseSettings.Leverage = 2
        
        self.Liquidate()
        self.counter = 0

        self.Debug("Start time " + str(type(self.StartDate)))

    def FineSelectionFunction(self, fine):
        # Filter stocks by Energy sector and sort by MarketCap
        fine1 = [x for x in fine if x.AssetClassification.MorningstarSectorCode == MorningstarSectorCode.TECHNOLOGY]
        sortedByMarketCap = sorted(fine1, key=lambda c: c.MarketCap, reverse=True)
        filteredFine = [i.Symbol for i in sortedByMarketCap]
        
        # Filter top 5 stocks
        self.filter_fine = filteredFine[:3]
        return self.filter_fine
    
    def OnSecuritiesChanged(self, changes):
        # Process added securities
        for security in changes.AddedSecurities:
            self.Debug(f"Security Added: {security.Symbol}")
            # You can set holdings or perform other actions here
        
        # Process removed securities
        for security in changes.RemovedSecurities:
            self.Debug(f"Security Removed: {security.Symbol}")
            if security.Invested:
                self.Liquidate(security.Symbol)
    
    def OnData(self, data):
        # Ensure stocks are printed only once
        if not self.hasPrintedTopStocks:  
            for ticker in self.filter_fine:
                string = "- " + str(ticker)
                self.Debug(string)  # Print to the console
            self.hasPrintedTopStocks = True   # Flag to print only once