Gym and agent for algorithmic stock and cryptocurrency trading


I think not only is this a hard thing to turn into something practical, due to advantages of speed and access to data that professional investment has, but it is also somewhat counter to the goals of OpenAI. OpenAI is about sharing “AI for all”, whilst algorithmic trading is about gaining an advantage for a few people, who can extract financial value from a dynamic system by spotting mismatches between current sale value and longer term value, and are in a position to take advantage of it (e.g. they have significant funds in the system)


If an AI becomes able determine which stocks to invest in better than a person can, I think there will be more important results from this than an individual profiting from stock trading.


Don’t waste your time. You have dreams of beating market with software, cool idea, but you will waste your time, money and you will not learn much doing it (your brain does not work well when money or any other pleasure is your motivation, if you don’t believe me, just look up forex trading on youtube and watch how the ‘gurus’ do it ie gamble hoping you sign up for their site/product with hopes of bringing their only source of ‘steady’ income)

But if you insist…

What I suggest you do is as follows:

  1. Read a tutorial how to export price data from MetaTrader or whatever your platform.

  2. Read tutorial on how to create a simple gym environment if that is the path you want (it would be infinitely wiser to just have an array say of bars { float open, close, high, low}[n] (lower n is better believe it or not),and feed it to Keras to generate your alpha ie when to enter positions. How? you slide the a window of say n bars and predict if price will be 50 pips or whatever up or down and then have an mt4 enter positions.

As a heads up you will find your algo “sucks” meaning it is only accurate like ever slightly better than coin flipping, however this is godly. When you read the releases by top quant funds like virtu you will quickly realize that they “only” have 52% wining trades, yet somehow they have never had a losing day in history. How is this possible? Yup, 800,000 trades a day with 2% edge is how you make billions.

Most wannabe traders/quants waste 99% of their time looking at lagging indicators (be it moving averages,RSI or other #$^#), they create web communities, forums, more useless brilliant indicators (if you read the word fractal, fibonacci or other bullcorn etc run). The truth is the nitty gritty is in risk management and deciding when to exit or close positions (you know how to ‘let winners ride and cut losers short’). This is the reason financial insts. have billions in silicon to run essentially MC based on their value functions of the…world.

And let it be clear, that nobody will tell you how to do this part. But if you want to know… your best bet is to get an account with a very high leverage like 1000:1 or something of the like. Now this is incredibly dangerous but the reason for this incredibly high leverage is to allow yourself to be able to make a large number of bets and not necessarily have to close them if you initially seem wrong.

Good luck, and although tensorflow/openai offer some really nice code, there is a good reason deploying said code is very poorly documented and there is a significant learning curve should you ever want to deploy/monetize something based on tensorflow and these seemingly open reinforcement learning software

p.s. you will find it counter-intuitive that once you finally figure out the price direction in the next time-step that you will make 5-10x more money taking the opposite side bet of what your net predicts. Why? Hint: 95% human traders lose in long run :slight_smile:


Hi, I am also interested in this. I have started with a simplistic algorithm for trading and I am using it live. For phase 2 I want to using RL to create a model using Gym as the environment. I probably won’t create a very sophisticated env by myself, but I do want to do something. I would like to collaborate if possible.