Overall Statistics
Total Orders
423
Average Win
1.11%
Average Loss
-1.76%
Compounding Annual Return
3.226%
Drawdown
29.200%
Expectancy
0.068
Start Equity
100000
End Equity
120969.62
Net Profit
20.970%
Sharpe Ratio
0.07
Sortino Ratio
0.051
Probabilistic Sharpe Ratio
1.262%
Loss Rate
35%
Win Rate
65%
Profit-Loss Ratio
0.63
Alpha
-0.037
Beta
0.616
Annual Standard Deviation
0.131
Annual Variance
0.017
Information Ratio
-0.639
Tracking Error
0.103
Treynor Ratio
0.015
Total Fees
$686.24
Estimated Strategy Capacity
$33000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
19.26%
# region imports
from AlgorithmImports import *
# endregion

class EnergeticFluorescentPinkSardine(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2018, 1, 1)
        self.set_end_date(2024, 1, 1)
        self.set_cash(100000)
        self.spy = self.add_equity("SPY", Resolution.MINUTE).symbol

        # Create a 1 hour consolidator
        self.consolidator = self.Consolidate(self.spy, timedelta(minutes=60), self.on_data_consolidated)

        # Register the RSI indicator to the consolidator
        self.spy_rsi = RelativeStrengthIndex(14, MovingAverageType.Simple)
        self.RegisterIndicator(self.spy, self.spy_rsi, self.consolidator)

        self.set_benchmark(self.spy)

    def on_data_consolidated(self, bar):
        # This method will be called at the end of each 1 hour period
        # self.log(f"Current RSI {self.spy_rsi.current.value}")
        if not self.portfolio.invested and self.spy_rsi.IsReady:
            if self.spy_rsi.Current.Value < 40:
                self.set_holdings(self.spy, 1)
        elif self.portfolio.invested and self.spy_rsi.IsReady:
            if self.spy_rsi.Current.Value > 60:
                self.liquidate(self.spy)

    def on_data(self, data: Slice):
        # This method will be called every minute
        pass