diff --git a/dashboard.py b/dashboard.py index 6a494d0..96348d9 100644 --- a/dashboard.py +++ b/dashboard.py @@ -27,30 +27,25 @@ signal_functions: List[Dict[str, SignalFunction]] = [ ] symbol = 'SPY' +today = datetime.today() +data = ohlc(symbol = symbol, start_date = today - timedelta(days = 180), end_date = today) -def calculate_signals(data: DataFrame, days: int = 12) -> DataFrame: - end_date = datetime.today() - start_date = end_date - timedelta(days = days + 10) - data = ohlc(symbol = symbol, start_date = start_date, end_date = end_date) - - recent_signals = data.tail(days) +def calculate_signals(days: int = 12) -> DataFrame: signal_data = [] for signal_info in signal_functions: - signals = signal_info['function'](recent_signals) signal_dict = {'Strategy': signal_info['strategy']} - dates = [datetime.strptime(str(date), '%Y-%m-%d').strftime('%m/%d') for date in recent_signals['Date']] + + signals = signal_info['function'](data).tail(days) + dates = [datetime.strptime(str(date), '%Y-%m-%d').strftime('%m/%d') for date in data.tail(days)['Date']] for date, signal in zip(dates, signals): signal_dict[date] = signal - + signal_data.append(signal_dict) return DataFrame(signal_data) def load_chart() -> dict: - today = datetime.today() - data = ohlc(symbol = symbol, start_date = today - timedelta(days = 180), end_date = today) - candlestick_chart = CandlestickChart( x = data['Date'], opens = data['Open'], @@ -61,7 +56,7 @@ def load_chart() -> dict: return figure_with_subplots([[candlestick_chart]]) -signal_data = calculate_signals(DataFrame(), days = 12) +signal_data = calculate_signals() app.layout = dbc.Container( [