Skip to main content

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

Metadata

Release files for tenvs 1.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tenvs 1.0.9
File Size Uploaded
tenvs-1.0.9.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tenvs 1.0.9
File Interpreter ABI Platform
tenvs-1.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 52.4 kB

Release files / tenvs-1.0.9.tar.gz

Download URL tenvs-1.0.9.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c0cb385be032f82479e7ebb80320e2bb73e53e917a144509de496b2e7dc127ae
BLAKE2b-256 checksum
How to use checksums
b068dbe5a8213dd37fac6ce6ba814cec5e40fc74b5e2e889170b8469e768e27a
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / tenvs-1.0.9-py3-none-any.whl

Download URL tenvs-1.0.9-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc294c17a661152cae8636a6131579abe3083e85359910c4fd755e8167952aca
BLAKE2b-256 checksum
How to use checksums
bb39e7591db74e16f67c676f7766d1281f153554aa945490589375516eaeeb7e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.9 This release

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page