Mega Millions has a chance of 1 in 259,000,000. The odds of winning Powerball are slightly worse at 1 in 292 millions. This is probably not the best way to earn a lot. Then I began to think about how people make a lot of cash trading stocks. Compounding can be very powerful. Imagine you have $100, and each day you make a 1% profit. This amounts to $3,778.02 within 365 trading days. In another 365 trading days, you will have $142,746.52. I could buy all the corporate bonds and stocks in the world within 15 years. At one point, they were estimated to be worth $116 trillion. It sounds like enough.
I’m not really interested in $116 Trillion but some would be nice. When I began to study trading, I discovered that the biggest mistake that traders make is letting their emotions take over. When the market suddenly dips or rises, we can lose all rationality and abandon our trading models to take advantage of the sudden market change. This problem could be avoided by using the computer that is soulless and without emotion. It seemed to me like the ideal new hire for my trading business.
What happened?
I decided to trade on the stock exchange, fully automated and commission-free using the popular Robinhood App together with a trial of Microsoft Azure Platform. Robinhood, a platform which allows commission-free trading and has an unofficial API to automate the buying and selling of stocks. Microsoft Azure is Microsoft’s cloud computing platform, which can be used for running servers, applications, and other services remotely within Microsoft’s modern datacenters. Combining these services allows us to automate our trading strategy in a simple and effective way. Microsoft’s artificial-intelligence modules could read articles and help me adjust my trading strategy according to what I found in the media.
I invested $130 at the beginning of the year and grew my fund by 22.5% within just 2 months. This was more than double the return my 401K gave me. Here’s how it was constructed.
Robinhood / IEX trading and data
I first opened a trading account at Robinhood. The account opening is free, but the free commission-free trading was of special interest to me. When I trade a small amount very often, I don’t make a lot of profit on each transaction. A platform that charges commissions would be a waste of money with such low numbers. Robinhood offers both a mobile app and a website to trade. The majority of websites use an API to get the data they need from their datastores. Some are documented, others not. There is unofficial documentation on GitHub for Robinhood API.
I ended up using IEX, a free API that is well documented and easy to use. Robinhood‘s official API could be removed at any moment, so I made sure to call as many official websites as I could. I used IEX data to perform market analysis and then Robinhood APIs for the purchase or sale orders.
Azure – Serverless Cloud Computing
PowerShell was used to write all of the code I needed for my trading and analysis. I could have run this from my home computer, but I didn’t want to risk a power outage or other disaster with $130 on the line. Azure gave me the ability to run my code in a datacenter of enterprise-grade remotely. Azure serverless features such as Logic Apps and Azure SQL were used, along with Cognitive Services, Automation Accounts, and Automation Accounts. Serverless options allowed me to avoid worrying about patching or server operating systems. I simply added my code and let the program run. Azure gave me $200 Azure credit for a free trial. The application cost less than $5 a month. My PowerShell scripts were hosted on automation accounts. Azure SQL was used to store the data I collected. Cognitive services allow sentiment analysis of text strings. This was used to analyze the news articles collected for each stock symbol. Then I linked all of the information together by using logic apps.
Build the Solution
I divided the solution into these pieces to build a viable one:
Get daily market data from IEX
Top 10 Stocks to Buy – Using Artificial Intelligence-driven algorithm
Unallocated funds in my Robinhood account
Unallocated funds can be distributed among the top 10 stocks.
Limit orders on stocks I own can lock in profits
This allows me to analyze all stocks in the market automatically each day. I can use funds from my previous sales to purchase desirable stocks and identify any stock that I should sell.
Here is a snippet from the code that was used to obtain market data from IEX. It uses some basic criteria in order to reduce approximately 8000 stocks to a manageable number. Then, I looped each stock and filtered by criteria according to my trading strategy in order to get the 10 best stocks to buy that day. I also collected the top five news articles for each stock to run sentiment analyses against.
In the diagram the left branch buys and the right branch is selling. On the left side, automation jobs trigger to pull a filtered data set from IEX or Robinhood. This data is then fed into SQL. Each new entry was subjected to text analytics to determine whether the news articles about that symbol were positive or negative. The algorithm used this score to rank stocks in order of most desirable to least desirable. A top 10 list was then selected. Once the top 10 list has been completed, a third task is executed to buy the stock. On the right, I’m querying SQL to check the stocks I own and selling them or alerting me if they don’t meet certain criteria.
Trading Strategy
The most challenging aspect of automating your trades is figuring out a profitable and sensible strategy. Day trading regulations required me to wait at least one day before I sold an investment. I had to decide whether to set a stop loss or a limit sale. Stop loss orders prevent you from losing too much money if your investment falls below a specific price. Limit orders sell the investment when it reaches the target price. Limit orders were my main focus, and I experimented with gains of 10%, 5%, and 2%. By setting a lower limit, I was able to buy and sell more often and reduce my overall risk as the gains were locked-in sooner. The whole process was more exciting because I could see the market move more. I set up alerts in my logic application to send me an email when I fell below a specific percentage. In a short time, I discovered that the best strategy was to combine both long-term and short-term investment strategies. Buy into companies that have strong financials, and sell at low margins in order to lock up short-term gains. If you are planning to invest in a similar venture and want to make money, I recommend doing research on key financial metrics like the price-to sales ratio, the price-to earnings ratio and other data points.
The conclusion of the article is:
It was easy, fun, and even profitable to build this application in Azure! If I run this application for 10 years, I’ll make just under $25 million. That won’t be enough to buy all of the worlds stocks in 15 years. As I embark on a new chapter of my life, I will be stopping auto-trading. I may pick it up again one day.