import pandas as pd
from pathlib import Path
import sys

BASE_PATH = Path(__file__).resolve().parents[2]
SRC_PATH = BASE_PATH / "src"

if str(SRC_PATH) not in sys.path:
    sys.path.append(str(SRC_PATH))

from features.spot_lag_v3 import get_model_ready_spot_lag_v3


def run_mae_test():

    df = get_model_ready_spot_lag_v3().copy()

    # future horizon
    horizon = 24

    df["future_min"] = df["close"].rolling(horizon).min().shift(-horizon)
    df["future_max"] = df["close"].rolling(horizon).max().shift(-horizon)

    df["mae_long"] = (df["future_min"] - df["close"]) / df["close"]
    df["mae_short"] = (df["future_max"] - df["close"]) / df["close"]

    longs = df[df["signal_direction_v3"] == 1]
    shorts = df[df["signal_direction_v3"] == -1]

    print("\nLONG MAE stats:")
    print(longs["mae_long"].describe())

    print("\nSHORT MAE stats:")
    print(shorts["mae_short"].describe())


if __name__ == "__main__":
    run_mae_test()