Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Momentum

A very simple backtest that follows intraday momentum. Ideas for expansion:

  • Choose among a universe of securities that have the highest momentum (or normalized momentum within their industry)
  • Is there a way to look at returns over longer periods than a day?
  • Combine with a value measure (book/price)
  • Combine with other Fama-French factors.
5 responses

Hello John,

I took a look at your algo, and I cloned it and ran it myself. I'm not positive it's doing what you intended to!

I added a debug line just before your "order" command, a buy version, and a sell version.

log.debug('newline '+ str(applemo) + ' - returns;' + str(data.portfolio.positions[sid(24)].amount) + ' - amount;' + str(data.portfolio.positions_value) + ' - positions value;' + str(data.portfolio.cash) + ' - cash;' + str((data.portfolio.positions_value + data.portfolio.cash)/data[sid(24)].price) + ' - buying!')  

Is that doing what you want it to?

Dan

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 not sure - it's meant to be fully invested at all times - long if the intraday return is positive; short if the intraday return is negative. I thought that's what I coded up.

Yeah, that's pretty much what it does. A couple thoughts:

  • It does a lot of ordering at market open. When the stock opens low
    you sell, and when it open high you buy - at that point you've missed
    a lot of the move already.
  • When the stock is roughly flat, you do a lot of buying and selling -
    look at 1/19/12 for instance.
  • You might look at doing a different window than straight up returns -
    try a moving daily average?
  • You might look at putting in a bigger step to trigger a trade -
    rather than buy and sell a lot on a flat day, only buy or sell if it
    moves a larger amount.

Yeah, this is a poor attempt at emulating a traditional quant momentum strategy. The typical timeframes there are monthly, rather than minute-ly, so you run into a lot of this rapid back-and-forth and non-continuous-time features.

Cool! I look forward to the next version!