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

2 responses

Yes, you could use something like this:

daily_ohlc = data.history(symbol('SPY'), ['open', 'high', 'low', 'close'], 252, '1d')

weekly_ohlc = daily_ohlc.resample('1W').agg({'open': 'first',  
                                 'high': 'max',  
                                 'low': 'min',  
                                 'close': 'last'})

monthly_ohlc = daily_ohlc.resample('1M').agg({'open': 'first',  
                                 'high': 'max',  
                                 'low': 'min',  
                                 'close': 'last'})  

Is that what you were looking for?

Hi Ishwar,

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

Cheers,
John