Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem with combining momentum strategy and Alpha #41

Hi all,

I'm having difficulties combining a momentum strategy (a mean-reversion strategy I found, flipped on its head) with an algorithm using Alpha #41 from the 101 Alphas project. If anyone could point me in the right direction I'd really appreciate it. Thanks.

3 responses

I looked at just having this trade...
troubleshooting:
- not trading... likely some code contradiction
- went to before trading (to see full data set that you then cut and slice as you want)...added a breakpoint on line 84/log.info to see results of long and short list
- both lists are running empty
- looked at code line 80 and 82 and they each create a mutually exclusive sample of stocks (one cannot be in the other...simplistic assumption stemming from 50th percentile usage of daily volume should provide hundreds of stocks)
- looked at 'output' and dataframe shows that each row will have a np.nan in either one or both of the high/low alpha 41 column
- long and short list both created using output.dropna(axis=0). ---the dropna ends up removing entire row if has one nan value, and since 'output' rows have nan in either one or both columns,output.dropna(axis=0) ends up removing every stock from 'output'
- removed dropna and now trading

    high_returns = recent_returns.percentile_between(70,100)  
    low_returns = recent_returns.percentile_between(0,30)  

note the low and high returns code of including the extremities of 0 and 100 ends up including the 'one-offs' of 5000% returns or -99.5% losses if you dont either zscore fix it or more simply use like 1.25 / 98.75

please excuse the brevity

your other post suggests you are recently starting to get acquainted with Q and algos and all ...have fun with attached ... still requires you to dig much deeper to understand the guts of whats going on etc. Using breakpoints is probably going to be one of your best friends as you get more familiar with these

I really appreciate the feedback, thanks. I hadn't been aware of the breakpoint feature, it looks like it'll help me out a lot. I will use it generously in any future code!