Overall Statistics
Total Orders
75
Average Win
5.40%
Average Loss
-1.54%
Compounding Annual Return
8.139%
Drawdown
17.500%
Expectancy
0.704
Start Equity
1000000
End Equity
1446722.72
Net Profit
44.672%
Sharpe Ratio
0.35
Sortino Ratio
0.313
Probabilistic Sharpe Ratio
13.936%
Loss Rate
62%
Win Rate
38%
Profit-Loss Ratio
3.50
Alpha
0.006
Beta
0.337
Annual Standard Deviation
0.103
Annual Variance
0.011
Information Ratio
-0.362
Tracking Error
0.144
Treynor Ratio
0.106
Total Fees
$1187.39
Estimated Strategy Capacity
$1200000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
4.35%
# 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):

        if self.IsWarmingUp:
            return  # Skip during warm-up
        # Ensure we have enough data to calculate the moving average
        if not self.fast_moving_average.is_ready:
            return
        
        if self.symbol in data and data[self.symbol] is not None:
            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"