Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
gap closing - help for universe

Hi all,

I am playing a bit with a simple gap closing algo but I would like to backtest it on a unviverse of stocks. However, I am getting an error message when I try to substitute single stock selection with set universe function...Can you pls have a look at my code and help me to find a solution?

The error message is related to line 48 and line 59 when i try to look for multiple conditions on the universe.

Thanks in advance!!!

Matteo

5 responses

Matteo, where is the error? The code above appears to run fine.

Is there a particular section you're trying to tune?

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.

Trading gaps has peaked my interest for a while now, but I haven't found the winning formula.

I rewrote this algo to include support for a large universe and I am sharing it with the Quantopian community to give back. If anyone else has improvements, please share!

Thanks,

Tristan

Hi Tristan,

I have been playing a bit with the algo and it seems that the gap momentum strategy performs better than the gap closing one, in my opinion mainly because of the poor risk return for the gap closing strategies in general. I removed the end of day closing of all positions, to let winning trades fly until they reach take profit. Below is an interesting backtest, I would like to add a trailing stop instead of fixed stop loss and take profit. Let me know what you think about it.

Matteo, Good research.

However, it looks like you removed the daily "close positions" logic, which is fine, but the algo uses too much leverage. We can add a modification to the ordering logic to only use the amount of cash available. I'll work on adding that functionality...

Yes, thank you Tristan. In my opinion it would be also good to try a trailing stop version of the algo...