Overall Statistics
Total Trades
143
Average Win
9.10%
Average Loss
-4.86%
Compounding Annual Return
305.769%
Drawdown
56.500%
Expectancy
0.472
Net Profit
292.999%
Sharpe Ratio
3.272
Probabilistic Sharpe Ratio
77.287%
Loss Rate
49%
Win Rate
51%
Profit-Loss Ratio
1.87
Alpha
2.525
Beta
-0.426
Annual Standard Deviation
0.787
Annual Variance
0.619
Information Ratio
3.224
Tracking Error
0.834
Treynor Ratio
-6.045
Total Fees
$623.71
Estimated Strategy Capacity
$2500000.00
Lowest Capacity Asset
BSV TRO5ZARLX6JP
from AlgorithmImports import *

class LogicalSkyBlueRat(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 1, 1)  # Set Start Date
        self.SetEndDate(2022, 12, 30)
        self.SetCash(10000)  # Set Strategy Cash
        # self.SetSecurityInitializer(self.CustomSecurityInitializer)

        self.equities = ["SPY", "TQQQ", "SPXL", "UVXY", "SQQQ", "BSV", "TECL"]
        self.indicators = dict()

        for equity in self.equities:
            self.AddEquity(equity, Resolution.Minute)
            self.Securities[equity].SetDataNormalizationMode(DataNormalizationMode.Raw)
            self.indicators[equity] = dict()

            self.indicators[equity]['RSI'] = dict()
            self.indicators[equity]['RSI']['Period-10'] = RelativeStrengthIndex(10) # self.RSI(equity, 10)#, resolution=Resolution.Daily)

            self.indicators[equity]['SMA'] = dict()
            self.indicators[equity]['SMA']['Period-20'] = SimpleMovingAverage(20) # self.SMA(equity, 20)#, resolution=Resolution.Daily)
            self.indicators[equity]['SMA']['Period-200'] = SimpleMovingAverage(200) # self.SMA(equity, 200)#, resolution=Resolution.Daily)

        self.Schedule.On(self.DateRules.EveryDay("SPY"),
                        self.TimeRules.BeforeMarketClose("SPY", 5),
                        self.FunctionBeforeMarketClose)

    # def CustomSecurityInitializer(self, security: Security) -> None:
    #     # Disable trading fees
    #     security.SetFeeModel(ConstantFeeModel(0, "USD"))

    def OnData(self, data: Slice):
        pass

    def FunctionBeforeMarketClose(self):

        for equity in self.equities:

            if not self.indicators[equity]['RSI']['Period-10'].IsReady:
                history = self.History(equity, 10, Resolution.Daily)

                for bar in history:
                    self.indicators[equity]['RSI']['Period-10'].Update(bar.EndTime, bar.Close)

            if not self.indicators[equity]['SMA']['Period-20'].IsReady:
                history = self.History(equity, 20, Resolution.Daily)

                for bar in history:
                    self.indicators[equity]['SMA']['Period-20'].Update(bar.EndTime, bar.Close)

            if not self.indicators[equity]['SMA']['Period-200'].IsReady:
                history = self.History(equity, 200, Resolution.Daily)

                for bar in history:
                    self.indicators[equity]['SMA']['Period-200'].Update(bar.EndTime, bar.Close)


            self.indicators[equity]['RSI']['Period-10'].Update(self.Time, self.Securities[equity].Close)
            self.indicators[equity]['SMA']['Period-20'].Update(self.Time, self.Securities[equity].Close)
            self.indicators[equity]['SMA']['Period-200'].Update(self.Time, self.Securities[equity].Close)
            
        # self.Log(f"Close: {self.Securities['SPY'].Close}\
        #     RSI: {self.indicators['SPY']['RSI']['Period-10'].Current.Value}\
        #     SMA-20: {self.indicators['SPY']['SMA']['Period-20'].Current.Value}\
        #     SMA-200: {self.indicators['SPY']['SMA']['Period-200'].Current.Value}")

        if self.Securities['SPY'].Close > self.indicators['SPY']['SMA']['Period-200'].Current.Value:
            if self.indicators['TQQQ']['RSI']['Period-10'].Current.Value > 79:
                self.SetHoldings("UVXY", 1, True)

            else:
                if self.indicators['SPXL']['RSI']['Period-10'].Current.Value > 80:
                    self.SetHoldings("UVXY", 1, True)

                else:
                    self.SetHoldings("TQQQ", 1, True)

        else:
            if self.indicators['TQQQ']['RSI']['Period-10'].Current.Value < 31:
                self.SetHoldings("TECL", 1, True)

            else:
                if self.indicators['SPY']['RSI']['Period-10'].Current.Value < 30:
                    self.SetHoldings("SPXL", 1, True)

                else:
                    if self.indicators['UVXY']['RSI']['Period-10'].Current.Value > 74:
                        if self.indicators['UVXY']['RSI']['Period-10'].Current.Value > 84:
                            if self.Securities['TQQQ'].Close > self.indicators['TQQQ']['SMA']['Period-20'].Current.Value:
                                if self.indicators['SQQQ']['RSI']['Period-10'].Current.Value < 31:
                                    self.SetHoldings("SQQQ", 1, True)

                                else:
                                    self.SetHoldings("TQQQ", 1, True)
                            
                            else:
                                if self.indicators['SQQQ']['RSI']['Period-10'].Current.Value > self.indicators['BSV']['RSI']['Period-10'].Current.Value:
                                    self.SetHoldings("SQQQ", 1, True)
                                else:
                                    self.SetHoldings("BSV", 1, True)

                        else:
                            self.SetHoldings("UVXY", 1, True)

                    else:
                        if self.Securities['TQQQ'].Close > self.indicators['TQQQ']['SMA']['Period-20'].Current.Value:
                            if self.indicators['SQQQ']['RSI']['Period-10'].Current.Value < 31:
                                self.SetHoldings("SQQQ", 1, True)

                            else:
                                self.SetHoldings("TQQQ", 1, True)

                        else:
                            if self.indicators['SQQQ']['RSI']['Period-10'].Current.Value > self.indicators['BSV']['RSI']['Period-10'].Current.Value:
                                self.SetHoldings("SQQQ", 1, True)

                            else:
                                self.SetHoldings("BSV", 1, True)