Reader small image

You're reading from  TensorFlow 2 Reinforcement Learning Cookbook

Product typeBook
Published inJan 2021
Reading LevelExpert
PublisherPackt
ISBN-139781838982546
Edition1st Edition
Languages
Right arrow
Author (1)
Palanisamy P
Palanisamy P
author image
Palanisamy P

Praveen Palanisamy works on developing autonomous intelligent systems. He is currently an AI researcher at General Motors R&D. He develops planning and decision-making algorithms and systems that use deep reinforcement learning for autonomous driving. Previously, he was at the Robotics Institute, Carnegie Mellon University, where he worked on autonomous navigation, including perception and AI for mobile robots. He has experience developing complete, autonomous, robotic systems from scratch.
Read more about Palanisamy P

Right arrow

Chapter 5: Reinforcement Learning in the Real World – Building Stock/Share Trading Agents

Software-based deep reinforcement learning (deep RL) agents have tremendous potential when it comes to executing trading strategies tirelessly and flawlessly without limitations based on memory capacity, speed, efficiency, and emotional disturbances that a human trader is prone to facing. Profitable trading in the stock market involves carefully executing buy/sell trades with stock symbols/tickers while taking into account several market factors such as trading conditions and macro and micro market conditions, in addition to social, political, and company-specific changes. Deep RL agents have a lot of potential when it comes to solving challenging problems in the real world and a lot of opportunities exist.

However, only a few successful stories of using deep RL agents in the real world beyond games exist due to the various challenges associated with real-world deployments of RL agents...

Technical requirements

The code in this book has been extensively tested on Ubuntu 18.04 and Ubuntu 20.04 and should work with later versions of Ubuntu if Python 3.6+ is available. With Python 3.6+ installed, along with the necessary Python packages, as listed at the start of each of the recipes, the code should run fine on Windows and Mac OS X too. You should create and use a Python virtual environment named tf2rl-cookbook to install the packages and run the code in this book. Installing Miniconda or Anaconda for Python virtual environment management is recommended.

The complete code for each recipe in each chapter is available here: https://github.com/PacktPublishing/Tensorflow-2-Reinforcement-Learning-Cookbook.

Building a stock market trading RL platform using real stock exchange data

The stock market provides anyone with a highly lucrative opportunity to participate and make profits. While it is easily accessible, not all humans can make consistently profitable trades due to the dynamic nature of the market and the emotional aspects that can impair people's actions. RL agents take emotion out of the equation and can be trained to make profits consistently. This recipe will teach you how to implement a stock market trading environment that will teach your RL agents how to trade stocks using real stock market data. When you have trained them enough, you can deploy them so that they automatically make trades (and profits) for you!

Getting ready

To complete this recipe, make sure you have the latest version. You will need to activate the tf2rl-cookbook Python/conda virtual environment. Make sure you update the environment so that it matches the latest conda environment specification...

Building a stock market trading RL platform using price charts

Human traders look at several indicators on their price monitor in order to vet and identify a potential trade. Can we allow the agents to also visually look at the price candlestick charts to trade stocks instead of providing just a tabular/CSV representation? Yes, we can! This recipe will teach you how to build a visually rich trading environment for your RL agents.

Getting ready

To complete this recipe, make sure you have the latest version. You will need to activate the tf2rl-cookbook Python/conda virtual environment. Make sure that you update the environment so that it matches the latest conda environment specification file (tfrl-cookbook.yml), which can be found in this cookbook's code repository. If the following import statements run without any issues, you are ready to get started:

import os
import random
from typing import Dict
import cv2
import gym
import numpy as np
import pandas as pd
from gym...

Building an advanced stock trading RL platform to train agents to mimic professional traders

This recipe will help you implement a complete stock trading environment with high-dimensional image observation spaces and continuous action spaces for training your RL and deep RL agents. This will allow you to build intelligent trading bots using RL so that you can closely approximate how a professional stock trader would trade stocks. Like a professional trader, the RL agent you'll train will watch the stock market data in the form of candlesticks and price line charts and make trading decisions. A well-trained RL agent could potentially make thousands of profitable trades without needing a break or commission, unlike a human professional trader, thereby increasing your profits!

Getting ready

To complete this recipe, make sure you have the latest version. You will need to activate the tf2rl-cookbook Python/conda virtual environment. Make sure that you update the environment...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
TensorFlow 2 Reinforcement Learning Cookbook
Published in: Jan 2021Publisher: PacktISBN-13: 9781838982546
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Palanisamy P

Praveen Palanisamy works on developing autonomous intelligent systems. He is currently an AI researcher at General Motors R&D. He develops planning and decision-making algorithms and systems that use deep reinforcement learning for autonomous driving. Previously, he was at the Robotics Institute, Carnegie Mellon University, where he worked on autonomous navigation, including perception and AI for mobile robots. He has experience developing complete, autonomous, robotic systems from scratch.
Read more about Palanisamy P