Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Random Forest for Universe of Stock - Extension of ( Simple Machine Learning Example )

Hi,

This is an extension of “Simple Machine Learning Example” by Gus Gordon. This code has a capacity to train the data using random forest of each stock for the whole universe.

Let me first start by saying this is very inefficient code and is not suitable for testing with minute data. The reason is that I am accessing historical price data ( the last 500 or so days ) each time I called handle_data function. So, that is clearly a waste since I should have just stored the last 500 days of price data and add the last piece each new day.

Since the contents of stocks we are testing are constantly changing, I am thinking to create a dictionary of deque. Please let me know if you think there is a better way.
Currently, I don’t understand enough of the underlying structure when I accessing “data” by calling “handle_data(context,data)” I tried to print it. It looks something like this. I cannot see the whole data since there is logging limit.

And, I cannot see the type of this “data” since Quantopian prohibits the use of function “type.” So, I would really appreciate if someone tells me more about this data so that I can manipulate and access each part of ‘data’ object.
For strategy perspective, it appears that feeding only its own historical price series is not enough to create a profitable machine learning algorithm, ( at least for this Random Forest. ) I will try other classification algorithms later on..

BarData({Security(14848, symbol='YHOO', security_name='YAHOO INC', exchange='NASDAQ GLOBAL MARKET', start_date=datetime.datetime(1996, 4, 12, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 10, 29, 0, 0, tzinfo=), first_traded=None): SIDData({'high': 34.47, 'price': 33.875, 'volume': 17874901, 'open_price': 33.99, 'low': 33.67, 'sid': Security(14848, symbol='YHOO', security_name='YAHOO INC', exchange='NASDAQ GLOBAL MARKET', start_date=datetime.datetime(1996, 4, 12, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 10, 29, 0, 0, tzinfo=), first_traded=None), 'source_id': 'DynamicTradeSource9ff47b00706a65c8c7907de35ef40e9e', 'close_price': 33.875, 'dt': datetime.datetime(2014, 5, 20, 0, 0, tzinfo=), 'type': 4}), Security(5121, symbol='MU', security_name='MICRON TECHNOLOGY INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 10, 29, 0, 0, tzinfo=), first_traded=None): SIDData({'high': 27.16, 'pri...