It was about 5:30am Saturday morning of PennApps, and I couldn't fall asleep. I was done for the next few hours working on our main hack, so I decided to load up the FINRA data into a database on my machine. Before I went to sleep around 6:30am I had some decent graphs.
What it does
Given a ticker symbol on an index tracked by the FINRA data, learn at which points in time the slope of the value of the stock diverges from the slope of the main index. Basically, when was this stock going down when its index was going up, and vice versa.
How I built it
At first I was just graphing the data. Just passing an arbitrary number of tickers on the command line and plotting their data over the last 20 years against each other. Saturday afternoon I spent some time around Qualtrics talking to Chris, and he suggested I look at the data for some kind of outlier, like a stock that doesn't follow its index; that could be a sign of an interesting company. So most of the credit for inspiration goes to him.
Having finished my backend work on our team's main hack, I spent a few hours Saturday evening into Sunday morning writing the script that would differentiate these rogue stocks. Using the FINRA historical data, I have numpy find a regression equation for the stock being tested and its index. Then I enumerate the first derivatives at every x value (date) for those two regressions. Then I check each x value of the ticker being tested, and if the sign of the derivative at that point differs from the sign of the derivative of the index's regression equation, I output a message telling the user the stock was divergent on that date.
Challenges I ran into
The challenges were mostly just looking up numpy and matplotlib calls, which turned out to be easy to find given an abundance of online tutorials and documentation. I knew from the beginning pretty much how I wanted to write it, but wasn't familiar with the math libraries.
Accomplishments that I'm proud of
I think it's a compact and useful script. Something interesting to play with for like twenty minutes.
What I learned
A small amount about the numpy and scipy libraries.
What's next for Rogue Stocks
Most likely a long life of sitting quietly in my file system. It's good enough of a script that I'll keep it, but I can't see myself using it often.