The ability to code is like having a trading superpower.
For instance, when something that seems “rare” happens in the marketplace, you can quickly and easily write some code to see how rare that event actually is.
Instead of relying on the financial media, you can do your own analysis. More importantly, you can see what happened after such an event occurred and whether that constitutes a tradable opportunity or not.
In this Connors Research Traders Journal, we will show you how easy it is to check the frequency of a market event. We will also show you how straightforward it is to observe typical market behavior after such an event occurred.
Rely On Facts! Not Talking Heads on CNBC Who Say “I Think…”
Imagine that the US stock market has been on a run of strong recent performance, rising 10% in the last 6 months.
You are wondering if it is the right time to put some of your cash to work in the market given the strong performance.
You don’t want to be a sucker, however. The market has increased by 10% in just 6-months, isn’t it too late to buy now?
You turn on CNBC and a pundit basically says what you are thinking.
“The market has had a very strong run here and I think it looks expensive and overbought” (of course citing no data whatsoever). “I wouldn’t buy at these elevated prices after this run-up.”
If you have basic coding skills, you can easily check to see if this recent run of performance is, in fact, as overbought and as rare as the pundit is implying.
Data vs. Opinion. The Beauty of Python Code
The first step is to grab the data. If you don’t know how to do this, attend our free webinar on how to code in Python on Monday, December 23 at 1 pm. Click here to register.
Here we grab daily historical open, high, low, close, and volume data for SPY beginning on January 1, 2003 through December 15, 2019.
We save our data as the variable “df”. We then observe the last 5 rows of our data using .tail().
Let’s make a quick graph of the historical price of SPY. This is done via only two lines of Python code as shown below.
Let’s now make a quick plot of rolling 6-month, or 126 business days, total returns.
Shocking! It certainly doesn’t look like a 10% trailing 6-month total return is anything out of the ordinary. In fact, we can see that the market has had much stronger 6-month performances in the past, hitting +20% or higher multiple times.
Next, let’s check out how many total days are in our sample size and how many of those days had a trailing 6-month return greater than 10%.
Here we have 4,142 total days in our sample.
Of those 4,142 today days, 1,148 of them had trailing 6-month returns greater than 10%. That is 27.7% of the time, not exactly a rare event!
Finally, let’s see what the future 3-month returns are for SPY after a 10% 6-month advance occurred. This can be accomplished in a few lines of Python code.
As you can see, the median 3-month future return after a 10% 6-month increase is a positive 3.36%. Annualized it’s over 13% a year!
We can certainly agree that just because the market increased 10% in a 6-month period, that is NOT a reason to sell as the TV pundit implied.
Learn How To Do This For Yourself
With basic Python coding skills, you’re empowered to decide for yourself with facts and data instead of the opinion of a TV pundit. This is the power of coding in Python. You can quickly, and professionally fact check analysts who rely on their opinion.
Don’t worry if this code is confusing to you, especially if you have limited experience with a coding language. All this is learnable in under 10 hours.
In fact, we guarantee you’ll learn how to code strategies in Python in under 6 hours. We back this with a 100% money-back guarantee. That’s how sure we are you’ll have the knowledge to run a test like this.
We will teach you how to do all of this and more in our upcoming course – Python Programming for Traders.
Attend the free webinar on Monday (or sign up to receive the recording). You’ll be on the path to joining the tens of thousands of professional traders around the world who work for major hedge funds and bank trading desks who do their systems testing and programming in Python.
Click here to register for the webinar now.
Chris Cain, CMT
PS – If you’re already programming in Python, feel free to type my code onto Quantopian to go even further with this.