Overall Statistics
Total Orders
9
Average Win
9.96%
Average Loss
-0.84%
Compounding Annual Return
21.939%
Drawdown
6.100%
Expectancy
2.217
Start Equity
1000000
End Equity
1287458.35
Net Profit
28.746%
Sharpe Ratio
1.339
Sortino Ratio
1.623
Probabilistic Sharpe Ratio
90.387%
Loss Rate
75%
Win Rate
25%
Profit-Loss Ratio
11.87
Alpha
0.027
Beta
0.48
Annual Standard Deviation
0.073
Annual Variance
0.005
Information Ratio
-0.646
Tracking Error
0.076
Treynor Ratio
0.203
Total Fees
$111.21
Estimated Strategy Capacity
$1000000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
1.93%
# region imports
from AlgorithmImports import *
# endregion

class QuantLeague(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2023, 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"