• Stars
    star
    345
  • Rank 122,652 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cloud-native Financial Reinforcement Learning

Podracer

News: We are out of hands, please star it and let us know it is urgent to update this project. Thanks for your feedback.

This project can be regarded as FinRL 2.0: intermediate-level framework for full-stack developers and professionals. It is built on ElegantRL and FinRL

We maintain an elegant (lightweight, efficient and stable) FinRL lib, helping researchers and quant traders to develop algorithmic strategies easily.

  • Lightweight: The core codes are less than 800 lines and are based on PyTorch and NumPy.

  • Efficient: Its performance is comparable with Ray RLlib.

  • Stable: It is as stable as Stable Baseline 3.

Design Principles

  • Be Pythonic: Quant traders, data scientists and machine learning engineers are familiar with the open source Python ecosystem: its programming model, and its tools, e.g., NumPy.

  • Put researchers and algorithmic traders first: Based on PyTorch, we support researchers to mannually control the execution of the codes, empowering them to improve the performance over automatical libraries.

  • Lean development of algorithmic strategies: It is better to have an elegant (may be slightly incomplete) solution than a comprehensive but complex and hard to follow design, e.g., Ray RLlib link. It allows fast code iteration.

DRL Algorithms

Currently, most model-free deep reinforcement learning (DRL) algorithms are supported:

  • DDPG, TD3, SAC, A2C, PPO, PPO(GAE) for continuous actions
  • DQN, DoubleDQN, D3QN for discrete actions
  • MILP (learn to cut using natural evolutionay strategy) for portfolio optimization

For DRL algorithms, please check out the educational webpage OpenAI Spinning Up.

File Structure

An agent in agent.py uses networks in net.py and is trained in run.py by interacting with an environment in env.py.

  • net.py # Neural networks.
    • Q-Net,
    • Actor Network,
    • Critic Network,
  • agent.py # RL algorithms.
    • AgentBase
    • AgentDQN
    • AgentDDPG
    • AgentTD3
    • AgentSAC
    • AgentPPO
  • env.py # Stock Trading environment
  • run.py # Stock Trading application
    • Parameter initialization,
    • Training loop,
    • Evaluator.
  • StockTrading_Demo.ipynb # One stock trading demo using PPO algorithm

Formulation of the Stock Trading Problem

Formally, we model stock trading as a Markov Decision Process (MDP), and formulate the trading objective as maximization of expected return:

  • State s = [b, p, h]: a vector that includes the remaining balance b, stock prices p, and stock shares h. p and h are vectors with D dimension, where D denotes the number of stocks.
  • Action a: a vector of actions over D stocks. The allowed actions on each stock include selling, buying, or holding, which result in decreasing, increasing, or no change of the stock shares in h, respectively.
  • Reward r(s, a, sโ€™): The asset value change of taking action a at state s and arriving at new state sโ€™.
  • Policy ฯ€(s): The trading strategy at state s, which is a probability distribution over actions at state s.
  • Q-function Q(s, a): the expected return (reward) of taking action a at state s following policy ฯ€.
  • State-transition: After taking the actions a, the number of shares h is modified, as shown in Fig 3, and the new portfolio is the summation of the balance and the total value of the stocks.

Stock Trading Environment

Environment Design

The environment is designed in the OpenAI gym-style since it is considered as the standard implementation of reinforcement learning environments.

  • Initialization: the stock data from Yahoo Finance is pre-processed, and the variables related to the stock trading problem are initialized. Before the training, an initialization function is used to create a new environment for interacting with the agent.
  • Reset: the state and variables of the environment are reset to the initial condition. This function is used once the simulation stops and needs to restart.
  • Step: the state takes an action from the agent and then returns a list of three things โ€” the next state, the reward, the indication of whether the current episode is done or not. The way the environment computes the next state and the reward is based on the state-action transition defined in the previous blog. The step function is used when the agent collects the transitions for training usage.

State Space and Action Space

  • State Space: We use a 181-dimensional vector consists of seven parts of information to represent the state space of multiple stocks trading environment: [b, p, h, M, R, C, X], where b is the balance, p is the stock prices, h is the number of shares, M is the Moving Average Convergence Divergence (MACD), R is the Relative Strength Index (RSI), C is the Commodity Channel Index (CCI), and X is the Average Directional Index (ADX).
  • Action Space: As a recap, we have three types of actions: selling, buying, and holding for a single stock. We use the negative value for selling, positive value for buying, and zero for holding. In this case, the action space is defined as {-k, โ€ฆ, -1, 0, 1, โ€ฆ, k}, where k is the maximum share to buy or sell in each transaction.

