Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Newbie Question - Accesing different timeframes

Hi,

Is it possible within the python code to access different timesframes for things such as Close, MACD, MMA/E. Bollinger Bands etc?

If so, could you provide me with an example.

Thanks,

5 responses

Yes, it is possible, I'm not sure how familiar with Python you are, but a good place to get started would be to learn the pandas data structures. Pandas is a powerful data analysis library you have access to, along with several other scientific libraries like statsmodels, numpy, and scipy.

I'm not sure what MMA/E is, but I think it's the rainbow of moving averages, here's an example that plots several moving averages and invests 25% of the account for each one that the price is currently above.

Hi,

Thanks for your reply.

Sorry, MMA/E are simple moving averages and exponential moving averages in English so your example does help.

My python knowledge is limited and pandas seems beyond me at the moment. Would you be able to give me an example of how to use pandas to formulate a weekly and/or monthly close values from the available data? This should give me something to go on.

Thanks once again for your help.

BUMP

Hey Andrew,
Pandas has a resample function that will work perfectly for getting weekly and monthly values. This backtest has an example. Note that the field 'price' in the history function is the close prices, but any missing dates will be forward filled. If you do not want the data to be forward filled, replace 'price' with 'close_price'

If you have a regular Python list, array slicing has 3 parts, (start index, end index, step size), if you wanted to select every N element, use some_list[start: stop: N]. If you want to include the entire list, you can simplify that down to, some_list[::N], hope this answered your question.

David

Thanks very much, that helps greatly! :-)