Overall Statistics
Total Trades
1419
Average Win
0.87%
Average Loss
-0.59%
Compounding Annual Return
-0.790%
Drawdown
36.900%
Expectancy
-0.002
Net Profit
-5.407%
Sharpe Ratio
0.029
Probabilistic Sharpe Ratio
0.098%
Loss Rate
60%
Win Rate
40%
Profit-Loss Ratio
1.48
Alpha
0.031
Beta
-0.241
Annual Standard Deviation
0.139
Annual Variance
0.019
Information Ratio
-0.478
Tracking Error
0.226
Treynor Ratio
-0.017
Total Fees
$3973.34
Estimated Strategy Capacity
$70000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
# region imports
from AlgorithmImports import *
# endregion

# Import necessary libraries
# from quantconnect.algorithm import QCAlgorithm
# from quantconnect.indicators import SimpleMovingAverage

class SimpleSMATradingStrategy(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2022,1,1)
        # Set the cash we'd like to use for our backtest
        self.SetCash(100000)

        # Set the symbol we'd like to use for our backtest
        self.symbol = self.AddEquity("SPY").Symbol

        # Set the lookback period for our moving average
        self.lookback_period = 20

        # Create a Simple Moving Average indicator
        self.sma = self.SMA(self.symbol,self.lookback_period)

        # Schedule an event to fire every trading day at market close
        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(17, 0), self.Trade)

    def Trade(self):
        # Get the current price of the asset
        current_price = self.Securities[self.symbol].Price

        # Check if the moving average indicator is ready to be used
        if self.sma.IsReady:
            # Get the value of the moving average indicator
            sma_value = self.sma.Current.Value

            # If the current price is greater than the moving average, buy the asset
            if current_price > sma_value:
                self.SetHoldings(self.symbol, 1)
            # If the current price is less than the moving average, sell the asset
            elif current_price < sma_value:
                self.SetHoldings(self.symbol, -1)
            # If the current price is equal to the moving average, do nothing
            else:
                pass
        else:
            # If the moving average indicator is not ready, do nothing
            pass