Back to Community
Neural Network that tests for mean-reversion or momentum trending

This is a simple neural network, much of which is taken from here

It uses the Hurst Exponent and the Sharpe Ratio as inputs and trains for a small amount of days before actually using stock data. If the output of the neural network is < 0.2 there's hope that it's mean-reverting and if it's greater than 0.8, there's hope that it's momentum trending.

Things to note:

  • From my testing, it doesn't seem to be detecting momentum trending data when used with actual S&P
  • Bias with the S&P as it's been on-rise since the last three years
  • After a while, the output of the neural network seems to converge to -1, almost indefinitely, so limiting the amount of training days would be a good idea.

The algorithm definitely needs a lot of work so please feel free to play around with it and post back your suggestions.

Edit** The output seems to converge to -1 regardless of training depth, if anyone has some input on this, please feel free to contribute!

Much credit goes to Tom Starke
-Seong

Clone Algorithm
1234
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: 5249b62092cd0106d0af9f2a
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.
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.

10 responses

Hi Seong,
I haven't had time to look over your algo yet but the returns seem to be way too high. This post here points out what the problem might be.

Tom

Limited leverage a bit and the returns have cooled down a lot. Definitely looking for a better way to check the validity of the output, open to suggestions!

-Seong

Clone Algorithm
303
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: 52653e1199f7120756d20571
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.

Hello Seong,

Does this algo give a different result each time it is run? That is what I find although some returns (23.8%, 70.4%) do re-occur.

Regards,

Peter

It is normal to get different results with neural networks. The network can be slightly different every time you train it. Even with the same data.

I guess that itself (consistency of results) might be an indicator of the strength of a model.

Seong...how can you make this constant... so that it ill be reliable....https://www.quantopian.com/posts/neural-network-that-tests-for-mean-reversion-or-momentum-trending

John, you could try to set the random seed with numpy.random.seed() or do a static initialization of the weights.

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.

wat line... do I substitute that numpy.random.seed()??

In initialize you would put numpy.random.seed(123). http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html

already put numpy.random.seed(123). @ initialize its still random...

I kinda did that before. The biggest problem here is that it could be quite confusing when the ranges of the output result are small, say, 0.2-0.21, or , 0.6-0.62. How are you gonna distinguish btw a momentum and a trend with these paras?