Overall Statistics
Total Trades
7
Average Win
3.42%
Average Loss
-3.21%
Compounding Annual Return
4.357%
Drawdown
7.700%
Expectancy
0.378
Net Profit
0.845%
Sharpe Ratio
0.311
Probabilistic Sharpe Ratio
36.862%
Loss Rate
33%
Win Rate
67%
Profit-Loss Ratio
1.07
Alpha
0.083
Beta
-0.216
Annual Standard Deviation
0.156
Annual Variance
0.024
Information Ratio
-0.594
Tracking Error
0.186
Treynor Ratio
-0.225
Total Fees
$19.78
Estimated Strategy Capacity
$320000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
class MomentumEffectAlgorithm(QCAlgorithm):

    def Initialize(self):

        self.SetStartDate(2021, 7, 1)  # Set Start Date
        self.SetCash(100000)           # Set Strategy Cash

        self.UniverseSettings.Resolution = Resolution.Daily

        self.macd = {}           # Dict of Momentum indicator keyed by Symbol
        self.num_coarse = 100   # Number of symbols selected at Coarse Selection
        self.num_fine = 50      # Number of symbols selected at Fine Selection
        self.userlist = ["AAPL"]      #User list

        self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)


    def CoarseSelectionFunction(self, coarse):
        symbols = [x.Symbol for x in coarse if x.Symbol.Value in self.userlist]
        return symbols


    def FineSelectionFunction(self, fine):
        symbols = [x.Symbol for x in fine if x.Symbol.Value in self.userlist]
        return symbols


    def OnData(self, data):
        for i in self.Securities.Keys:
            self.Debug(self.macd[i].Current.Value)
            if self.macd[i].Current.Value > self.macd[i].Signal.Current.Value:
                self.SetHoldings(i, 1)
            elif self.macd[i].Signal.Current.Value > self.macd[i].Current.Value:
                self.Liquidate(i)


    def OnSecuritiesChanged(self, changes):

        # Clean up data for removed securities and Liquidate
        for security in changes.RemovedSecurities:
            pass

        for security in changes.AddedSecurities:
            if security.Symbol not in self.macd:
                self.macd[security.Symbol] = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential)
                history = self.History(security.Symbol, 100, Resolution.Daily).loc[security.Symbol]
                for idx, row in history.iterrows():
                    self.macd[security.Symbol].Update(idx, row['close'])
                self.RegisterIndicator(security.Symbol, self.macd[security.Symbol], Resolution.Daily)