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
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: 5862d3a2e0eafe5e6f0d2a3b
There was a runtime error.
3 responses

I looked at just having this trade...
troubleshooting:
- 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

7
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: 58631fdfc48dcc5e75f65aa4
There was a runtime error.

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

7
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: 58632647004af55e7e8b8ec4
There was a runtime error.

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!