Easy-to-customize Features

  • Initial_capital: the initial capital that the user wants to invest.
  • Tickers: the stock pool that the user wants to trade with.
  • Initial_stocks: the initial amount of each stock and the default could be zero.
  • buy_cost_pct, sell_cost_pct: the transaction fee of each buying or selling transaction.
  • Max_stock: the user is able to define the maximum number of stocks that are allowed to trade per transaction.
  • tech_indicator_list: the list of financial indicators that are taken into account, which is used to define a state.
  • start_date, start_eval_date, end_eval_date: the training and backtesting time intervals. Thee time dates (or timestamps) are used, once the training period is specified, the rest is backtesting.

More Repositories

1

FinGPT

FinGPT: Open-Source Financial Large Language Models! Revolutionize ๐Ÿ”ฅ We release the trained model on HuggingFace.
Jupyter Notebook
12,852
star
2

FinRL

FinRL: Financial Reinforcement Learning. ๐Ÿ”ฅ
Jupyter Notebook
9,692
star
3

ElegantRL

Massively Parallel Deep Reinforcement Learning. ๐Ÿ”ฅ
Python
3,590
star
4

FinRL-Trading

For trading. Please star.
Jupyter Notebook
2,003
star
5

FinRobot

FinRobot: An Open-Source AI Agent Platform for Financial Applications using LLMs ๐Ÿš€ ๐Ÿš€ ๐Ÿš€
Jupyter Notebook
1,302
star
6

FinRL-Meta

FinRLยญ-Meta: Dynamic datasets and market environments for FinRL.
Python
1,255
star
7

FinNLP

Democratizing Internet-scale financial data.
Jupyter Notebook
1,088
star
8

FinRL-Tutorials

Tutorials. Please star.
Jupyter Notebook
798
star
9

Awesome_AI4Finance

Resources
136
star
10

RLSolver

Solvers for NP-hard and NP-complete problems with an emphasis on high-performance GPU computing.
Python
126
star
11

FinML

FinML: A Practical Machine Learning Framework for Dynamic Stock Selection
Jupyter Notebook
95
star
12

FinRL_Crypto

FinRL_Crypto: Cryptocurrency trading of FinRL
Python
76
star
13

FinRL_Market_Simulator

Python
69
star
14

Deep-Reinforcement-Learning-for-Stock-Trading-DDPG-Algorithm-NIPS-2018

Practical Deep Reinforcement Learning Approach for Stock Trading. NeurIPS 2018 AI in Finance.
Python
69
star
15

Quantifying-ESG-Alpha-using-Scholar-Big-Data-ICAIF-2020

Quantifying ESG Alpha using Scholar Big Data: An Automated Machine Learning Approach.
Jupyter Notebook
66
star
16

FinRL-Blogs

Blogs, tutorials, news. Please star.
56
star
17

Financial-News-for-Stock-Prediction-using-DP-LSTM-NIPS-2019

Differential Privacy-inspired LSTM for Stock Prediction Using Financial News. NeurIPS Robust AI in Financial Services 2019.
Python
33
star
18

AI4Finance-Education

education channel
24
star
19

Liquidation-Analysis-using-Multi-Agent-Reinforcement-Learning-ICML-2019

Multi-agent Reinforcement Learning for Liquidation Strategy Analysis. ICML 2019 AI in Finance.
Jupyter Notebook
24
star
20

TransportRL

High-performance RL library for transportation problems, e.g., autonomous driving, traffic light control, UAV control, and path planning.
Python
23
star
21

FinEmotion

Python
23
star
22

Popular-RL-Algorithms

Jupyter Notebook
22
star
23

Risk-Management-using-Deep-Learning-for-Midterm-Stock-Prediction-KDD-2019

Risk Management via Anomaly Circumvent: Mnemonic Deep Learning for Midterm Stock Prediction. KDD 2019.
Jupyter Notebook
19
star
24

FinRL_Imitation_Learning

Jupyter Notebook
16
star
25

Dynamic-Stock-Recommendation-Machine_Learning-Published-Paper-IEEE

Jupyter Notebook
14
star
26

Quantum-Tensor-Networks-for-Variational-Reinforcement-Learning-NeurIPS-2020

Quantum Tensor Networks for Variational Reinforcement Learning. NeurIPS 2020.
Python
13
star
27

FinGPT-Earnings-Call-LLM-Agent

Jupyter Notebook
8
star
28

AI4Finance_Job_Info

Job Infor in the intersection of AI, Big data, and Finance.
6
star
29

Optimistic-Bull-Pessimistic-Bear-DRL-Stock-Portfolio-Allocation-ICML-2019

5
star
30

Scholar-Data-Driven-Alpha-in-AI-Industry-IEEE-BigData-2019

Practical Machine Learning Approach to Capture the Scholar Data Driven Alpha in AI Industry. IEEE BigData 2019.
Jupyter Notebook
5
star
31

Awesome_FinRL

FinRL resources: papers, projects
5
star
32

FinRAG

FinRAG: Financial Retrieval Augmented Generation
Python
4
star
33

.github

4
star
34

ML_Price_Prediction

Predict price
4
star
35

FinGPT-Research

Jupyter Notebook
2
star
36

PlotFigs

Plot figures for academic papers.
Python
1
star