Code Monkey home page Code Monkey logo

gym-stock-trading's Introduction

Gym Stock Trading

Gym Stock Trading is an OpenAI Gym environment for stock trading with integrations into Alpaca trade api for live and paper trading.

Basics

For a better understanding of OpenAI Gym, check out the docs: https://github.com/openai/gym

There are two environments included:

Gym Stock Trading Environment (intended for historical data backtesting) uses 1min OHLCV (Open, High, Low, Close, Volume) aggregate bars as market data and provides unrealized profit/loss as a reward to the agent. Details of the operations of the environment can be found in the class docstring.

Alpaca Stock Trading Environment allows you to use the model trained in the Stock Trading Gym to test the live market in the form of paper or live trading. You must have an Alpaca Brokerage account (and API keys) to use this environment. Its free (although you have to fund the account) so don't let this hold you back. You can find Alpaca's website here: https://alpaca.markets

Installation

git clone https://github.com/duhfrazee/gym-stock-trading
cd gym-stock-trading
pip install -e .

Example

Environment initialization

Gym Stock Trading Environment

  • market_data:
    • generator that yields a tuple of (asset_data, previous_close)
      • asset_data: dataframe with 1 full day of 1 min aggregate bars
      • previous_close: previous day closing price
  • daily_avg_volume=None:
    • integer used to normalize volume (I use 30-day daily average volume for the asset)
  • observation_size=1:
    • number of aggregate bars returned in the observation
      • Note: if the current step is 0 (first observation) and the observation size is 5, all excess observations will be 0
  • volume_enabled=True:
    • denotes wether to include volume as part of observation
  • trade_penalty=0.0
    • amount to penalize agent per trade
  • allotted_amount=10000.0
    • amount of money the agent has to trade

Alpaca Stock Trading Environment

  • symbol:
    • str: symbol to trade, ex. 'AAPL'
  • previous_close:
    • float: Previous day close for asset
  • daily_avg_volume=None:
    • integer used to normalize volume (I use 30-day daily average volume for the asset)
  • live=False:
    • Whether to trade paper or live assets
  • observation_size=1:
    • number of aggregate bars returned in the observation
      • Note: if the current step is 0 (first observation) and the observation size is 5, all excess observations will be 0
  • volume_enabled=True
    • denotes wether to include volume as part of observation
  • allotted_amount=10000.0)
    • amount of money the agent has to trade

Environment Details

gym-stock-trading's People

Contributors

duhfrazee 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.