Overall Statistics
Total Orders
9
Average Win
0%
Average Loss
-1.29%
Compounding Annual Return
6.671%
Drawdown
6.100%
Expectancy
-1
Start Equity
1000000
End Equity
1049980.78
Net Profit
4.998%
Sharpe Ratio
-0.087
Sortino Ratio
-0.064
Probabilistic Sharpe Ratio
35.363%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.015
Beta
0.166
Annual Standard Deviation
0.074
Annual Variance
0.005
Information Ratio
-0.36
Tracking Error
0.165
Treynor Ratio
-0.039
Total Fees
$73.49
Estimated Strategy Capacity
$1400000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
3.26%
Drawdown Recovery
152
# region imports
from AlgorithmImports import *
# endregion

class QuantLeague(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2020, 1, 1)
        self.set_cash(1000000)
        self.symbol = self.add_equity("SPY", Resolution.Daily).Symbol
        self.fast_moving_average = self.sma(self.symbol, 50, Resolution.Daily)
        self.last_action = None

    def on_data(self, data):
        # Ensure we have enough data to calculate the moving average
        if not self.fast_moving_average.is_ready:
            return
        
        price = data[self.symbol].Close
        # Buy if the price is above the moving average
        if price > self.fast_moving_average.current.value:
            if not self.portfolio.invested or self.last_action == "Sell":
                self.set_holdings(self.symbol, 1)
                self.last_action = "Buy"

        # Sell if the price is below the moving average
        elif price < self.fast_moving_average.current.value:
            if self.portfolio.invested and self.last_action == "Buy":
                self.liquidate(self.symbol)
                self.last_action = "Sell"