StockMonitor - my fundamental analysis bot

StockMonitor - my fundamental analysis bot

I finally wrote a piece of software that I've wanted for years - a bot that regularly monitors the stock market for good, fundamentally sound companies that are undervalued, and then lets me know as soon as it finds them.

Automating value investing

I like the idea of buying something at a bargain that would likely truly increase in value over time, not because of it being a fad or fashion, but because it is really produces a net benefit to its stakeholders. Damn, that line sounded a bit more corporate than I intended, but it's relatively succinct and I stand by it.

If we're being honest, everything else is merely speculation. Although I do dabble in stuff like crypto, I do not view it as investing. To me it's just one or two steps up from gambling.

Why? Because it does not produce any additional value over time, its value merely depends on what a bunch of people collectively think it's worth. A value based on... feelings? Hopes? Peer pressure? Who knows.

To me that's not truly reliable and definitely not measurable enough to base longterm decisions on. Wow, as I wrote that I could just feel the multitude of objections undulating across the internet and socials; "what about smart contracts!?", and mentions of "stores of value", and cries of "gold-is-just-as-bad". Quite.

And some of those criticisms might have interesting points. And yes, the same could perhaps even be said about other more traditional forms of 'investment', like residential property and precious metals. But since all of that is only tangentially related to this post, and I'm in control of what's being discussed here, let's declare it a digression, side-step the horrified, and swiftly move along.

Sure, the line between investing and speculation can be very nebulous, and I do not really want to get into that an intricate of discussion and comparison with this post, but in short, I believe it comes down to that some people like pumping money into things they feel or hope would be worth more in the future. They prefer hunches, gut feelings, popularity and the wisdom of the crowd to analysis of the old-school and boring. They often have slogans too, mentions of moons and diamonds and, of course, lots and lost of cheering each other on.

Others(and this is where I align myself) prefer to pump money into things they think will increase in value in due to some more concrete and measurable properties, and often puts great emphasis on the output such an entity produces. They consider that measuring and processing those properties could give one a better idea of what that thing might be realistically worth in real monetary terms, regardless of what yours or others fluctuating feelings and hunches might suggest in a moment-by-moment basis.

You see, people and their opinions are fickle. And being due to human beings being spooked, ignorant, confused or distracted, things of real value might be worth more than most people feel it is in the open market, at any particular moment in time, due to random reasons.

Everyone can suddenly get all excited about that new tech-car company, and perhaps totally forget about the boring, ancient company that might produce a lot of the chemicals used in that very same tech-car company's production lines.

The market value of companies goes up and down daily, based on what's said in the news, what's being tweeted and what some random politician might have said. But thinking about it, how can that make sense? How can a company's real value change on a whim, a whisper or mere rumour?

And that, essentially, is what the concept of value investing entails - basing investment decisions on some measurable intrinsic properties of the investment instrument, and not being swayed by the markets' irrational ups and downs. I'll also offer the definition of value investing from Investopedia, to give you a clearer idea of what I'm angling for.

Value investing is an investment strategy that involves picking stocks that appear to be trading for less than their intrinsic or book value. Value investors actively ferret out stocks they think the stock market is underestimating. They believe the market overreacts to good and bad news, resulting in stock price movements that do not correspond to a company's long-term fundamentals. The overreaction offers an opportunity to profit by buying stocks at discounted prices—on sale.

Thus the aim of the bot I wanted to build was to automate the process of fundamental analysis on a particular stock market index - in my case the S&P500 - and have it notify me when it finds an opportunity where the market might be considering a stock worth less than it possibly is in reality.

The bot spec

I wanted to automate everything I previously did manually, when it came to deciding what to buy and when, except for the actual trading part. I would still like to leave that particular task manual, as I want to have the final say in if I think a stock is a good purchase or not.

That being said, the bot does the following;

  • It updates and caches a list of stocks in the S&P500 every 3 months.
  • It fetches and/or calculates the latest fundamental metrics for each stock, including stuff like PE, EPS, FCF, Pietroski F-Score, book value, sales and earnings every 3 months, and caches it in between.
  • It ranks them from most profitable, productive and stable to least, then drops the bottom ones leaving only the top 8
  • It calculates an estimate per share value for each company with a customised form of the Benjamin Graham formula
  • It then compares the latest price of that top 8 with their calculated estimated value twice a day, and sends me an email report of this process on every other check(thus once a day)
  • It notifies me via SMS and email when it finds a stock that's going at a rate a little below the estimate, so that I can have a look and decide if it's a good buy or not myself.

Choosing a stack

I chose to use NodeJS, as that's the stack I use most frequently at my day job. This helps me move comfortably fast, as I'm fluent enough in it to be able to put most of my mental effort going towards architecting the app itself, and not towards trying to figure out a new language or framework.

I could also reuse a lot of code from previous side-projects, in order to get it built much faster. Some of the code I recycled included comms functions like sending email and SMS, error loggers and Dockerfile setups.

I also opted to not use TypeScript, as I found the basic application easy enough to build and reason about without having to worry about types too much, and because it's merely a personal project that doesn't need to be sanity-checked for other team members' sake.

Although I worked on it on my free time on-and-off, sometimes in the early mornings and sometimes on weekends, I estimate it took me about 6-8 hours to get it done and in its current relatively satisfactory state.

Fundamental analyst bot in action!

The bot currently doesn't have a dashboard or web UI, but I can offer you a screenshot from the console.

StockMonitor in action

Conclusions and disclaimers

Now, I'm not a professional trader, financial advisor or a particularly astute financially literate person, so I'm not sure of how much worth this thing really is. But this was a fun project to work on and helps me keep a regular albeit automated eye on the market to help find opportunities as defined by my own personal investment preferences and inclinations.

I'm sure some of you would disagree with the validity of the metrics I'm tracking or some of the things I might have said in the post, but for me, this bot is pretty nifty.

I'd certainly not use it to advise others on what to buy or not, but for me and my own funds it's perfect, because it automates what I did manually anyway, just way more often and regular, thereby freeing up some of my time and mental energy for other endeavours.

It hasn't identified anything for me to buy as of yet, so I obviously can't vouch for its practical usefulness at this point, but it's only been running a couple of days and the market is rather bullish in general at the moment. But I'm patient, I'll wait. I know my bot's got my back.

I'll post an update again once it's made its first recommendations, and hopefully again after that, with some concrete results.

Thanks for reading. If you have any comments or suggestions, follow and contact me on Twitter @RikNieu

If you want to read more of my rants, sign up below and I'll mail you when I post new stuff. 👇

Show Comments
Buy me a coffeeBuy me a coffee