Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to generate Weekly and Monthly OHLC Bars with Quantopian Data

Hi,

I am trying to work with either Weekly or Monthly OHLC bars. However, I am not sure how to do it. Is it possible to use data in this time-frequency?

Thanks,
John

4 responses

Hi Ishwar,

Many thanks! that was exactly what I was looking for.

Cheers,
John

Did anyone find an example of how to generate weekly and monthly bars?

This may help

def initialize(context):  
    schedule_function(resampled_data, date_rules.week_end(), time_rules.market_close())

def resampled_data(context, data):  
    stock = symbol('SPY')  
    OHLC = data.history(stock, ['open', 'high', 'low', 'close'], 5, '1d')  
    OHLC_W = OHLC.resample('1W-FRI').agg({'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last'})

    print(OHLC_W)  

Will aggregating data like this take into account the various market holidays? Good Friday, Christmas, etc.?