Software Engineer
Python, AI, Stocks, and Money
January 04, 2022

I think everyone has a project why they started programming.

For some it was because they picked up basic in high school. For others, they liked to poke around network traffic and see what was going on.

For me, it was stocks and crypto trading. A number of years back I picked up a copy of Inside the Black Box by Nishi Narang and Richard Brewer (You can find a copy here) The book itself is a dense firehose of information, but man, I was hooked. The methods of trading, of billions of dollars of trading undergoing at a constant rate, faster than any human could ever react had a magical pull. I had to build something like it.

Of course, this was a long time ago. I could barely program a Hello World at the time, so my first attempt at the project did not go far.

However, I celebrated my third year as a professional developer this year, and hit the halfway point through Northeastern University's Computer Science Graduate Master's program to boot. So in my AI class, I decided to take another swing at it. The term project was supposed to take perhaps 50 hours, but I sank several hundred in, in the pursuit of the one project I never forgot.

And it's worked out really well!

The program takes over 4600 stocks a day from a given csv file, and originally updated them using Alpha Advantages API, with a rate limited of a horrendous 75 per minute. Just fetching the historical data took over 3 hours every day.

After that, I went for a hybrid approach with the Alpaca API instead for recent data, so the data fetch took around 30 minutes instead. From there, I populated the JSON data into pandas DataFrames with my own indicators, ran the stocks through an oscillating indicator check, saving the ID's of the stocks that were pushed to the extremes. Of the 4600, about 50 made it through this at average, most of them penny stocks, or one of the many crashing and burning Pharma companies that were being brought low post-covid.

For the ones that made it this far, I did a full intra-day data fetch using Alpha Advantage for their full financial history (Something AA is actually excellent for), and ran them through a TensorFlow-Assisted Neural Net for a short-term price prediction, and a friend of mine added a Linear Regression as well. Finally, the ID's, previous price, and predicted price used SMTP to email out the next day's recommendations for buys and sells.

While the system itself works very well, I am actually having a surprising amount of trouble getting exit values for when to sell, since it's a vastly different method that I've ever tried to invest with before.

Moving forward, I would love to dig deeper and create an Algorithmic trading protocol to trade for me, but I think that would be best used as a paper trade system for at least a year before throwing actual currency at it.

But overall, it works well, and I finally got to build at least a major chunk of the reason why I became a programmer in the first place, and that's a pretty great feeling.

You can find the Stock Advisor Repo here, and stay tuned, because it's far from where I want to be for my vision of it.

Until next time,