Source-linked AI summary

FinRL: A Deep Reinforcement Learning Library for Automated Stock Trading in Quantitative Finance

Xiao-Yang Liu, Hongyang Yang, Qian Chen, Runjia Zhang, Liuqing Yang, Bowen Xiao, Christina Dan Wang

arXiv:2011.09607v2q-fin.TRcs.LG

TL;DR

Implementing practical DRL trading strategies is arduous and error-prone, creating a barrier for beginners. FinRL addresses this gap with a layered, extensible library that combines environments, agents, tutorials, backtesting, and benchmarks, and demonstrates reproducible trading applications.

  • Problem

    Implementing practical DRL trading agents requires arduous, error-prone development and debugging, limiting beginner access to quantitative-finance experimentation.

  • Method

    FinRL uses a three-layer, extensible architecture integrating market environments, fine-tuned DRL agents, tutorials, market constraints, backtesting, and evaluation baselines.

  • Results

    FinRL provides reproducible demonstrations for single-stock trading, multiple-stock trading, and portfolio allocation across representative financial datasets and workflows.

  • Takeaways & Limitations

    FinRL makes DRL-driven stock-trading strategy development more accessible, efficient, and extendable for beginners, investors, and strategy builders.

Abstract

from arXiv · show

As deep reinforcement learning (DRL) has been recognized as an effective approach in quantitative finance, getting hands-on experiences is attractive to beginners. However, to train a practical DRL trading agent that decides where to trade, at what price, and what quantity involves error-prone and arduous development and debugging. In this paper, we introduce a DRL library FinRL that facilitates beginners to expose themselves to quantitative finance and to develop their own stock trading strategies. Along with easily-reproducible tutorials, FinRL library allows users to streamline their own developments and to compare with existing schemes easily. Within FinRL, virtual environments are configured with stock market datasets, trading agents are trained with neural networks, and extensive backtesting is analyzed via trading performance. Moreover, it incorporates important trading constraints such as transaction cost, market liquidity and the investor's degree of risk-aversion. FinRL is featured with completeness, hands-on tutorial and reproducibility that favors beginners: (i) at multiple levels of time granularity, FinRL simulates trading environments across various stock markets, including NASDAQ-100, DJIA, S&P 500, HSI, SSE 50, and CSI 300; (ii) organized in a layered architecture with modular structure, FinRL provides fine-tuned state-of-the-art DRL algorithms (DQN, DDPG, PPO, SAC, A2C, TD3, etc.), commonly-used reward functions and standard evaluation baselines to alleviate the debugging workloads and promote the reproducibility, and (iii) being highly extendable, FinRL reserves a complete set of user-import interfaces. Furthermore, we incorporated three application demonstrations, namely single stock trading, multiple stock trading, and portfolio allocation. The FinRL library will be available on Github at link https://github.com/AI4Finance-LLC/FinRL-Library.

1 Introduction

FinRL is introduced as a complete, beginner-friendly, and reproducible library for developing and evaluating DRL stock-trading strategies. Its layered architecture combines market environments, trading agents, applications, tutorials, and benchmarking support.

  • Motivation: DRL addresses dynamic stock-trading decisions, but implementing such strategies is arduous and error-prone, especially for beginners.Development requires configuring environments, managing trading states and data, and standardizing evaluation outputs.
  • Design principles: Completeness, hands-on tutorials, and reproducibility are the library’s three primary design principles.These principles aim to cover the DRL framework, guide beginners through detailed walkthroughs, and support transparent, repeatable use.
  • FinRL library: FinRL provides a three-layer architecture spanning market environments, DRL agents, and automated stock-trading applications.The environment layer uses historical data, the agent layer supplies algorithms and rewards, and the top layer contains trading applications.
  • Capabilities: FinRL incorporates trading environments with market frictions and supports customization of trading time steps.The library provides environments incorporating market frictions and allows users to customize trading granularity.
  • Capabilities: The library includes fine-tuned DRL algorithms, standard reward functions, evaluation baselines, tutorials, and benchmark use cases.These components are intended to reduce debugging workloads, promote reproducibility, and support performance evaluation.

2 Related Works

