Skip to main content

A portfolio rebalancing task environment for reinforcement learning

Project description

pmenv

Introduction to the pmenv Package

The pmenv is a reinforcement learning environment for the Portfolio Rebalancing Task. It loads multiple stock market data using tickers and synchronizes them into a 3D tensor format suitable for learning. It is an efficient environment for implementing and testing various reinforcement learning algorithms.

Overview

The pmenv is composed of two modules, DataManager and Environment:

  • The Environment module plays a role in simulating the stock market environment and handling the transitions caused by price changes and transactions. The observation is a vector of Open, High, Low, Close price and Volume and the action space is $[-1,1]^N$ where $N$ is a number of risky assets in the portfolio. Portfolio is a vector of weights of all assets and the first entry always represents cash weight.

  • The DataManager module is responsible for loading multiple stock market data using tickers and synchronizing them into a unified format suitable for learning.

The mathematical details of the environment are implemented based on the following paper. Please refer to the paper for further information. An intelligent financial portfolio trading strategy using deep Q-learning, ESWA, 2020

Install

pip install pmenv

Basic Usage

import pmenv

datamanager = pmenv.DataManager()

# Tickers and Period
tickers = ["AAPL", "INCY", "REGN"]

train_start = "2019-01-02"
train_end = "2021-06-30"

# Load stock OHLCV dataframe with a ticker
data = datamanager.get_data(tickers[0], train_start, train_end)
# Load stock data tensor with ticker list
data_tensor = datamanager.get_data_tensor(tickers, train_start, train_end)


environment = pmenv.Environment(data_tensor)

# Set transaction cost
config = {"CHARGE": 0.0025, "TEX": 0.001}
environment.config = config

# Initialize the environment with balance
balance = 5000
observation = environment.reset(balance)

# Step
action = np.random.random(size=(len(tickers))
next_observation, reward, done = env.step(action)

Tutorial with RL

  1. Portfolio Rebalancing with Deep Q-Learning
  2. Portfolio Rebalancing with DDPG
  3. Portfolio Rebalancing with Dirichlet Distribution Trader

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pmenv-1.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

pmenv-1.0.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pmenv-1.0.1.tar.gz.

File metadata

  • Download URL: pmenv-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pmenv-1.0.1.tar.gz
Algorithm Hash digest
SHA256 aca654769ed63540e45fc7b00a2a37b3f36afa599bd26d804a5ad43472aaac9f
MD5 d38471a65f5fc54739897e7b01abd577
BLAKE2b-256 c3170de37b2c0978627b2201b18a8466783ef8972e1ea0dce057f251e5d0c2b4

See more details on using hashes here.

File details

Details for the file pmenv-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pmenv-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for pmenv-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb5069b059b0f70c0a52e5bca996e4b2f0cd7ef93d22785317bfe54e5d3a8965
MD5 e546f50f9b72214842c91b0149f6dfa4
BLAKE2b-256 b310ba2afad8ac897bc032a429ae3accc2eccf59a9c29dc165ea81e4aff656e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page