Make An AI Stock Trading Bot For Free

Judy Roxen
3 min readOct 22, 2021

Quantitative trading

As new technology becomes available, algorithmic trading is becoming more popular. In the past, I wrote about the development of algorithmic trading systems in Java. Python is a powerful language that provides excellent documentation and easy implementation stock trading bot. This article will explain how to create an algorithmic trading system using Python. It also demonstrates how to deploy an AI model trained to execute live trades. GitHub contains the code for this project.

This article will be divided into the following steps.

I: Connecting with a Brokerage House

II: Trading System Development

III: AI Trading Model Development

IV: AI Trading Model Deployment

(Bonus): Cloud Deployment

Connecting to a Brokerage House

This article will use Alpaca, one of many free and easy ways to start algorithmic trading. First, connect to a brokerage house to get live data on the securities you are interested in trading. To generate an API key, create an account.

This is for the brokerage connection. We can use an instance of the Alpaca Paper Socket Class as a reference to the API. Below, we will request stock data for our AI model. However, if you want to see how to place stock orders and request stock information now, the documentation can be found. This is just one piece of the puzzle. You can use any brokerage house you wish to. This is a brokerage house that provides an API for data and order fulfillment professional trader.

Development of a Trading System

Once we have established a connection with the brokerage house, it is now possible to build our trading platform. I created a new design pattern that can house any security with different time frames and AI models. Does it sound complicated? It’s not complicated.

It is essential to create an abstract Trading System class that allows us to implement custom rule sets for every trading system. It is easy to program the code, which will enable us to initialize and thread an infinite loop.

A trading system is an abstract type with some abstract functions. The functions can be abstracted to change from one implementation to the next while still maintaining the same class structure. Consider, for example, a portfolio management and day trading system. The system loop of the portfolio management system will contain a different AI model from that of the system loop for day trading. Implementing the abstract class trading system is easy. This article will focus on building a portfolio management software, and then I’ll show you how to train an AI model that executes trades. Consider the following…

This Portfolio Management System will house the AI which will execute trades. After we have developed our AI trading model, we will be returning to this implementation.

AI Trading Model Development

This system will allow me to train and build an AI model as my portfolio manager. The goal is to teach the neural network to purchase at a threshold of negative change and sell at a positive difference in stock prices. Our AI is trained to deal with the rip. [Please note that I do not recommend that you implement this in live systems, we will discuss the subject further down] I will create and annotate a dataset based upon weekly market data from IBM to train this neural network. A signal feature will give a value within the set 0–1 based upon a threshold for change.

--

--

Judy Roxen
0 Followers

Judy Blogger is a passionate wordsmith with a flair for storytelling. With a keen eye for detail and a heart that beats for genuine narratives.