import msyrs
import datetime

# "E:\Work\jpmaqs-data\data\ADPEMPL_SA_P1M1ML1\USD_ADPEMPL_SA_P1M1ML1.csv"

DATA_FOLDER_PATH = "E:/Work/jpmaqs-data"

dfpath = f"{DATA_FOLDER_PATH}/data/ADPEMPL_SA_P1M1ML1/USD_ADPEMPL_SA_P1M1ML1.csv"

print(msyrs.qdf.load_qdf(dfpath))

cids_dm = "AUD.CAD.CHF.EUR.GBP.JPY.NOK.NZD.SEK.USD".split(".")
cids_em = "CLP.COP.CZK.HUF.IDR.ILS.INR.KRW.MXN.PLN.THB.TRY.TWD.ZAR".split(".")
cids = cids_dm + cids_em
cids_dux = list(set(cids) - set(["IDR", "NZD"]))
ecos = "CPIC_SA_P1M1ML12.CPIC_SJA_P3M3ML3AR.CPIC_SJA_P6M6ML6AR.CPIH_SA_P1M1ML12.CPIH_SJA_P3M3ML3AR.CPIH_SJA_P6M6ML6AR.INFTEFF_NSA.INTRGDP_NSA_P1M1ML12_3MMA.INTRGDPv5Y_NSA_P1M1ML12_3MMA.PCREDITGDP_SJA_D1M1ML12.RGDP_SA_P1Q1QL4_20QMA.RYLDIRS02Y_NSA.RYLDIRS05Y_NSA.PCREDITBN_SJA_P1M1ML12".split(
    "."
)
mkts = "DU02YXR_NSA.DU05YXR_NSA.DU02YXR_VT10.DU05YXR_VT10.EQXR_NSA.EQXR_VT10.FXXR_NSA.FXXR_VT10.FXCRR_NSA.FXTARGETED_NSA.FXUNTRADABLE_NSA".split(
    "."
)
xcats = ecos + mkts

tickers = [f"{c}_{x}" for c in cids for x in xcats]


# load_qdf_from_download_bank

df = msyrs.qdf.load_qdf_from_download_bank(
    folder_path=DATA_FOLDER_PATH, tickers=tickers
)
print(df)

start_date = (datetime.datetime.now() - datetime.timedelta(days=5)).strftime("%Y-%m-%d")

sel_cids = ["AUD", "USD", "GBP", "CAD", "JPY", "EUR"]
df_eq = msyrs.qdf.reduce_dataframe(
    df=df, cids=["AUD"], xcats=["EQXR_NSA"], start=start_date
)
print(df_eq)

fx_xcats = [xc for xc in xcats if xc.startswith("FX")]
df_fx = msyrs.qdf.reduce_dataframe(df=df, xcats=fx_xcats, intersect=True)
print(df_fx)
