Yvictor / TradingGym

Trading and Backtesting environment for training reinforcement learning agent or simple rule base algo.
MIT License
1.54k stars 349 forks source link

Error while rendering environment? #8

Open fightthepower opened 5 years ago

fightthepower commented 5 years ago

Thank you for this I was looking for something like this. when I am trying out this I am getting a assertion error like this

self.ax.lines.remove(self.price_plot[0]) AttributeError: 'trading_env' object has no attribute 'ax'

data frame sample

>>> df.head()
   serial_number        Date   Open   High    Low  Close      Volume
0              0  1998-01-02  13.63  16.25  13.50  16.25   6411700.0
1              1  1998-01-05  16.50  16.56  15.19  15.88   5820300.0
2              2  1998-01-06  15.94  20.00  14.75  18.94  16182800.0
3              3  1998-01-07  18.81  19.00  17.31  17.50   9300200.0
4              4  1998-01-08  17.44  18.62  16.94  18.19   6910900.0

I want to use Volume column alone as the my observation state. This is the whole code

import random
import numpy as np
import pandas as pd
import trading_env

df = pd.read_csv('./dataset/AAPL.csv')

df.rename(columns={'Unnamed: 0':'serial_number'},inplace=True)

env = trading_env.make(env_id='training_v1', obs_data_len=50, step_len=14,
                       df=df, fee=0.1, max_position=5, deal_col_name='Close', 
                       feature_names=['Volume'])

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

IMPORTANT: Can you please tell me what is the action space index for buy, sell and hold. I can see action space consists of three integers but can't find where its mapped to.

omar94khan commented 1 year ago

0 is for hold. 1 is for long / buy. 2 is for short / sell.