go back to the Table of Contents page
Intro
The spikability data that I've been posting is based on the spikability function that I wrote to digitize parts of the SSS for automated setup scoring. It was only partially successful because half of the SSS isn't really easy to formulate in a compact way. The algo runs within www.quantopian.com and you can check out the source code in this forum post.
How to use the algorithm to generate your own stock history information:
Make a quantopian account and then go to the forum post link above. Clone the algorithm (fig 1). Edit line 22 where it says "context.sec = sid(NNNNN)" and delete everything after the "d". When you type "d(" to finish "sid(" you'll get a context menu popup (fig 2). You can type in a ticker and it will perform a lookup for you. Pick the correct ticker. After you finish the line with the right SID lookup number, hit cmd-B or control-B or click on the "Build Algorithm" button at the top of the IDE/text editing area (fig 3). It'll run the algorithm and the printed info will show up in the log to the right of the screen. Note - don't forget to update the backtest dates to the most current date. The data from each day gets posted at midnight of the trading day (if I recall correctly) and you need to span at least 1 day in the backtest (fig 4). So for today (4/5/17), for example, you can only get data up to 4/4/17, so you want the backtest dates to go from 4/3/17 to 4/4/17. The algo will get the data from 4/3/17 to five years back.
> figure 1:
> figure 2:
> figure 3:
> figure 4:
How to use the output:
There are three cases you can use the history for. Case 1 is for predicting how a gap up is likely going to act today. Case 2 is for predicting how a stock that did strongly today will likely act tomorrow. And case 3 is for figuring out if a stock has a history of volatility to let you know if it's a "prior runner". Let's look at an example to see how to get this information out of the output:
Here's EBIO's lookup from a few days ago. There are six sections to this output. Here are descriptions for what each of the sections is showing and how you can use that information. Note that only days that have >250k shares traded are used. I moved it up to 1M at one point but it screened too many days out. It might go higher in the future but I haven't done enough backtesting and correlation testing to figure out what the most representative sample is for better predictiveness.
1. History of large positive moves intraday (open->close)
This is showing only the intraday percentage moves for a stock. This is only intraday to screen out stocks that gap on news and then only trade like 5% either way after the price gap. Think >1B shares and something fundamental happened like a merger. The ranges are given in each row and the count of instances for each day in a given range are given. I added the explicit percentage values so you can get a feel for how much of a move the stock makes. I didn't include negative moves because they are captured in section 4. Keep in mind this is also only open->close. Big moves to the high or low are not captured in this count.
2. History of large HOD moves (open->high):
The large spikes are captured in this section. The stock doesn't have to hold the gains here but that doesn't really matter much for spikability purposes. Keep in mind that a stock can go gap from 1 to 4 and go to 10 and close at 4 and it will have a 0% change intraday but still register a large spike because of the high. If you see a lot of high of day values here then you can assume the stock was at least a one-day runner. Also note that the ranges are different from section 1 - they start at 25 and go to 200+.
3. History of gap up moves (close->open):
This tells you what kind of gap up history a stock has. This can help in getting a feel for how volatile a stock can be. Note that gap-downs are not recorded here so this isn't a complete picture. It's also mostly output because I needed the gap up history info to generate section 4.
4. Given a gap up (n=X), statistically the stock closes:
This tells you what the likely direction will be given a gap up. EBIO has a history of getting smacked down on gap ups because the company is kinda crummy. You can see this in the spread of the outcomes. Note that the stock only has to gap by 5% and the percentage is relative to the open, not the prior day close. I might increase the gap minimum to count in the future, although that might cutoff too many samples. Again, not enough correlation testing to fine-tune the sample screening. Note that the higher the sample size (n=Sample Size), the more reliable the results could be. If there's only 2 prior examples and it's a 50/50 split of going up or down, the outcome is pretty unpredictable.
5. Given a +10% day (n=X), vs day 1 close, the 2nd day will open:
This tells you what the likely open and direction of a stock will be on the 2nd day after a +10% intraday move. Note the ordering - the first two lines are when the stock closes up intraday, and the last two lines are when the stock closes down intraday. The first and third are "gap ups" and the second and fourth are "gap downs". Keep in mind that a gap is used very loosely here because the check is only >=0 or <0. In this case again, you can see that EBIO has a 77% chance of closing red intraday on the day after a 10% intraday move.
6. Holistic spikability score:
This was originally the only value I used from this function when it was much much simpler. The idea was to count the number of large intraday percentage days and the number of large high of day spikes, and weight and sum up the different ranges to make a score from 0 to 10. It's weirdly biased so it's left it mostly as an artifact. When I was using it in a real algorithm (buys and sells positions, not just printing history), I made the cutoff something like "anything <1.25 would be skipped as unlikely to be volatile." It was okay (there were plenty of other problems with the way the algo was handling scoring so I don't think the spikability score was a major issue).
Conclusion:
If I were looking at the stock history for EBIO, I'd assume there's a high probability that any gap is going to end red on the day and holding overnight will be risky and profits should be taken early in the 2nd day. I'd also know that there's some history of big intraday moves so it's not entirely off the list of potential plays but it looks like it has a history of failing by end of day or by the 2nd day.
Things I Will Probably Change:
1. I want to add in multi-day runner history identification soon, something that is "easy" to identify visually and might be easy to quantify, depending on how loose I want to call a continued run.
2. I also need to add in some output for when there is limited history. If something has all 5 years of lookup, it has a higher chance of having more instances of spiking than something that has only been around for a year.
3. There's more info in the percentages that actually resulted. I had to summarize the output because I was overflowing the log limitations, but if I could pull the numbers into MATLAB or some similar Python module, I'd like to output the outcomes as a histogram. I think that would do a better job of visualizing the past results.
4. Lastly, I'd like to capture some intraday patterns in the lookup, but to do so I'd need to actually do a backtest over each day in the past, pull up the minute-by-minute history at the end of a backtest day, and then do pattern recognition / classification on that day after screening the overall day for volume and price action. I don't know if I can get that to fit inside of the 1-minute timeout limit inside of the Quantopian backtesting environment. I also think that this would kill the memory limits pretty quickly so this might not be feasible without a better grasp of how to write optimized Python.
check out other topics on the Table of Contents page





This is awesome!
Just wanted to say thank you very much :)
This is great, thanks for sharing this.
I've finally had the time to do this and really sit and read your post. I thank you again and humbly bow haha, you seem to be in an entirely different skill set than I, although I totally agree with the level of detail you are wanting! Thanks again
Join now or log in to leave a comment