Maintained

FinRL guide

FinRL is the standard starting point for experimenting with reinforcement learning on market data.

Last reviewed · Also known as FinRL-Meta, AI4Finance

Quick answer

FinRL is an open-source deep reinforcement learning library for trading from the AI4Finance Foundation. It provides Gym-style market environments, agents from Stable-Baselines3 and other libraries (PPO, A2C, SAC, DDPG, TD3), and a train → test → trade pipeline with data from Yahoo, Alpaca and others, including paper trading on Alpaca.

FinRL at a glance

Category
Machine learning & AI
Language
Python
License
MIT
Does
Machine learning, Backtesting, Paper trading
Markets
Stocks, Crypto
Best for
Research and education in RL-based portfolio allocation and trading.
In AlgoGP
Use the exported strategy object from your own code

Pick it if

Research and education in RL-based portfolio allocation and trading.

Watch out for

RL results are fragile and prone to overfitting.

FinRL strengths and limitations

Strengths

  • Ready-made environments and agents.
  • Many tutorials and papers.
  • Paper-trading path via Alpaca.

Limitations

  • RL results are fragile and prone to overfitting.
  • Research code quality varies across versions.

FinRL example

pip install finrl
Install
from finrl.agents.stablebaselines3.models import DRLAgent
agent = DRLAgent(env=train_env)
model = agent.get_model("ppo")
trained = agent.train_model(model=model, tb_log_name="ppo", total_timesteps=100_000)
Abridged training loop.

Use FinRL with AlgoGP

AlgoGP does not add FinRL to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from FinRL yourself.

  1. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from FinRL

    Feed FinRL’s bars to StrategyBridge, place the returned orders with FinRL, and report fills back with sync().

FinRL connects to Alpaca, Yahoo Finance, Binance. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.

FinRL: frequently asked questions

Does reinforcement learning work for trading?

It can fit history very well; out-of-sample robustness is the hard part, so validate walk-forward and paper trade.

FinRL alternatives

Independent guide. AlgoGP is not affiliated with FinRL. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy