Member-only story
How I Built a Python RL Trading Bot That Simulated 1150% Profit
Leverage financial data and Reinforcement Learning to build a profitable trading strategy in Python
Written in collaboration with
Trading in highly shorted stocks can lead to sudden price surges or squeezes when buyers flood the market. Identifying these scenarios is often challenging, but thanks to Financial Modeling Prep (FMP) and reinforcement learning (RL), we can attempt to anticipate those big moves in an automated way. In this article, we’ll build a Python script that uses FMP’s Fail-to-Deliver API to collect “fail-to-deliver” metrics, merges them with daily price data, and trains a Proximal Policy Optimization (PPO) model to learn how to buy or sell shares under certain conditions. The entire RL training loop logs into a file, preserving the console from clutter.
We’ll also mention FMP’s Daily Chart EOD API, which is another helpful endpoint if you ever want to retrieve extended daily historical data for stocks. Although our script focuses on short-squeeze detection for equities, the same approach — fetching historical data, processing it, and training an RL agent — can be adapted to other asset classes as well.
Let’s dive in!