import pandas as pd
import numpy as np

def load_data(file_path='data/data.csv'):
    try:
        df = pd.read_csv(file_path)
        df['date'] = pd.to_datetime(df['date'])
        df.set_index('date', inplace=True)

        required_columns = ['Open', 'Close', 'active_addresses']
        missing_columns = [col for col in required_columns if col not in df.columns]

        if missing_columns:
            raise ValueError(f"Missing required columns: {missing_columns}")

        return df

    except FileNotFoundError:
        raise FileNotFoundError(f"{file_path} not found")
    except Exception as e:
        raise Exception(f"Error loading data: {str(e)}")

def get_default_date_range(df):
    """Get the earliest and latest dates from the dataframe"""
    return df.index.min().strftime('%Y-%m-%d'), df.index.max().strftime('%Y-%m-%d')


def zscore(x, window):
    return (x - x.rolling(window).mean()) / x.rolling(window).std()