Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-19.258
Tracking Error
0.158
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
class FocusedBlueMosquito(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 11, 6)  # Set Start Date
        self.SetEndDate(2020, 11, 10)
        self.SetCash(100000)  # Set Strategy Cash
        self.symbol = self.AddEquity("SPY", Resolution.Minute).Symbol
        self.gap_finder = GapFinder(self, self.symbol, 10)
        self.Log(f"Gap finder log:\n{self.gap_finder.log.to_string()}")
        
        
class GapFinder:
    def __init__(self, algorithm, symbol, days):
        # Warm up history
        history = algorithm.History(symbol, days + 1, Resolution.Daily)
        if history.empty:
            self.log = pd.DataFrame()
            return
        history = history.loc[symbol].drop('volume', axis=1)
        
        # Calculate gaps
        history['yesterdays_close'] = history['close'].shift(1)
        history['gap'] = history.open - history.yesterdays_close 
        history = history.dropna()
        
        # Check which gaps have filled
        for time, row in history.iterrows():
            if row.gap == 0:
                continue
            
            filled = False
            for future_time, future_row in history.loc[time:].iterrows():
                gap_up_filled = row.gap > 0 and future_row.low <= row.close
                gap_down_filled = row.gap < 0 and future_row.high >= row.close
                if gap_up_filled or gap_down_filled:
                    filled = True
                    break
            history.loc[time, 'filled'] = filled
            
        # Save gap log
        self.log = history