Git Product home page Git Product logo

rl-trader's Introduction

RL Trader

A collection of RL financial applications; part of a talk at BADS2018

Position Bot

This agent is created to demonstrate how Q-learning can be applied to a real-world problem. Retail trading is chosed as it has a lot of resemblances with many real-world problem such as ads bidding. We created the environment based on minute-level bitcoin price data from Kaggle. We use the original Deep Q-learning implementation as stated in the paper Playing Atari with Deep Reinforcement Learning. For more advanced implementations as well as other methods, check out our bi-weekly Bangkok School of AI Reinforcement Learning Workshop.

Disclaimer You will not get rich with this algorithm. We do not hold any Bitcoin position as of 2018-10-31.

Environment

The environment is based on Bitcoin price from 2016-08-01 13:21:00 to 2016-10-10 00:00:00. It consists of 6 * 60 values for a state and 3 available actions. The state represents batch-normalized 60-minute previous ohlc, vwap and position. The actions are enter short position, do nothing, enter long position respectively. In our example notebook, we run the agent for 10,000 timesteps. The reward is differential sharpe ratio.

Actions look like: 
* 0 - short
* 1 - nothing
* 2 - long
Action size: 3
States look like: (1, 6, 60)

Getting Started

  1. Install dependencies.
pip install -r requirements.txt
  1. Follow position_sandbox.ipynb to train the agent.

  2. Our implementation is divided as follows:

  • replay_memory.py - Experience Replay Memory
  • agent.py - Agent
  • qnetwork - Q-networks for local and target

Train Agent

These are the steps you can take to train the agent with default settings.

  1. Initiate environment
env = SingleStockMarket(bitstamp_df)
  1. Create a experience replay memory.
mem = ReplayMemory(10000)
  1. Create an agent.
a = VanillaQAgent(replay_memory = mem)
  1. Train the agent.
state = env.reset()
for i in trange(10000):
    #select action
    action = a.act(state,i)  

    #step
    next_state,reward,done,info = env.step(action)                
    a.step(state,action,reward,next_state,done)

    state = next_state                          

Imitation Bot

Work in progress

Shortfall Bot

Work in progress

rl-trader's People

Contributors

cstorm125 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.