- Home
- Design & Media
- TradingGym
TradingGym
Trading and Backtesting environment for training reinforcement learning agent or simple rule base al
Rating
Votes
0
score
Downloads
0
total
Price
Free
No login needed
Works With
About
TradingGym
[](https://travis-ci.org/Yvictor/TradingGym)
TradingGym is a toolkit for training and backtesting the reinforcement learning algorithms. This was inspired by OpenAI Gym and imitated the framework form. Not only traning env but also has backtesting and in the future will implement realtime trading env with Interactivate Broker API and so on.
This training env originally design for tickdata, but also support for ohlc data format. WIP.
Installation
git clone https://github.com/Yvictor/TradingGym.git
cd TradingGym
python setup.py installGetting Started
import random
import numpy as np
import pandas as pd
import trading_env
df = pd.read_hdf('dataset/SGXTW.h5', 'STW')
env = trading_env.make(env_id='training_v1', obs_data_len=256, step_len=128,
df=df, fee=0.1, max_position=5, deal_col_name='Price',
feature_names=['Price', 'Volume',
'Ask_price','Bid_price',
'Ask_deal_vol','Bid_deal_vol',
'Bid/Ask_deal', 'Updown'])
env.reset()
env.render()
state, reward, done, info = env.step(random.randrange(3))
### randow choice action and show the transaction detail
for i in range(500):
print(i)
state, reward, done, info = env.step(random.randrange(3))
print(state, reward)
env.render()
if done:
break
env.transaction_details- obs_data_len: observation data length
- step_len: when call step rolling windows will + step_len
- df exmaple
>|index|datetime|bid|ask|price|volume|serial_number|dealin| >|-----|--------|---|---|-----|------|-------------|------| >|0|2010-05-25 08:45:00|7188.0|7188.0|7188.0|527.0|0.0|0.0| >|1|2010-05-25 08:45:00|7188.0|7189.0|7189.0|1.0|1.0|1.0| >|2|2010-05-25 08:45:00|7188.0|7189.0|7188.0|1.0|2.0|-1.0| >|3|2010-05-25 08:45:00|7188.0|7189.0|7188.0|4.0|3.0|-1.0| >|4|2010-05-25 08:45:00|7188.0|7189.0|7188.0|2.0|4.0|-1.0|
- df: dataframe that contain data for trading
serial_number -> serial num of deal at each day recalculating
- fee: when each deal will pay the fee, set with your product.
- max_position: the max market position for you trading share.
- deal_col_name: the column name for cucalate reward used.
- feature_names: list contain the feature columns to use in trading status.
Training
#### simple dqn
- WIP
#### policy gradient
- WIP
#### actor-critic
- WIP
#### A3C with RNN
- WIP
Backtesting
- loading env just like training
env = trading_env.make(env_id='backtest_v1', obs_data_len=1024, step_len=512,
df=df, fee=0.1, max_position=5, deal_col_name='Price',
feature_names=['Price', 'Volume',
'Ask_price','Bid_price',
'Ask_deal_vol','Bid_deal_vol',
'Bid/Ask_deal', 'Updown'])- load your own agent
Don't lose this
Three weeks from now, you'll want TradingGym again. Will you remember where to find it?
Save it to your library and the next time you need TradingGym, it’s one tap away — from any AI app you use. Group it into a bench with the rest of the team for that kind of task and you can pull the whole stack at once.
⚡ Pro tip for geeks: add a-gnt 🤵🏻♂️ as a custom connector in Claude or a custom GPT in ChatGPT — one click and your library is right there in the chat. Or, if you’re in an editor, install the a-gnt MCP server and say “use my [bench name]” in Claude Code, Cursor, VS Code, or Windsurf.
a-gnt's Take
Our honest review
Trading and Backtesting environment for training reinforcement learning agent or simple rule base al. Best for anyone looking to make their AI assistant more capable in design & media. It's completely free and works across most major AI apps. This one just landed in the catalog — worth trying while it's fresh.
Tips for getting started
Tap "Get" above, pick your AI app, and follow the steps. Most installs take under 30 seconds.
What's New
Imported from GitHub
Ratings & Reviews
0.0
out of 5
0 ratings
No reviews yet. Be the first to share your experience.