The financial market is a very important part of any economy. For an economy to thrive, its financial market must be solid. Since the advent of machine learning, companies have begun to adopt algorithmic trading in the purchase of stocks and other financial assets. There has been proven successful with this method, and it has risen in prominence over time. Given its rise, several machine models have been developed and adopted for algorithmic trading. One popular machine learning model for trading is the time series analysis. You have already learned about reinforcement learning and Keras, and in this chapter, they will be used to develop a model that can predict stock prices.
You're reading from Python Reinforcement Learning Projects
Automation is taking over in almost every sector, and the financial market is no exception. Creating automated algorithmic trading models will provide for a faster and more accurate analysis of stocks before purchase. Multiple indicators can be analyzed at a speed that humans are incapable of. Also, in trading, it is dangerous to operate with emotions. Machine learning models can solve that problem. There is also a reduction in transaction costs, as there is no need for continuous supervision.
In this tutorial, you will learn how to combine reinforcement learning with time series modeling, in order to predict the prices of stocks, based on real-life data.
The data that we will use will be the standard and poor's 500. According to Wikipedia, it is An American stock market index based on the market capitalizations of 500 large companies having common stock listed on the NYSE or NASDAQ. Here is a link to the data (https://ca.finance.yahoo.com/quote/%255EGSPC/history?p=%255EGSPC).
The data has the following columns:
- Date: This indicates the date under consideration
- Open: This indicates the price at which the market opens on the date
- High: This indicates the highest market price on the date
- Low: This indicates the lowest market price on the date
- Close: This indicates the price at which the market closes on the date, adjusted for the split
- Adj Close: This indicates the adjusted closing price for both the split and dividends
- Volume: This indicates the total volume of shares available
The date under consideration for training the data is as follows:
Start: 14 August 2006 End: 13th August 2015
On the website, filter the date as follows, and download...
Our solution uses an actor-critic reinforcement learning model, along with an infused time series, to help us predict the best action, based on the stock prices. The possible actions are as follows:
- Hold: This means that based on the price and projected profit, the trader should hold a stock
- Sell: This means that based on the price and projected profit, the trader should sell a stock
- Buy: This means that based on the price and projected profit, the trader should buy a stock
The actor-critic network is a family of reinforcement learning methods premised on two interacting network models. These models have two components: the actor and the critic. In our case, the network models that we will use will be neural networks. We will use the Keras package, which you have already learned about, to create the neural networks. The reward function that we are looking to improve is the profit.
The actor takes in the state of the environment, then returns the best action, or a policy that...
In conclusion, machine learning can be applied to several industries and can be applied very efficiently in financial markets, as you saw in this chapter. We can combine different models, as we did with reinforcement learning and time series, to produce stronger models that suit our use cases. We discussed the use of reinforcement learning and time series to predict the stock market. We worked with an actor-critic model that determined the best action, based on the state of the stock prices, with the aim of maximizing profits. In the end, we obtained a result that boasted an overall profit and included increasing profits over time, indicating that the agent learned more with each state.
In the next chapter, you will learn about the future areas of work.