Prior work applies DRL broadly in quantitative finance, while existing machine-learning libraries provide related reinforcement-learning infrastructure. FinRL consolidates several DRL approaches for financial trading applications.

  • DRL in finance: Related work describes DRL applications in quantitative finance and categorizes algorithms as value-based, policy-based, and actor-critic methods.FinRL consolidates and elaborates these algorithmic approaches for financial DRL models.
  • Open-source libraries: Existing libraries provide standardized environments, DRL algorithms, prototyping frameworks, scalable modular systems, or batch reinforcement-learning support.Examples include OpenAI Gym, OpenAI Baselines, Stable Baselines, Google Dopamine, RLlib, and Horizon.
  • Applications: DRL research in finance includes volatility-scaled futures trading and policies combining stock time series with news sentiment and knowledge graphs.These examples illustrate the range of financial inputs and tasks addressed by prior work.

3 The Proposed FinRL Library

FinRL organizes stock-trading development into layered environments, agents, and applications, with modular components supporting market simulation, training, rewards, and evaluation. It also provides multiple datasets, time granularities, algorithms, reward functions, and user-import interfaces.

  • Architecture: FinRL uses three layers: environments, DRL trading agents, and stock-trading applications.The lower layer provides APIs to the upper layer, and the agent interacts with the environment through exploration and exploitation.
  • Modularity and extensibility: Its modular design lets users select modules across layers, update existing modules, and develop new ones through reserved interfaces.The library presents DRL algorithms as modules and supports user-imported data with adjustable time-step granularity.
  • State space: The state space can include balance, owned shares, prices, trading volume, and MACD and RSI technical indicators at daily, hourly, or minute frequency.These features describe observations received by the trading agent from the environment.
  • Action space: The action space supports selling, holding, or buying, including multi-share actions represented by integers from −k through k.For example, buying 10 AAPL shares is represented as 10 and selling 10 as −10.
  • Reward function: FinRL supplies commonly used rewards based on portfolio-value change, portfolio log return, or Sharpe ratio, while allowing user-defined risk and transaction-cost terms.The portfolio-value reward is r(s, a, s′) = v′ − v, and the Sharpe-ratio reward uses mean(R_t) divided by std(R_t).
  • Market environments: FinRL simulates live stock markets with real market data and provides six representative-listing environments plus one user-defined environment.The listed environments cover NASDAQ-100, DJIA, S&P 500, SSE 50, CSI 300, and HSI.
  • DRL agents: The library includes fine-tuned DQN, DDPG, Multi-Agent DDPG, PPO, SAC, A2C, and TD3 algorithms, with support for adaptation and ensemble methods.The implementations are based on OpenAI Baselines and Stable Baselines.

4 Evaluation of Trading Performance

FinRL evaluates trading strategies through standardized metrics, baselines, phased data splits, use cases, and backtesting that incorporates practical trading constraints.

  • FinRL evaluates trading performance using final portfolio value, annualized return, annualized standard deviation, maximum drawdown ratio, and Sharpe ratio.
  • Traditional trading strategies serve as baselines for comparing DRL strategies against profit and risk objectives.
  • Training, validation, and testing datasets respectively fit models, tune parameters while avoiding overfitting, and provide unbiased evaluation.
  • The single-stock Sharpe ratios outperform the S&P 500 market benchmark.
  • Multiple-stock trading and portfolio allocation use DDPG and TD3 over Dow Jones 30 constituents, whose Sharpe ratios exceed the DJIA and min-variance baselines.
  • The evaluation demonstrates single-stock trading with PPO across ETFs and major technology stocks, with maximum drawdown affected by the Covid-19 market crash.

5 Conclusions

FinRL is an extendable DRL library for automated stock trading that supports customization across the market simulator, trading agents, and strategy layers. Its training-validation-testing flow, automated backtesting, benchmark tests, and reproducible tutorials support several trading scenarios.

  • FinRL is designed specifically for automated stock trading with educational and demonstrative purposes.
  • Customization is available across FinRL’s market simulator, trading-agent learning algorithms, and profitable-strategy layers.
  • FinRL follows a training-validation-testing flow and provides automated backtesting and benchmark tests for trading-strategy design.
  • Reproducible Jupyter notebook tutorials demonstrate single-stock trading, multiple-stock trading, and stock-information penetration scenarios.
  • FinRL aims to make powerful DRL-driven trading-strategy implementation accessible, efficient, and engaging.
Loading 2011.09607v2…