Convert daily pandas stock data to monthly data using first trade day of the month

前端 未结 3 767
一生所求
一生所求 2020-12-30 16:41

I have a set of calculated OHLCVA daily securities data in a pandas dataframe like this:

>>> type(data_dy)


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 16:51

    I've seen in the last version of pandas you can use time offset alias 'BMS', which stands for "business month start frequency" or 'BM', which stands for "business month end frequency".

    The code in the first case would look like

    data_dy.resample('BMS', closed='right', label='right').apply(ohlc_dict)
    

    or, in the second case,

    data_dy.resample('BM', closed='right', label='right').apply(ohlc_dict)
    

提交回复
热议问题