A custom OpenAI gym environment for simulating stock trades on historical price data with live rendering. In this project, we've implemented a simple, yet elegant visualization of the agent's trades using Matplotlib.
Great thanks to:
- Creating new Gym Env | by OpenAI
- Deep Reinforcement Learning Hands On | by Max Lapan (the book)
- Create custom gym environments from scratch — A stock market example | by Adam King
- Rendering elegant stock trading agents using Matplotlib and Gym | by Adam King
- Creating Bitcoin trading bots that don’t lose money | by Adam King
In order to run the environment you need to do the following:
- Copy the repo to your computer.
- Go to the one directory above of the copied repo on your computer in the Terminal.
For example:
cd PycharmProjects/
. - Run the command:
pip install -e gym-stocktrading
.
Make sure your pip is related to the relevant python environment (pipenv/conda/...) where gym package is located.
That's it! You've installed the new gym-env on your computer.
In another project try to run the environment with this code:
import gym
env = gym.make('gym_stocktrading:stocktrading-v0')
ob = env.reset()
done = False
for i in range(100):
while not done:
action = env.action_space.sample()
ob, reward, done, _ = env.step(action)
env.render()
if done:
ob = env.reset()
done = False
env.close()
Snapshot | Gif (in motion) |
---|---|
Enjoy!
Created by Neural Trading ©