from __future__ import annotations from dataclasses import dataclass from pathlib import Path import pandas as pd from .indicators import rsi, macd @dataclass class DataBundle: df_sentiment: pd.DataFrame df_transcript: pd.DataFrame df_bn_hourly: pd.DataFrame df_news: pd.DataFrame df_bn_1m: pd.DataFrame df_nifty_daily: pd.DataFrame def copy(self) -> "DataBundle": return DataBundle( self.df_sentiment.copy(), self.df_transcript.copy(), self.df_bn_hourly.copy(), self.df_news.copy(), self.df_bn_1m.copy(), self.df_nifty_daily.copy(), ) def _read_excel(path: Path) -> pd.DataFrame: if not path.exists(): raise FileNotFoundError(path) return pd.read_excel(path) def load_data(paths) -> DataBundle: df_sent = _read_excel(paths.sentiment_pred) df_tx = _read_excel(paths.zerodha_tx) df_bn_hourly = _read_excel(paths.banknifty_hourly) df_news = _read_excel(paths.bank_news) df_bn_1m = _read_excel(paths.banknifty_1m) df_nifty = _read_excel(paths.nifty_daily) # Parse dates if "predicted_for" in df_sent.columns: df_sent["predicted_for"] = pd.to_datetime(df_sent["predicted_for"]) if "Prediction_for_date" in df_tx.columns: df_tx["Prediction_for_date"] = pd.to_datetime(df_tx["Prediction_for_date"], dayfirst=True) for df in (df_bn_hourly, df_bn_1m, df_news, df_nifty): for c in df.columns: if "date" in c.lower() or c.lower() == "datetime": try: df[c] = pd.to_datetime(df[c]) except Exception: pass # Indicators df_bn_hourly = rsi(df_bn_hourly) df_bn_hourly = macd(df_bn_hourly) df_nifty = rsi(df_nifty) df_nifty = macd(df_nifty) return DataBundle( df_sentiment=df_sent, df_transcript=df_tx, df_bn_hourly=df_bn_hourly, df_news=df_news, df_bn_1m=df_bn_1m, df_nifty_daily=df_nifty, )