Back to Community
Random Forest Classification

This was more about testing the concept than anything else--in a real production I would want to check the amount of money I have, make sure that I don't have conflicting trades, etc.

Clone Algorithm
171
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5542b7aa29c3d90d2422784c
There was a runtime error.
5 responses

Brett, thanks for posting. Looks really interesting and I think exploring random forest classifiers is an interesting avenue.

In case you want to retrain the model you could use the schedule_func() functionality. Moreover, it would be cool to somehow track the number of correct predictions to see if it actually filters out any signal. I know this is mainly meant as a framework for blackbox algorithms but those metrics would also be useful irrespective of the way the ML algo is trained.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Brett, why are you applying a ML algo on one stock?

@Thomas Thanks, I'll look into that, there are always new functions here for me to explore
@Aaron mostly because this is for coursework, and is more of a proof of concept than an actual implementation--if you look at the code you can see that I set i=0--the reason is that it would make it easy later to iterate through a list of stocks. I definitely will play with this concept more, but I really just wanted to get a working implementation out there. I also figured I'd share my work, because I always get great comments on how I can improve what I've got out there.

Sorry, but it seems to me that this algo is fundamentally wrong (= no correlation between the random forest prediction and results). I have just found this algo and at first look it was an interesting concept, but I have added just some log print and it shows:
- prediction is -1 on 08/16/2011, 08/17/2011, 08/29/2011, 11/10/2011 and +1 on 09/13/2011
- prediction is 0 on all other days, so most of the time
- leverage is continuously growing, at the end it equals 3.4288486196
- position amount is 90960 at the end

The problem is that after the first -1 prediction + 5 days the "Iterate through and sell stocks that need to be sold" part starts executing and never stops. It continuously buys 20 stock in every day from that time. So the result is caused by this part of the algo and not the random forest.

Another interesting insight if you print out the feature importances of trainig set ( log.info(clf.feature_importances_) ):
[ 0.0226167 0.02402722 0.03290289 0.03810386 0.03319766 0.05443647 0.04481815 0.02837444 0.02219877 0.03530863 0.02546308 0.03016573
0.02440857 0.03986063 0.01865393 0.02430047 0.03319342 0.0348683
0.04663834 0.03969558 0.05259424 0.02008375 0.05023988 0.036746
0.03870388 0.04181752 0.0436984 0.03384612 0.02903738]

mean | 0.03442
median | 0.0338
sample standard deviation | 0.009821

This means 30 days history prices importance is more or less equally distributed as you expect. There is no real prediction power based on history prices.

Thanks for the input--this was definitely far from ideal implementation--it was done for a homework assignment.