How to Build a Stock Market Algorithm

How to build a stock market algorithm is no easy task. Many have tried before and in order to achieve this and have lost thousands upon thousands of dollars attempting to. Creating a stock market algorithm that is close to that of the actual New York Stock exchange which considers all factors that could possibly be at play is nearly impossible given that the current algorithm has likely come about from over a century of experience and technological growth. This article series focuses on creating an algorithm that is close to the New York Stock Exchange, however, it will not be an exact replica so don’t go betting your 401K on it.

Related Posts

In this article I will focus mainly on three different algorithm types that could possibly exist and will begin implementing. The first is based on firm foundation theory, the second is based on Castle-in-the-air theory, and the 3rd is my own secret blend of the two previous algorithms that get even closer to what the actual stock market’s algorithm might look like.

How to Build a Stock Market Algorithm with the Firm Foundation Method

The firm foundation theory focuses mainly on the fact that each stock has an intrinsic value. These intrinsic values are typically determined by how this stock performs, its earnings multiple, and many different factors on the balance sheet. When these different factors are considered by financial analysts they are better able to determine what the price of a specific security should be (although it is sometimes or usually not). In a perfect world firm foundation theory would determine the price of every stock and security in the market. How well a company performs and its profits over its expenses would lead to the determination of a price, however, this is not how the world works and would likely not be the best way of creating the stock market algorithm due to the fact that groupthink typically has a lot of impact on how a security is priced.

Build a Stock Market Algorithm with the Castle-in-the-air Method

As mentioned in the previous section, firm foundation theory has a key role in determining the price of different securities in the market. However, one of the largest influences on the price of a stock is the behavior of humans who are buying and selling that stock. When the trading volume of a specific stock indicates that more people are buying that stock than are selling it, And word on the Grapevine indicates that a stock will likely rise in price, outperform competitors, or introduce some great new product, even if not the case, many investors are more inclined to buy that stock. This leads to inflation of the company’s stock price and more people catching wind of the stock and purchasing it. In this way, regardless of the actual earnings of the company, the stock price increases.
This is why humans and the news media have such a huge impact on the market.

How to Build a Stock Market AlgorithmWhen you see a report of something like the failure of the Boeing 737 Max that we’ve been seen in the last year and its affect on Boeing’s stock price, or that airlines and governments are banning travel to specific countries like with the coronavirus pandemic and airline stock prices, it is not the news of this that causes the market to plummet, but rather human beings selling stock in the companies that they believe will begin to lose money because of these news. In this way it is revealed that firm foundation theory and the intrinsic value of stocks, though incredibly important in long-term projections, do not have as big of an impact on the market day to day as human beings.

Stock Market Algorithm Based on Trading Volume and Intrinsic Value

This section will focus on the combination of firm foundation theory with the Castle in the air theory. The reason why this is so necessary is because firm foundation theory will give us a starting point, it will give us an intrinsic value to start with, and trading volume, most often a product of people creating castles in the air, will let us incorporate the human factor into our algorithm. Firm foundation and the intrinsic value of stock will allow us to give more accurate long-term predictions given that the stock market has been seen historically to correct itself in the events of human error and the madness of crowds. Castle in the air theory and the trading volume of specific stocks will allow us to more accurately predict the short term, from an hour of trading to a week of trading, while waiting for the market hysteria caused by continuous news media coverage to die down.

In a series following this article I will be attempting to use several different finance APIs and The Java programming language, as well as explaining my thought process and choices, to create an algorithm that will track the three major indexes real time and make short and long term predictions of those indexes.



Disclaimer: The opinions and documentation contained within this article and on this blog are the sole property of and are not to be copyrighted or reproduced in any manner, else legal action within the rights of the United States legal code could be use to obtain recompense. All articles and blog posts are the sole opinions of the writers of the blog, and are not necessarily in line with what exactly will work for you, you should consult a CPA, Tax Professional, or Financial Professional to determine what exact financial needs are in line with your interests. Also, from time to time, certain links on this website will be used to generate affiliate commissions, in order to support the health and growth of our website, health and business.