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
-5.79
Tracking Error
0.115
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
from AlgorithmImports import *

class SymbolData:
    def __init__(self, algorithm, symbol, rsi_period):
        self.algorithm = algorithm
        self.symbol = symbol
        self.rsi = algorithm.RSI(symbol, rsi_period, Resolution.Daily)
        self.rsi_history = []
        
    def update(self, time, price):
        if self.rsi.IsReady:
            current_rsi = self.rsi.Current.Value
            self.rsi_history.insert(0, current_rsi)
            if len(self.rsi_history) > 3:
                self.rsi_history.pop()
            
            # Log RSI values
            self.algorithm.Debug(f"{time}: {self.symbol} - RSI: {current_rsi:.2f}, History: {[f'{x:.2f}' for x in self.rsi_history]}")
        else:
            self.algorithm.Debug(f"{time}: {self.symbol} - RSI not ready")

class RSIHistoryIssueDemo(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2024, 11, 1)
        self.SetCash(100000)
        self.SetWarmup(30)
        
        # Multiple symbols from Option Alpha universe for demonstration
        self.symbols = ["AAL", "AAPL", "ABBV", "AMD", "AMZN"]
        self.Log(f"Monitoring symbols: {', '.join(self.symbols)}")
        
        self.rsi_period = 5
        self.symbols_data = {}
        
        # Initialize data for each symbol
        for symbol in self.symbols:
            equity = self.AddEquity(symbol, Resolution.Daily)
            self.symbols_data[symbol] = SymbolData(self, symbol, self.rsi_period)
            
            # Get historical data for each symbol
            history = self.History(equity.Symbol, 30, Resolution.Daily)
            history_df = history.loc[equity.Symbol]
            self.Debug(f"Requested 30 days of history for {symbol}, received {len(history_df)} bars")
            
            # Process historical data
            for index, row in history_df.iterrows():
                self.symbols_data[symbol].update(index, row['close'])

        self.Schedule.On(self.DateRules.EveryDay(), 
                        self.TimeRules.At(10, 0), 
                        self.CheckRSIHistory)

    def CheckRSIHistory(self):
        self.Log(f"\n{'='*50}")
        self.Log(f"RSI History Check at {self.Time}")
        self.Log(f"{'='*50}")
        
        for symbol, data in self.symbols_data.items():
            if self.Securities[symbol].Price != 0:  # Only log if we have price data
                current_price = self.Securities[symbol].Close
                data.update(self.Time, current_price)

    def OnData(self, data):
        pass