Overall Statistics
Total Trades
3
Average Win
0%
Average Loss
-6.95%
Compounding Annual Return
-19.550%
Drawdown
7.400%
Expectancy
-1
Net Profit
-6.955%
Sharpe Ratio
-2.231
Probabilistic Sharpe Ratio
0.001%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.16
Beta
0.009
Annual Standard Deviation
0.072
Annual Variance
0.005
Information Ratio
-0.17
Tracking Error
0.499
Treynor Ratio
-17.866
Total Fees
$3.97
class VerticalNadionGearbox(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 2, 20)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        symbols = [ Symbol.Create("SPY", SecurityType.Equity, Market.USA) ]
        self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )
        self.UniverseSettings.Resolution = Resolution.Daily
        
        self.AddAlpha(MyAlphaModel())
        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
        
        self.SetRiskManagement(MaximumDrawdownPercentPerSecurityCustom(0.05))
        
        self.SetExecution(ImmediateExecutionModel())


    def OnData(self, data):
        pass
        
class MyAlphaModel(AlphaModel):
    emitted = False
    
    def Update(self, algorithm, data):
        if self.emitted:
            return []
        else:
            self.emitted = True
            return [Insight.Price("SPY", timedelta(365), InsightDirection.Up)]
            
class MaximumDrawdownPercentPerSecurityCustom(RiskManagementModel):

    def __init__(self, maximumDrawdownPercent = 0.05):
        self.maximumDrawdownPercent = -abs(maximumDrawdownPercent)
        self.liquidated = set()

    def ManageRisk(self, algorithm, targets):
        targets = []
        for kvp in algorithm.Securities:
            security = kvp.Value

            pnl = security.Holdings.UnrealizedProfitPercent
            if pnl < self.maximumDrawdownPercent or security.Symbol in self.liquidated:
                # liquidate
                targets.append(PortfolioTarget(security.Symbol, 0))
                if algorithm.Securities[security.Symbol].Invested:
                    self.liquidated.add(security.Symbol)
                    algorithm.Log(f"Liquidating {security.Symbol}")

        return targets