获取上一个交易日—python

获取上一个交易日—python

    • 直接上代码

直接上代码

import tushare as ts
import datetime
def last_train_data():
    alldays = ts.trade_cal()
    tradingdays = alldays[alldays['isOpen'] == 1]   # 开盘日
    nowTime = time.mktime(time.strptime( datetime.datetime.now().strftime('%Y-%m-%d'),"%Y-%m-%d"))
    trandtime = time.mktime(time.strptime(tradingdays['calendarDate'].values[-1],"%Y-%m-%d"))
    i=1
    while int(nowTime)-int(trandtime)<0:
        i+=1
        trandtime = time.mktime(time.strptime(tradingdays['calendarDate'].values[-i],"%Y-%m-%d"))
    trandtime=tradingdays['calendarDate'].values[-i]
    return trandtime

你可能感兴趣的:(python,python)