Low-code stock trading with machine learning (ML)

First published on April 18, 2022

 

6 minute read

John Patrick Hinek

TLDR

Wall street banks use a variety of tools when making market predictions. One of those tools is machine learning software. Using Mage to build a model that can predict next-day prices can be another asset for individuals wanting to make predictions. 

Outline

  • Intro

  • Dataset

  • Model training

  • Evaluation

  • Deploying API

  • Closing thoughts

Disclaimer: This is not financial advice. 

All investment strategies and investments involve risk of loss.

 

Nothing contained in this website should be construed as investment advice

. Any reference to an investment's past or potential performance is not, and should not be construed as, a recommendation or as a guarantee of any specific outcome or profit.

Intro: 

With the growth of machine learning (ML) and artificial intelligence (AI) technology, stock trading has become synonymous with technology. As trading thrives on finding patterns within data, ML and AI have proven to be a viable solution to predict the market. According to an analysis of the S&P 500 by 

, 88.4% of hedge funds underperformed over the past 15 years. One proposed solution to improve this statistic is using AI and ML software. According to 

, over 80% of the stock market is powered by bots. A growing part of the hedge funds technology fleet is AI and ML powered software.

With a team of expert data scientists and machine learning engineers at the helm of hedge fund technology, it has become more intangible for individuals to make bets on the same caliber as Wall Street. Using AI software of your own could prove to be a future option that guides and checks one’s financial trading. 

As neither a data scientist or machine learning engineer myself, I’ll be using 

to predict stock price for its low-code model creating power. I’ll be working off of an estimation model.

Dataset: 

The power behind any AI/ML model is data. The stock market naturally makes a perfect dataset as stock prices are publicly available and have been well documented at specific time intervals everyday. To generate a dataset of any stock, I’d recommend following the instructions 

In today’s example, we’ll be using a pre-existing dataset found on 

created by 

.

This dataset tracks Netflix’s stock price over the course of 5 years from February 5, 2018 to February 5, 2022. 7 columns make up this dataset: 

  1. Date: Day of the stock posting

  2. Open: What the market opened at

  3. High: Highest stock price of a day

  4. Low: Lowest stock price of the day

  5. Close: What the market closed at

  6. Adj close: Amends a stock's closing price to reflect that stock's value after accounting for any corporate actions.

  7. Volume: Measures the number of shares traded in a stock or contracts traded in futures or options.

Model training: 

The first step of training a model in Mage is choosing a use case to train your data on, we’ll be using estimation, and importing data, in this case using a CSV. Once data is imported, looking at the “view insights” tab on the top of the data will give you a graph that provides further data insights and visualization of distribution. 

After viewing insights, we’ll need to set out intentions for our model training. Mage provides a guide that makes model training easy to follow. 

  1. What do you want to estimate? #open_

  2. What column has a unique identifier? #volume 

  3. What column has a timestamp? #date_ 

After filling in those boxes, you can either begin training your model, or apply suggested actions that may improve your model’s performance. For stock predictions, we want to shift the “adj_close” column as we will use this to predict next day’s stock price. 

Once the data has been imported and the necessary actions have been performed, it’s time to train your model which takes either 2 or 20 minutes depending on the algorithm you choose. 

Evaluation:

Great news! Our model came back with excellent performance. This means our model was better than the baseline for predicting the opening stock price of Netflix stock (NFLX). In our “Review” tab under “Top Features”, we can see a breakdown of what influenced our model’s performance most. This will give us the necessary information to make further predictions when deploying our model. 

Deploying API:

With the model successfully trained, we can deploy our API by exporting to an external app or testing further predictions in Mage’s playground feature. Access to any of these features will be under “Predict”.

“Top features” lay out the defining features of our model. That is, the features that influenced the model’s predictions the most. To make a prediction for the opening price of NFLX, we just need to enter new data points in the playground features which influence the performance of our first model. That is, the adjusted closing price and date. 

For this test prediction, we entered the 2 dates following the completion of our dataset (February 7, 2022 and February 8, 2022). The adj_closing on February 7, 2022 was 402.10, our prediction had the opening price at 388.590, compared to the actual price which was 398.18. The adj_closing on February 8, 2022 was 403.53, our prediction had the opening price at 408.261, compared to the actual price at 408.65. 

An updated dataset would be required to continue making predictions with this model. To upload a new dataset, simply go to “Train”, “Add data”, follow the steps to add a new dataset, and then combine the two datasets on similar columns. 

Closing thoughts 

While the predictions from our model aren’t 100% accurate, they show a promising result in assisting individuals who want to make more informed stock trading decisions. The stock market is very volatile and affected by world events that a machine wouldn’t be able to predict. Taking a holistic approach and looking at all of one's resources is advised when making trading decisions. As Wall Street traders have begun to rely heavily on AI/ML technology to assist in their decision making, we believe that it’s important for individuals to have access to the same, or similar, technology to make their stock trading predictions.