Overall Statistics
Total Trades
23
Average Win
3.21%
Average Loss
-0.51%
Compounding Annual Return
20.072%
Drawdown
8.500%
Expectancy
2.625
Net Profit
20.052%
Sharpe Ratio
1.538
Probabilistic Sharpe Ratio
70.454%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
6.25
Alpha
0.125
Beta
0.079
Annual Standard Deviation
0.091
Annual Variance
0.008
Information Ratio
-0.353
Tracking Error
0.135
Treynor Ratio
1.768
Total Fees
$36.63
Estimated Strategy Capacity
$89000000.00
Lowest Capacity Asset
SPY 2T
class WellDressedYellowCat(QCAlgorithm):

    def Initialize(self):
        # parameters:
        startingCash = 100000
        trailingStop = 0.04
        self.longEntryThreshhold = 0.15
        self.shortEntryThreshhold = -0.15
        self.longAllocation = 1 # 100% long
        self.shortAllocation = -1 # 100% short
        symbol = "SPY"
        
        self.SetStartDate(2021, 1, 1)  # Set Start Date
        self.SetEndDate(2022, 1, 1)
        self.SetCash(startingCash)  # Set Strategy Cash
        self.symbol = self.AddEquity(symbol, Resolution.Minute).Symbol
        self.tli = self.AddData(TLI, "tli", Resolution.Minute).Symbol
        
        self.AddRiskManagement(TrailingStopRiskManagementModel(trailingStop))


    def OnData(self, data: Slice):
        if self.tli in data:
            if data[self.tli].Value > self.longEntryThreshhold:
                self.SetHoldings(self.symbol, self.longAllocation)
            elif data[self.tli].Value < self.shortEntryThreshhold:
                self.SetHoldings(self.symbol, self.shortAllocation)
    

class TLI(PythonData):

    def GetSource(self, config, date, isLive):
        source = "https://www.dropbox.com/s/zlm00njnufrhnko/TLI.csv?dl=1"
        return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);

    def Reader(self, config, line, date, isLive):
        if not (line.strip() and line[0].isdigit()):
            return None
        
        data = line.split(',')
        tli = TLI()
        
        try:
            tli.Symbol = config.Symbol
            # make data available Monday morning (Friday 16:00 + 66 hours) 
            # since we can't trade on weekend anyway
            tli.Time = datetime.strptime(data[0], '%Y-%m-%d %H:%M:%S') + timedelta(hours=66)
            
            tli.Value = data[1]
            
        except ValueError:
            return None
        
        return tli