/rl-stock-trading

Stock Trading with Reinforcement Learning (DQN & DDPG)

Primary LanguagePython

Stock Trading Automation with Deep Reinforcement Learning

Description

An automated stock trading with Deep Reinforcement Learning (DQN & DDPG) for AAPL, BA, and TSLA with news sentiment and one/ multi-step stock price prediction.

For complete report & slide, navigate to reports.

Instructions

To run locally:

  1. Clone this repository. NOTE: Scripts are written with Python 3.7.

  2. Install Open MPI from here

MacOS: brew install cmake openmpi

  1. Create conda environment

conda create --name rl_stock python=3.7 -y

  1. Activate the conda environment

conda activate rl_stock

  1. Install requirements

pip install -r requirements.txt

Run

Arguments

  • -a, --agent, DQN or DDPG
  • -f, --forecast, one or multi
  • -s, --sentiment, True or False

Baseline

python run.py -a {DQN|DDPG}

Baseline + News Sentiment Analysis

python run.py -a {DQN|DDPG} -s True

Baseline + One/Multi-step Stock Forecast

python run.py -a {DQN|DDPG} -f {one|multi}

Baseline + One/Multi-step Stock Forecast + News Sentiment Analysis

python run.py -a {DQN|DDPG} -f {one|multi} -s True

Stock Forecast and Portfolio Reward plots will pop up during runtime. It is intended behavior for visual reports and it is fine to exit (X) and run.py will continue running through its course.

System Architecture

Flowchart

News Sentiment Analysis

Flowchart

Stock Price LSTM Forecast

Flowchart

Data Collection

This repo is self-contained with data. To self-collect for your own stock data, navigate to utils/collect_data.py and modify accordingly.

Credits