17 Sep, 2020

Hoping for live trading soon!

I’ve been working on my code like a dog this whole time and have made some major progress recently.

One major change is to the “decision making” part of the code, the one that decides whether or not to execute a trade. Before, it was a large series of “triggers”, a bunch of if/else statements that would set off the trade. It became a hassle to organize them in such a way that it wouldn’t execute before taking in all relevant factors, and nesting conditions (putting conditions within conditions, where all the conditions had to be met) often presented problems when trying to debug problems, or figure out why it traded when it did. What I’ve replaced it with is a scored-based system, where it considers the same conditions, but it runs up a score depending on which ones are met. If it exceeds a certain number, it executes the appropriate trade. This has made the code run slower but has made it much easier to add or remove conditions, as well as debugging. I’ve even made it where I can give conditions weight, so that some are considered more strongly than others.

Another major development is that I’ve moved the code from my personal Windows computer to a dedicated Linux server. This achieves two things: the code runs faster (particularly on fetching information from the database) and allowed me to install a module called Trader, which embeds a group of PHP functions dedicated specifically to technical analysis. Things I’ve been having a rough time doing manually, like calculating MACD values, are now handled by Trader. The documentation is next to non-existent (all there is is a listing of available functions with an explanation of values to be used with the functions, but little to no explanation of what they output or why it’s done the way it is). So far this has resulted in finally being able to generate accurate MACD numbers and charts. I’m now going through my code and replacing the appropriate portions (mainly my custom, brute-force functions).

That said, setting up the server was a nightmare and a half for myself and my friend Peter, who goes to crazy lengths to help me out with the myriad tech problems I have. Mad props to Peter, you’re the real MVP!

One minor development is that I’ve finally been able to crack and implement my “indexing” idea, that of making my own stock market indexes (by market, by sector) that I will later use to start making predictive calls. A major problem with this was that I was previously relying too much on using my SQL database to handle the math, which I’ve since gotten over by simply letting PHP do it manually. It’s gone from taking around 180 seconds to process a single day’s worth of data to approximately 120 seconds to process 4-5 days’ worth of data. Now that it’s on a Linux server, it’s all the way down to around 60-70 seconds to process 5 days of data.

So for now I’m focusing on integrating the Trader functions into my code, which I’m hoping will only take a couple days. Once I’m done with that, I’ll move on to what will be the last major portion of the script: to run every single stock I have data for (that being all of AMEX, NASDAQ, NYSE and OTCBB, over 21,000 stocks) through the trading simulation to determine what stock(s) will be best to trade on a given day. That will involve coming up with another, separate scoring system, one which I’ll have to work on to determine what factors to take into consideration (success rate, average returns, etc.) and how to weigh each factor. I was hoping to have something “usable” by the end of this month but I’m thinking mid- to late-October might be a more reasonable “launch date”.

Tags: , ,

Leave a Reply