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
-54.138
Tracking Error
0.081
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
# region imports
from AlgorithmImports import *
# endregion

class JumpingBrownCrocodile(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2023, 1, 10)
        self.set_end_date(2023, 1, 16)
        self.set_cash(100000)
        baba = self.add_equity("BABA", Resolution.MINUTE)
        baba.set_data_normalization_mode(DataNormalizationMode.SPLIT_ADJUSTED)
        self.baba = baba.symbol

        # Rolling Windows - Daily
        self.window_daily = STRAT_Rolling_Window(5)

        # Data Subscriptions - 15 Minute, Daily, Weekly, Monthly and Quarterly
        self.daily_consolidator = self.consolidate(self.baba, Resolution.DAILY, self.on_daily_consolidated)
        self.print_warm_up = False
        self.warm_up_done = False

        counter = 0
        historical_trade_bars = self.history[TradeBar](self.baba, 200, Resolution.DAILY) # Fetch maximum needed bars

        for trade_bar in historical_trade_bars:
            if counter > 195:
                self.print_warm_up = True
                self.log(f"Counter: {counter}; Trade Bar Info: {trade_bar}")
                self.log(f"Bar Time: {trade_bar.time}")
                self.log(f"Bar End Time: {trade_bar.end_time}")

            # Warm up consolidators
            self.daily_consolidator.update(trade_bar)
            counter += 1

        self.warm_up_done = True
            
    def on_data(self, data: Slice):
        if self.time.hour == 9 and self.time.minute == 31:

            if self.baba in data.bars:
                current_bar = data.bars[self.baba]
                self.log(self.time)
                self.log(f"It's exactly 9:31am, proof: {self.time}")
            else:
                self.log("No data at 9:31am")
        
        elif self.time.hour == 15 and self.time.minute >= 56:

            if self.baba in data.bars:
                current_bar = data.bars[self.baba]
                self.log(f"It's after 3:55pm, here's the exact date/time: {self.time}")
            else:
                self.log(f"No data at {self.time}")
        
        elif self.time.hour == 16 and self.time.minute == 0:
            self.log("Market closed")

    def on_daily_consolidated(self, bar):
        if self.print_warm_up and not self.warm_up_done:
            self.log(f"Warm Up Bar: {bar}")
            self.log(f"Warm Up Bar Time: {bar.time}")
            self.log(f"Warm Up Bar End Time: {bar.end_time}")

        if self.warm_up_done is True:
            self.log(f"Daily bar was just consolidated: {bar}")

class STRAT_Rolling_Window:
    def __init__(self, max_len):
        self.max_len = max_len
        self.data = []

    def add(self, data):
        self.data.insert(0, data)
        if len(self.data) > self.max_len:
            self.data.pop()

    def __getitem__(self, index):
        return self.data[index]

    def __len__(self):
        return len(self.data)

    def is_ready(self):
        return len(self.data) == self.max_len

    def reset(self):
        self.data = []