Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
100000
End Equity
100000
Net Profit
0%
Sharpe Ratio
0
Sortino 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
-27.101
Tracking Error
0.104
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
Drawdown Recovery
0
# region imports
from AlgorithmImports import *
# endregion

class GeekyOrangePig(QCAlgorithm):

    def initialize(self):
        # These throw the error because on_warmup_finished runs at midnight on Feb 1st, 
        # which is the same time as when _select_assets runs:
        self.set_start_date(2021, 1, 30)  # Saturday
        #self.set_start_date(2021, 1, 31)  # Sunday
        #self.set_start_date(2021, 2, 1)    # Monday

        # These date doesn't throw the error:
        #self.set_start_date(2021, 1, 29) 
        #self.set_start_date(2021, 2, 2)

        self.set_end_date(self.start_date + timedelta(10))

        self.settings.seed_initial_prices = True
        self._calls = 0
        self.universe_settings.resolution = Resolution.DAILY
        self.universe_settings.schedule.on(self.date_rules.month_start("SPY"))
        self.add_universe(self._select_assets)
        self.set_warm_up(timedelta(450))

    def _select_assets(self, fundamentals):
        self._calls += 1
        self._longs = [list(fundamentals)[self._calls].symbol]
        self._shorts = []
        return self._longs + self._shorts

    def _rebalance(self):
        if self.is_warming_up:
            return  
        for symbol in self._longs + self._shorts:
            if symbol not in self.securities:
                self.quit(f'{symbol} not in self.securities')

    def on_warmup_finished(self):
        time_rule = self.time_rules.at(8, 0)
        self.schedule.on(self.date_rules.month_start("SPY"), time_rule, self._rebalance)
        self.schedule.on(self.date_rules.today, time_rule, self._rebalance)