Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
-0.46%
Compounding Annual Return
-5.545%
Drawdown
1.000%
Expectancy
-1
Net Profit
-0.463%
Sharpe Ratio
-1.849
Probabilistic Sharpe Ratio
18.853%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.071
Beta
0.054
Annual Standard Deviation
0.03
Annual Variance
0.001
Information Ratio
-2.903
Tracking Error
0.113
Treynor Ratio
-1.042
Total Fees
$2.29
Estimated Strategy Capacity
$25000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
class JumpingTanAnguilline(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 7, 1)
        self.SetEndDate(2021, 8, 1)
        self.SetCash(100000) 
        self.AddEquity("SPY", Resolution.Minute)
        
        self.AddAlpha(CustomTrailingStopForFlatInsightAlpha(0.01))
        
        self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())

class CustomTrailingStopForFlatInsightAlpha(AlphaModel):
    
    def __init__(self, maximumDrawdownPercent = 0.05):
        self.maximumDrawdownPercent = -abs(maximumDrawdownPercent)
        self.trailingHighs = dict()
        
    def Update(self, algorithm, data):
        insights = []
        
        # entry for test
        if algorithm.Time.day == 12 and algorithm.Time.hour == 9 and algorithm.Time.minute == 40:
            insights.append(Insight.Price("SPY", Expiry.EndOfMonth, InsightDirection.Up))
        
        # We can move the whole TrailingStopRiskManagementModel here for checking and emitting flat insight
        for kvp in algorithm.Securities:
            symbol = kvp.Key
            security = kvp.Value

            # Remove if not invested
            if not security.Invested:
                self.trailingHighs.pop(symbol, None)
                continue

            # Add newly invested securities
            if symbol not in self.trailingHighs:
                self.trailingHighs[symbol] = security.Holdings.AveragePrice   # Set to average holding cost
                continue

            # Check for new highs and update - set to tradebar high
            if self.trailingHighs[symbol] < security.High:
                self.trailingHighs[symbol] = security.High
                continue

            # Check for securities past the drawdown limit
            securityHigh = self.trailingHighs[symbol]
            drawdown = (security.Low / securityHigh) - 1

            if drawdown < self.maximumDrawdownPercent:
                # liquidate
                insights.append(Insight.Price(symbol, Expiry.EndOfMonth, InsightDirection.Flat))

        return insights