pythonで日本の金融市場の前営業日取得

chatGPTに聞いたやつを整頓。
'TSE'は使えなかったので'Financial_Markets_JP'を指定。これであってるのかは不明。
情報が古かったのかな。

import pandas_market_calendars as mcal

def get_prev_bizdayTSE(date):

    date = datetime.datetime.strptime(date, '%Y/%m/%d').date()
    tdy = mcal.get_calendar('Financial_Markets_JP').valid_days(start_date=date, end_date=date)[0]
    prev_day = (tdy - datetime.timedelta(days=1)).date()
    bday = mcal.get_calendar('Financial_Markets_JP').valid_days(start_date=prev_day, end_date=prev_day)[0].date()
    while bday != prev_day:
        prev_day = prev_day - datetime.timedelta(days=1)
        bday = mcal.get_calendar('Financial_Markets_JP').valid_days(start_date=prev_day, end_date=prev_day)[0].date()
    return bday.strftime('%Y/%m/%d')