Overall Statistics
Total Trades
107
Average Win
1.10%
Average Loss
-0.81%
Compounding Annual Return
1.050%
Drawdown
9.300%
Expectancy
0.139
Net Profit
5.550%
Sharpe Ratio
0.174
Probabilistic Sharpe Ratio
2.058%
Loss Rate
52%
Win Rate
48%
Profit-Loss Ratio
1.37
Alpha
0.013
Beta
-0.019
Annual Standard Deviation
0.06
Annual Variance
0.004
Information Ratio
-0.79
Tracking Error
0.182
Treynor Ratio
-0.557
Total Fees
$175.20
Estimated Strategy Capacity
$940000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
class LongMomentumSPY(QCAlgorithm):
    
    def Initialize(self):
        
        self.SetStartDate(2016, 4, 14)  
        self.SetEndDate(2021, 6, 14)  
        self.SetCash(100000)  
        self.spy = self.AddEquity("SPY", Resolution.Daily)  
        self.SetBenchmark("SPY")
        self.SetBrokerageModel(BrokerageName.AlphaStreams)
        self.SetExecution(ImmediateExecutionModel())
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        
        symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA)]
        self.AddUniverseSelection(ManualUniverseSelectionModel(symbols))
      
        self.spyMomentum = self.MOMP("SPY", 30, Resolution.Daily)
        
        
        upthreshold = self.GetParameter("upthreshold")
        
        self.AddAlpha(LongMomentumAlphaModel(self.spyMomentum, upthreshold))
        
    def OnEndOfDay(self, symbol):
        self.Log("Taking a position of " + str(self.Portfolio[symbol].Quantity) + " units of symbol " + str(symbol))
        
class LongMomentumAlphaModel(AlphaModel):

    def __init__(self, spyMomentum, upthreshold):
        self.period = timedelta(120)
        self.spyMomentum = spyMomentum
        self.upthreshold = float(upthreshold)
        
    def Update(self, algorithm, data):
        insights = []
        
        
            
        if self.spyMomentum.IsReady:
            if self.spyMomentum.Current.Value >= self.upthreshold:
                insights.append(Insight("SPY", self.period, InsightType.Price, InsightDirection.Up, 1.0, None))
            else:
                insights.append(Insight("SPY", self.period, InsightType.Price, InsightDirection.Flat, 1.0, None))
            
        return insights
    
    def OnSecuritiesChanged(self, algorithm, changes):
        self.changes = changes