Overall Statistics
Total Trades
229
Average Win
9.71%
Average Loss
-3.95%
Compounding Annual Return
8.558%
Drawdown
57.200%
Expectancy
1.184
Net Profit
6632.814%
Sharpe Ratio
0.604
Probabilistic Sharpe Ratio
0.123%
Loss Rate
37%
Win Rate
63%
Profit-Loss Ratio
2.46
Alpha
0.056
Beta
0.988
Annual Standard Deviation
0.167
Annual Variance
0.028
Information Ratio
0.533
Tracking Error
0.105
Treynor Ratio
0.102
Total Fees
$0.00
Estimated Strategy Capacity
$0
import decimal

class FocusedYellowGreenFrog(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(1970, 1, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.spx = self.AddData(SPX, "SPX", Resolution.Daily).Symbol
        self.yield10yr = self.AddData(Yield10Yr, "yield", Resolution.Daily).Symbol
        
        self.period = 90
        self.SetWarmup(self.period)
        
        self.yield_average = self.SMA(self.yield10yr, self.period, Resolution.Daily)
        self.yield_std = self.STD(self.yield10yr, self.period, Resolution.Daily)
        
        self.thresh = 2.5
        
        self.month = None

    def OnData(self, data):
        if not data.ContainsKey(self.yield10yr): return
    
        yield_thresh = self.yield_average.Current.Value + self.thresh*self.yield_std.Current.Value
        yield_value = data[self.yield10yr].Value
        
        if self.Time.month != self.month:
            self.month = self.Time.month
            self.Plot("Yield", "Threshold", yield_thresh)
            self.Plot("Yield", "Value", yield_value)
            self.Plot("Yield Difference", "Difference", yield_value - yield_thresh)
        
        if yield_value > yield_thresh:
            self.SetHoldings(self.spx, 0)
        elif not self.Portfolio.Invested:
            self.SetHoldings(self.spx, 1)
    

class SPX(PythonData):
    '''S&P 500 Index Data'''

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


    def Reader(self, config, line, date, isLive):
        # If first character is not digit, pass
        if not (line.strip() and line[0].isdigit()): return None

        data = line.split(',')
        spx = SPX()
        spx.Symbol = config.Symbol
        spx.Time = datetime.strptime(data[0], '%d/%m/%Y')# + timedelta(days=1)
        spx.Value = decimal.Decimal(data[1])

        return spx


class Yield10Yr(PythonData):
    '''10 Year Treasury Constant Maturity Rate'''

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


    def Reader(self, config, line, date, isLive):
        # If first character is not digit, pass
        if not (line.strip() and line[0].isdigit()): return None

        data = line.split(',')
        yield10yr = Yield10Yr()
        yield10yr.Symbol = config.Symbol
        yield10yr.Time = datetime.strptime(data[0], '%d/%m/%Y')# + timedelta(days=1)
        yield10yr.Value = decimal.Decimal(data[1])

        return yield10yr