Using TensorTrade for Making a Simple Trading Algorithm

Matthew Brulhardt
Level Up Coding
Published in
6 min readDec 20, 2020

--

In this tutorial, I’m going to show how to use Ray with TensorTrade (TT) in order to create a profitable algorithm on a predictable sine curve. You may be asking yourself, why use something so simple when the real world is much more difficult to predict? This is a very good question, and there is a simple answer.

“The man who moves a mountain begins by carrying away small stones.”
-
Confucius

Before trying to jump into the world of complex trading environments, a simple sine curve can be used to perform a sanity check on your trading algorithm. The reward and action scheme used should be able to make money on a predictable pattern. If it doesn’t, then there is no possibility success will be found on a more complex environment.

There are some questions to ask before wasting time and resources in developing an algorithm. Primarily, does the reward function correctly specify the goal? In this tutorial, I’ll show a reward and action scheme that can be used to train an agent to make profitable decisions on a sine curve.

Architecture

First, we need to install some libraries.

$ pip install tensortrade==1.0.1b0 ray[tune,rllib] symfit

Now let’s import everything we need to run our code.

--

--

MS in Applied Mathematics and Statistics @ Stony Brook University | I’m a simple person who likes four things: design, mathematics, computer science, and data.