Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
buy at 4pm when stock opens down 8% or more

first post!
the cool thing i'm finding about this site is it allows me to test trading strategies i've been using for years but never really knew if they worked. surprise! it doesn't. i'm wondering if i'm missing anything or anyone has an idea if it can be improved. when i do this on my own i a) don't buy $5000 worth of a stock each time, and b) typically buy at the open (or near to the open) rather at the close, but 4pm seems to work better in my tests.
i am a total newbie with python and algos too so please be gentle! :)

4 responses

Hey Dan!

Great first post, you're already doing a few of the best practices. I was surprised too when I started moving my strategies onto Quantopian, it helped me realize what I was doing well and what I was doing poorly.

Check out this thread for some tutorials on Python and Quantopian.

One last thing to point out related to what you something you said above. I see in your code you have schedule function commented out. We highly recommend that you use schedule function instead of writing your own date/time code. Schedule function is far more robust. The thing you said above that I want to address is "but 4pm seems to work better in my tests." please be careful about over fitting your algo, and making changes just because it performs better in the backtest. Try that new change in a different backtest, or live trading and it might not perform as well as you hope. Also be careful to when submitting orders near market open or close, as you can run into slippage, and liquidity issues for some securities that you may not be dealing with when trading with smaller amounts of capital.

You're off to a good start, happy coding!

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.

I'm trying to determine if a successful strategy for buy/hold could consist of an algo like above, whereby a buy order for an index like SPY would be bought up to once per day when the SPY is down 3% or more at 15:45.

My coding expertise is very limited. I was able to amend the algo on percentage, but I don't understand how to make the changes to do what I want here.

My apologies-- the attached is that which I intended to attach.

Hi Patrick,

Thanks for posting. Your strategy idea is a good one, but the code from the original post on this thread uses some deprecated elements of the API. It would be good for you to hone your skills with Python, and then get started on an algorithm from scratch using the tools (such as Pipeline) that have been developed in the year since this thread started.

First you should take a look at some learning materials for Python. A few good sources are listed under "How do I learn to write Python?" on the FAQ. Then, go through the Getting Started Tutorial for an introduction to writing algorithms on Quantopian.

After that, I hope you'll have enough knowledge to start writing an algorithm of your own. If you need any help with it, just ask.

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.