Back to Community
[deleted]
12 responses

I added a pipeline and a few filters. It was running really slowly so I only backtested it for a month. There were lots of unfilled orders but it seemed to be generating a profit. Looking back at the results, it seems like the pipeline was mostly returning small caps and even a few mid caps instead of just penny stocks. This wouldn't work very well with commissions.

Clone Algorithm
28
Loading...
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: 596de14e8bb376520f030931
There was a runtime error.

I worry on backtests like these that the penny stocks could be so thinly traded the backtest won't match actual results

Think the original algorithm was using penny stocks and the pipeline version is mostly returning small caps. The pipeline version used Q1500 as one of the filters and when I looked at the stocks it was trading, many of them were over $1B market cap and were worth $10-$50 per share. Alpha might be higher with actual penny stocks, but capacity could be a lot higher with small caps. Looks like multiple people are interested in trading this so I want to see if capacity can be increased further.

I am not sure it's faster, but it is nicer:

price_hist_shifted = hist.shift(1)  
support_retests = sum( (hist <= low_threshold) & (price_hist_shifted > low_threshold) )  
resistance_retests = sum( (hist >= high_threshold) & (price_hist_shifted < high_threshold) )  

Also, pay attention to this zipline "behaviour": https://www.quantopian.com/posts/simulation-of-non-marketable-limit-orders
When you use limit orders you get better execution price on zipline than reality, especially on low volume securities.

I encountered that problem with two algorithms that I traded via IB. Fantastic results on backtests, horrible in live trading. Am I sure the bad performance was due to that bug mentioned above? No, I cannot be sure 100% but I spent quite some time trying to figure out the problem and that's the most plausible explanation.

I think it might be a combination of Q Slippage and real world trading.

Say for example your thinly traded penny stock is bought at .50 and hits a high of day of .75, which just happens to be where you were looking to sell. The issue is that in Q backtesting it just sees a price of .75, but there might have only been 1-2 shares traded at this level when it hit .75 and not the 1,000s of shares you might have in your backtest.

I believe Charles Witt had a "bottom fishing" algo where this type of scenario played out and the backtest vs live trading was drastically different.

I think setting up the filters with get fundamentals would be faster than using the pipeline, although one of the filters compares the current market cap to the market cap a month ago and I don't think that's possible with get fundamentals. Comparing the current stock price to the stock price a month ago should work, though. I haven't tried live algorithm trading yet so don't know how closely it would match the backtest results.

Is there a typo on the last line? The original value was 1.04, wondering if it's supposed to be 1.004.

I looked at the chart for PLCE, Children's Place, since it was one of the stocks returned by the Q1500 screen. After considering the chart, it looks like small caps and mid caps can rise 4% sometimes, but it usually happens the next day. So I think holding the position overnight might work better for the bigger stocks. Seems like this was happening anyway since many of the orders entered late in the day were not going through. If I'm looking at the algorithm correctly it's risking $1 to make $20 so it doesn't have to be correct very often. Tests with values other than 4% didn't work as well, although it's hard to test a lot of different values because the algorithm is slow.

I did another test with a higher starting balance. Seems like it still works pretty well, although alpha did go down a bit.

Clone Algorithm
23
Loading...
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: 59719c66fbe2235241d3fe8d
There was a runtime error.

Think it might run faster outside of the cloud platform, the code and inputs would need significant modifications and market cap might have to be replaced with share price depending on the data that's available.

Interesting. I was going to backtest it myself, but I was too impatient. I should probably let it run overnight. I tried something similar a week or two ago, but used the highs and lows of a moving average to determine support and resistance. I'll have to track down the code (I'm not good at labeling them or remembering which backtest is which) and post it. For trading penny stocks, I'd probably set high relative volume as a condition for entering or exiting a position to avoid liquidity issues.