Overall Statistics
Total Trades
110
Average Win
0.35%
Average Loss
-0.24%
Compounding Annual Return
2.118%
Drawdown
1.600%
Expectancy
0.412
Net Profit
5.598%
Sharpe Ratio
1.011
Probabilistic Sharpe Ratio
50.032%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
1.43
Alpha
0.017
Beta
0.032
Annual Standard Deviation
0.021
Annual Variance
0
Information Ratio
-0.524
Tracking Error
0.233
Treynor Ratio
0.668
Total Fees
$110.00
class TurnaroundTuesdayAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2018, 1, 1)
        self.SetCash(30000)
        self.ar = .33 # allocation ratio
        
        self.spy = self.AddEquity("SPY", Resolution.Minute)
        self.symbol = self.spy.Symbol

        self.monday_open = 0
        self.monday_down = False


    def OnData(self, data):
        if not data.ContainsKey(self.symbol) or data[self.symbol] is None:
            return
        
        if data.Time.weekday() == 0: # Monday
            if data.Time.hour == 9 and data.Time.minute == 31: # Open bar
                self.monday_open = data[self.symbol].Open
            
            if not self.spy.Exchange.DateTimeIsOpen(data.Time): # Close bar
                self.monday_down = data[self.symbol].Close < self.monday_open
                if self.monday_down:
                    self.quantity = self.CalculateOrderQuantity(self.symbol, self.ar)
                    if self.quantity > 0:
                        self.MarketOrder(self.symbol, self.quantity)
                    return
        
        if self.monday_down: # Fired on Tuesday at the open
            if self.quantity > 0:
                self.MarketOnCloseOrder(self.symbol, -self.quantity)
            self.monday_down = False