Overall Statistics
Total Trades
2014
Average Win
0.07%
Average Loss
-0.04%
Compounding Annual Return
-93.941%
Drawdown
20.000%
Expectancy
-0.570
Net Profit
-19.994%
Sharpe Ratio
-20.946
Probabilistic Sharpe Ratio
0%
Loss Rate
85%
Win Rate
15%
Profit-Loss Ratio
1.79
Alpha
-2.405
Beta
0.74
Annual Standard Deviation
0.103
Annual Variance
0.011
Information Ratio
-25.923
Tracking Error
0.096
Treynor Ratio
-2.903
Total Fees
$44154.33
from datetime import timedelta

class MOMAlphaModel(AlphaModel):
    
    def __init__(self):
        self.mom = []
      
    def OnSecuritiesChanged(self, algorithm, changes):
        
        #Initialize a 14-day momentum indicator for each symbol
        for security in changes.AddedSecurities:
            symbol = security.Symbol
            self.mom.append({"symbol":symbol, "indicator":algorithm.MOM(symbol, 14, Resolution.Minute)})  #14
        
    def Update(self, algorithm, data):

        #Sort the list of dictionaries by indicator in descending order
        ordered = sorted(self.mom, key=lambda kv: kv["indicator"].Current.Value, reverse=True)
        
        #Return a group of insights, emitting InsightDirection.Up for the first item of ordered, and InsightDirection.Flat for the second
        return Insight.Group(
            [
                Insight.Price(ordered[0]["symbol"], timedelta(1), InsightDirection.Up),
                #Insight.Price(ordered[1]["symbol"], timedelta(1), InsightDirection.Down),
                Insight.Price(ordered[1]["symbol"], timedelta(1), InsightDirection.Flat),
                #Insight.Price(ordered[3]["symbol"], timedelta(1), InsightDirection.Down),
            ])
        
class FrameworkAlgorithm(QCAlgorithm):
    
    def Initialize(self):

        self.SetStartDate(2019, 11, 1)   
        #self.SetEndDate(2013, 12, 1)   
        self.SetCash(1000000)           
        self.reference = "SPY"
        self.SetBenchmark("SPY")
        
        symbols = [
                    Symbol.Create("GLD", SecurityType.Equity, Market.USA), 
                    Symbol.Create("SPY", SecurityType.Equity, Market.USA),

                    ]
                    
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))

        # Call the MOMAlphaModel Class 
        self.SetAlpha(MOMAlphaModel())

        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        #self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())
        self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.002))
        self.SetExecution(ImmediateExecutionModel())
        self.SetBrokerageModel(BrokerageName.AlphaStreams)