Overall Statistics
Total Trades
964
Average Win
0.13%
Average Loss
-0.07%
Compounding Annual Return
64.792%
Drawdown
8.500%
Expectancy
1.054
Net Profit
49.320%
Sharpe Ratio
2.875
Probabilistic Sharpe Ratio
90.302%
Loss Rate
26%
Win Rate
74%
Profit-Loss Ratio
1.78
Alpha
0.536
Beta
0.011
Annual Standard Deviation
0.188
Annual Variance
0.035
Information Ratio
1.059
Tracking Error
0.218
Treynor Ratio
49.713
Total Fees
$1246.66
Estimated Strategy Capacity
$73000000.00
Lowest Capacity Asset
F R735QTJ8XC9X
from random import random

class RetrospectiveBrownDogfish(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 11, 5)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.UniverseSettings.Resolution = Resolution.Daily
        symbols = [ Symbol.Create(ticker, SecurityType.Equity, Market.USA) for ticker in ['SPY', 'TSLA', 'F', 'FB', 'XLK'] ]
        self.AddUniverseSelection( ManualUniverseSelectionModel(symbols) )
        
        self.SetAlpha(MyAlpha())
        
        self.SetPortfolioConstruction(BlackLittermanOptimizationPortfolioConstructionModel())
        
        self.SetExecution(ImmediateExecutionModel())

class MyAlpha(AlphaModel):
    symbols = []
    
    def Update(self, algorithm, data):
        insights = []
        for symbol in self.symbols:
            if not (data.ContainsKey(symbol) and data[symbol] is not None):
                continue
            
            # The BlackLittermanOptimizationPortfolioConstructionModel uses the insight magnitude to optimize 
            #  the portfolio allocations
            magnitude = round(random(), 4)
            
            insight = Insight.Price(symbol, timedelta(days=1), InsightDirection.Up, magnitude, confidence=1, sourceModel='MyAlpha', weight=0.1)
            insights.append(insight)
        return insights
    
    def OnSecuritiesChanged(self, algorithm, changes):
        for security in changes.AddedSecurities:
            self.symbols.append(security.Symbol)
        
        for security in changes.RemovedSecurities:
            if security.Symbol in self.symbols:
                self.symbols.remove(security.Symbol)