All Projects → Albert-Z-Guo → Deep Reinforcement Stock Trading

Albert-Z-Guo / Deep Reinforcement Stock Trading

Licence: gpl-3.0
A light-weight deep reinforcement learning framework for portfolio management. This project explores the possibility of applying deep reinforcement learning algorithms to stock trading in a highly modular and scalable framework.

Projects that are alternatives of or similar to Deep Reinforcement Stock Trading

Dask Docker
Docker images for dask
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Dat210x
Programming with Python for Data Science Microsoft
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Glasses
High-quality Neural Networks for Computer Vision 😎
Stars: ✭ 138 (+1.47%)
Mutual labels:  jupyter-notebook
Nfft
Lightweight non-uniform Fast Fourier Transform in Python
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Wikidataintegrator
A Wikidata Python module integrating the MediaWiki API and the Wikidata SPARQL endpoint
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Smilecnn
Smile detection with a deep convolutional neural net, with Keras.
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Datasets
🎁 3,000,000+ Unsplash images made available for research and machine learning
Stars: ✭ 1,805 (+1227.21%)
Mutual labels:  jupyter-notebook
Easy slam tutorial
首个中文的简单从零开始实现视觉SLAM理论与实践教程,使用Python实现。包括:ORB特征点提取,对极几何,视觉里程计后端优化,实时三维重建地图。A easy SLAM practical tutorial (Python).图像处理、otsu二值化。更多其他教程我的CSDN博客
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Robustautoencoder
A combination of Autoencoder and Robust PCA
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Fetching Financial Data
Fetching financial data for technical & fundamental analysis and algorithmic trading from a variety of python packages and sources.
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Drl
Deep RL Algorithms implemented for UC Berkeley's CS 294-112: Deep Reinforcement Learning
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Youtube Like Predictor
YouTube Like Count Predictions using Machine Learning
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Qutip Notebooks
A collection of IPython notebooks using QuTiP: examples, tutorials, development test, etc.
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Zhihu Spider
一个获取知乎用户主页信息的多线程Python爬虫程序。
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Rapids Single Cell Examples
Examples of single-cell genomic analysis accelerated with RAPIDS
Stars: ✭ 138 (+1.47%)
Mutual labels:  jupyter-notebook
Workshop
AI and Machine Learning with Kubeflow, Amazon EKS, and SageMaker
Stars: ✭ 2,418 (+1677.94%)
Mutual labels:  jupyter-notebook
End To End Generative Dialogue
A neural conversation model
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Dab And Tpose Controlled Lights
Control your lights with dab and t-pose, duh
Stars: ✭ 137 (+0.74%)
Mutual labels:  jupyter-notebook
Cnn Audio Denoiser
Tensorflow 2.0 implementation of the paper: A Fully Convolutional Neural Network for Speech Enhancement
Stars: ✭ 138 (+1.47%)
Mutual labels:  jupyter-notebook
Copy Paste Aug
Copy-paste augmentation for segmentation and detection tasks
Stars: ✭ 132 (-2.94%)
Mutual labels:  jupyter-notebook

Deep-Reinforcement-Stock-Trading

This project intends to leverage deep reinforcement learning in portfolio management. The framework structure is inspired by Q-Trader. The reward for agents is the net unrealized (meaning the stocks are still in portfolio and not cashed out yet) profit evaluated at each action step. For inaction at each step, a negtive penalty is added to the portfolio as the missed opportunity to invest in "risk-free" Treasury bonds. A lot of new features and improvements are made in the training and evaluation pipelines. All evaluation metrics and visualizations are built from scratch.

Key assumptions and limitations of the current framework:

  • trading has no impact on the market
  • only single stock type is supported
  • only 3 basic actions: buy, hold, sell (no short selling or other complex actions)
  • the agent performs only 1 action for portfolio reallocation at the end of each trade day
  • all reallocations can be finished at the closing prices
  • no missing data in price history
  • no transaction cost

Key challenges of the current framework:

  • implementing algorithms from scratch with a thorough understanding of their pros and cons
  • building a reliable reward mechanism (learning tends to be stationary/stuck in local optima quite often)
  • ensuring the framework is scalable and extensible

Currently, the state is defined as the normalized adjacent daily stock price differences for n days plus [stock_price, balance, num_holding].

In the future, we plan to add other state-of-the-art deep reinforcement learning algorithms, such as Proximal Policy Optimization (PPO), to the framework and increase the complexity to the state in each algorithm by constructing more complex price tensors etc. with a wider range of deep learning approaches, such as convolutional neural networks or attention mechanism. In addition, we plan to integrate better pipelines for high quality data source, e.g. from vendors like Quandl; and backtesting, e.g. zipline.

Getting Started

To install all libraries/dependencies used in this project, run

pip3 install -r requirement.txt

To train a DDPG agent or a DQN agent, e.g. over S&P 500 from 2010 to 2015, run

python3 train.py --model_name=model_name --stock_name=stock_name
  • model_name is the model to use: either DQN or DDPG; default is DQN
  • stock_name is the stock used to train the model; default is ^GSPC_2010-2015, which is S&P 500 from 1/1/2010 to 12/31/2015
  • window_size is the span (days) of observation; default is 10
  • num_episode is the number of episodes used for training; default is 10
  • initial_balance is the initial balance of the portfolio; default is 50000

To evaluate a DDPG or DQN agent, run

python3 evaluate.py --model_name=model_name --model_to_load=model_to_load --stock_name=stock_name
  • model_to_load is the model to load; default is DQN_ep10
  • stock_name is the stock used to evaluate the model; default is ^GSPC_2018, which is S&P 500 from 1/1/2018 to 12/31/2018
  • initial_balance is the initial balance of the portfolio; default is 50000

where stock_name can be referred in data directory and model_to_laod can be referred in saved_models directory.

To visualize training loss and portfolio value fluctuations history, run:

tensorboard --logdir=logs/model_events

where model_events can be found in logs directory.

Example Results

Note that the following results were obtained with 10 epochs of training only. alt_text

alt_text

Frequently Asked Questions (FAQ)

  • How is this project different from other price prediction approaches, such as logistic regression or LSTM?
    • Price prediction approaches like logistic regression have numerical outputs, which have to be mapped (through some interpretation of the predicted price) to action space (e.g. buy, sell, hold) separately. On the other hand, reinforcement learning approaches directly output the agent's action.

References:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].