Overall Statistics
Total Orders
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
15.846%
Drawdown
33.700%
Expectancy
0
Start Equity
1000000
End Equity
1801513.18
Net Profit
80.151%
Sharpe Ratio
0.625
Sortino Ratio
0.559
Probabilistic Sharpe Ratio
23.684%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0
Beta
0.998
Annual Standard Deviation
0.166
Annual Variance
0.028
Information Ratio
-0.864
Tracking Error
0
Treynor Ratio
0.104
Total Fees
$25.31
Estimated Strategy Capacity
$0
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
0.07%
# region imports
from AlgorithmImports import *
# endregion

class FormalYellowGreenBull(QCAlgorithm):

    def Initialize(self):
        self.SetCash(1000000)

        # 1. Backtesting Period Selection
        self.TrainingPeriod = "IS"

        # 2. Backtesting Period Lookup
        self.SetBacktestingPeriod()
        
        # Warm-up the algorithm for 50 days 
        self.SetWarmUp(50, Resolution.Daily)

        # Add SPY equity to the algorithm
        self.AddEquity("SPY", Resolution.Daily)

    def OnWarmupFinished(self):
        """Called when the algorithm warm-up is finished."""
        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)

    def OnData(self, data: Slice):
        """Ensure other data complete before tranaction"""
        if self.IsWarmingUp:
            return

        if not self.Portfolio.Invested:
            self.SetHoldings("SPY", 1)

    def SetBacktestingPeriod(self):
        """Sets the backtesting period based on the selected training period."""
        if self.TrainingPeriod == "IS":
            self.SetStartDate(2017, 1, 1)
            self.SetEndDate(2021, 1, 1)
        elif self.TrainingPeriod == "OOSA": 
            self.SetStartDate(2022, 1, 1)
            self.SetEndDate(2022, 11, 1)
        elif self.TrainingPeriod == "OOSB":
            self.SetStartDate(2016, 1, 1)
            self.SetEndDate(2017, 1, 1)
        elif self.TrainingPeriod == "LT":
            self.SetStartDate(2024, 8, 1)
            self.SetEndDate(2024, 8, 15)
        elif self.TrainingPeriod == "ST":
            self.SetStartDate(2020, 3, 1)
            self.SetEndDate(2020, 3, 31)