Sitemap
DataDrivenInvestor

empowerment through data, knowledge, and expertise. Join DDI community at https://join.datadriveninvestor.com

Follow publication

How I Built a Python RL Trading Bot That Simulated 1150% Profit

10 min readFeb 2, 2025

--

Press enter or click to view image in full size
Photo by Tomasz Frankowski on Unsplash

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!

API Endpoints and…

--

--

DataDrivenInvestor
DataDrivenInvestor
Nikhil Adithyan
Nikhil Adithyan

Written by Nikhil Adithyan

Founder @BacktestZone (https://www.backtestzone.com/), a no-code backtesting platform | Top Writer | Connect with me on LinkedIn: https://bit.ly/3yNuwCJ