Overall Statistics
from datetime import timedelta
class MOMAlphaModel(AlphaModel): 
    def __init__(self):
        self.mom = []
    def OnSecuritiesChanged(self, algorithm, changes):
        for security in changes.AddedSecurities:
            symbol = security.Symbol
            self.mom.append({"symbol":symbol, "indicator":algorithm.MOM(symbol, 14, Resolution.Daily)})
    def Update(self, algorithm, data):
        ordered = sorted(self.mom, key=lambda kv: kv["indicator"].Current.Value, reverse=True)
        return Insight.Group([Insight.Price(ordered[0]['symbol'], timedelta(22), InsightDirection.Up), Insight.Price(ordered[1]['symbol'], timedelta(22), InsightDirection.Flat) ])
 
class FrameworkAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2014, 1, 1)   
        self.SetEndDate(2019, 1, 1)    
        self.SetCash(100000)           
        symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA),  Symbol.Create("BND", SecurityType.Equity, Market.USA)]
        self.UniverseSettings.Resolution = Resolution.Daily
        self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
        self.SetAlpha(MOMAlphaModel())
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(rebalancingParam = timedelta(22)))
        self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02))
        
        #1. Set the Execution Model to an Immediate Execution Model
        self.SetExecution(ImmediateExecutionModel())