Skip to main content

No project description provided

Project description

Test Docker PyPI version

tenvs

基于OpenAI Gym的程序化交易环境模拟器, 旨在为沪深A股基于增强学习的交易算法提供方便使用, 接近真实市场的交易环境

基于tenvs的RL算法baselines repo: tbase

Features

  • 自动从tushare下载数据,已经下载的数据不会重复下载(默认目录"/tmp/tenvs")

  • 撮合规则:

    • 基于最高,最低价成交
    • 对交易量不作限制
  • 下单按照A股的规则,买卖按照1手100股为基本交易单位

  • 有拆分时,会根据复权因子对持仓进行相应的倍增, 以保持与真实市场一致

  • step() 比OpenAI gym多返回一个名为rewards的list, 包含每支股票的reward, 以方便Multi-Agent算法实现

安装指南

支持: MacOS/Linux/Windows, python 3.5+, 推荐使用 python3.7

安装方式一(直接使用): pip install tenvs

安装方式二(开发者模式)

git clone https://github.com/tradingAI/tenvs
cd tenvs
pip install -e .

使用

设置 tushare token(Tushare token注册申请):

export TUSHARE_TOKEN=YOUR_TOKEN

Examples

场景 实现 action observation reward 使用例子
单支股票, 全仓操作, 每日先卖再买 simple.py [scaled_sell_price, scaled_buy_price 市场信息+部分账户信息 可参数选择 simple_test.py
多支股票平均分仓, 每日先卖再买 average.py [scaled_sell_price, scaled_buy_price] * n 市场信息+部分账户信息 可参数选择 average_test.py
多支股票, 支持仓位控制, 每日先卖再买 multi_vol.py [scaled_sell_price, scaled_sell_volume, scaled_buy_price, scaled_buy_volume] * n 市场信息+部分账户信息 可参数选择 multi_vol_test.py

场景:

  • 单支股票, 全仓操作
  • 多支股票, 均匀分仓操作
  • 多支股票,支持仓位控制

reward functions:

  • simple: 盈利=1,否则=-1
  • daily_return: 每日的收益率
  • daily_return_add_count_rate: 收益率 + 成交统计信息
  • daily_return_add_price_bound: 收益率 - 最高最低价与买卖价差MSE
  • daily_return_with_chl_penalty: 收益率 - [close,high,low]与买卖价格相应惩罚

Contribution

  • Fork this repo
  • Add or change code && Please add tests for changes
  • Test
    • step1. 设置docker-compose需要的环境变量: BAZEL_USER_ROOT, OUTPUT_DIR, TUSHARE_TOKEN
      • 默认使用docker hub 镜像
      • 阿里云镜像: registry.cn-hangzhou.aliyuncs.com/tradingai/tenvs:latest
    • step2. docker-compose up
  • Send pull request

扩展Scenario

可以参考average.py的写法

  • 定义action
  • 定义observation
  • 定义reward

TODO List(欢迎一起完善)

  • 测试: 提升 unit test 覆盖率(coveralls.io)

  • 场景增加

    • 增加的reward函数(Blog post在不同的算法上的表现性能比较)
    • 增加observation中信息(因子挖掘)

线上交流方式

  • QQ群: 477860214

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

tenvs-1.0.9.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

tenvs-1.0.9-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file tenvs-1.0.9.tar.gz.

File metadata

  • Download URL: tenvs-1.0.9.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.7

File hashes

Hashes for tenvs-1.0.9.tar.gz
Algorithm Hash digest
SHA256 c0cb385be032f82479e7ebb80320e2bb73e53e917a144509de496b2e7dc127ae
MD5 d6d47be3747b1ed56db7293033e5a83c
BLAKE2b-256 b068dbe5a8213dd37fac6ce6ba814cec5e40fc74b5e2e889170b8469e768e27a

See more details on using hashes here.

File details

Details for the file tenvs-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: tenvs-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.7

File hashes

Hashes for tenvs-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 cc294c17a661152cae8636a6131579abe3083e85359910c4fd755e8167952aca
MD5 92b35c8f5ba81d08c7abec15cd2737fc
BLAKE2b-256 bb39e7591db74e16f67c676f7766d1281f153554aa945490589375516eaeeb7e

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